Skip to content

Commit

Permalink
YQ-3221 Result set row is empty with empty schema (ydb-platform#4607)
Browse files Browse the repository at this point in the history
  • Loading branch information
kardymonds authored May 17, 2024
1 parent 05b8833 commit ea6a93e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ydb/core/external_sources/object_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ struct TObjectStorageExternalSource : public IExternalSource {
++realSchemaColumnsCount;
}

if (realSchemaColumnsCount > 1) {
if (realSchemaColumnsCount != 1) {
issues.AddIssue(MakeErrorIssue(Ydb::StatusIds::BAD_REQUEST, TStringBuilder{} << TStringBuilder() << "Only one column in schema supported in raw format (you have "
<< realSchemaColumnsCount << " fields)"));
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/providers/common/provider/yql_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ bool ValidateFormatForInput(
++realSchemaColumnsCount;
}

if (realSchemaColumnsCount > 1) {
if (realSchemaColumnsCount != 1) {
ctx.AddError(TIssue(TStringBuilder() << "Only one column in schema supported in raw format (you have "
<< realSchemaColumnsCount << " fields)"));
return false;
Expand Down
14 changes: 14 additions & 0 deletions ydb/tests/fq/s3/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,17 @@ def test_ast_in_failed_query_compilation(self, kikimr, s3, client, unique_prefix

ast = client.describe_query(query_id).result.query.ast.data
assert "(\'columns \'(\'\"some_unknown_column\"))" in ast, "Invalid query ast"

@yq_all
@pytest.mark.parametrize("client", [{"folder_id": "my_folder"}], indirect=True)
def test_raw_empty_schema_binding(self, kikimr, client, unique_prefix):
kikimr.control_plane.wait_bootstrap(1)
connection_response = client.create_storage_connection(unique_prefix + "fruitbucket", "fbucket")
binding_response = client.create_object_storage_binding(name=unique_prefix + "my_binding",
path="fruits.csv",
format="raw",
connection_id=connection_response.result.connection_id,
columns=[],
check_issues=False)
assert "Only one column in schema supported in raw format" in str(binding_response.issues), str(
binding_response.issues)
17 changes: 17 additions & 0 deletions ydb/tests/fq/s3/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,20 @@ def test_precompute(self, kikimr, s3, client, unique_prefix):
assert len(result_set.rows) == 1
assert result_set.rows[0].items[0].bytes_value == b"Pear"
assert result_set.rows[0].items[1].int32_value == 15

@yq_all
@pytest.mark.parametrize("client", [{"folder_id": "my_folder"}], indirect=True)
def test_raw_empty_schema_query(self, kikimr, s3, client, unique_prefix):
self.create_bucket_and_upload_file("test.parquet", s3, kikimr)
storage_connection_name = unique_prefix + "fruitbucket"
client.create_storage_connection(storage_connection_name, "fbucket")
sql = f'''
SELECT * FROM `{storage_connection_name}`.`*`
WITH (format=raw, SCHEMA ());
'''

query_id = client.create_query("test_raw_empty_schema", sql, type=fq.QueryContent.QueryType.ANALYTICS).result.query_id
client.wait_query_status(query_id, fq.QueryMeta.FAILED)
describe_result = client.describe_query(query_id).result
describe_string = "{}".format(describe_result)
assert r"Only one column in schema supported in raw format" in describe_string
15 changes: 15 additions & 0 deletions ydb/tests/fq/yds/test_yds_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,18 @@ def test_yds_insert(self, client):
assert result_set.rows[0].items[1].text_value == 'xxx'
assert result_set.rows[1].items[0].int32_value == 456
assert result_set.rows[1].items[1].text_value == 'yyy'

@yq_v1
def test_raw_empty_schema_binding(self, kikimr, client, yq_version):
self.init_topics(f"pq_test_raw_empty_schema_binding_{yq_version}")
connection_response = client.create_yds_connection("myyds2", os.getenv("YDB_DATABASE"),
os.getenv("YDB_ENDPOINT"))
assert not connection_response.issues, str(connection_response.issues)
binding_response = client.create_yds_binding(name="my_binding",
stream=self.input_topic,
format="raw",
connection_id=connection_response.result.connection_id,
columns=[],
check_issues=False)
assert "Only one column in schema supported in raw format" in str(binding_response.issues), str(
binding_response.issues)

0 comments on commit ea6a93e

Please sign in to comment.