Skip to content

Commit f600bdf

Browse files
authored
Catch exception in LoadDynamicMetadata (#17500)
1 parent d7f39a1 commit f600bdf

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

ydb/core/external_sources/object_storage.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ struct TObjectStorageExternalSource : public IExternalSource {
344344
std::shared_ptr<TMetadata> Metadata;
345345
};
346346

347-
virtual NThreading::TFuture<std::shared_ptr<TMetadata>> LoadDynamicMetadata(std::shared_ptr<TMetadata> meta) override {
347+
virtual NThreading::TFuture<std::shared_ptr<TMetadata>> LoadDynamicMetadata(std::shared_ptr<TMetadata> meta) override try {
348348
auto format = meta->Attributes.FindPtr("format");
349349
if (!format || !meta->Attributes.contains("withinfer")) {
350350
return NThreading::MakeFuture(std::move(meta));
@@ -363,11 +363,7 @@ struct TObjectStorageExternalSource : public IExternalSource {
363363
structuredTokenBuilder.SetBasicAuth(params.SerializeAsString(), awsAuth.SecretAccessKey);
364364
} else if (std::holds_alternative<NAuth::TServiceAccount>(meta->Auth)) {
365365
if (!CredentialsFactory) {
366-
try {
367-
throw yexception{} << "trying to authenticate with service account credentials, internal error";
368-
} catch (const yexception& error) {
369-
return NThreading::MakeErrorFuture<std::shared_ptr<TMetadata>>(std::current_exception());
370-
}
366+
throw yexception{} << "trying to authenticate with service account credentials, internal error";
371367
}
372368
auto& saAuth = std::get<NAuth::TServiceAccount>(meta->Auth);
373369
structuredTokenBuilder.SetServiceAccountIdAuth(saAuth.ServiceAccountId, saAuth.ServiceAccountIdSignature);
@@ -548,6 +544,8 @@ struct TObjectStorageExternalSource : public IExternalSource {
548544
}
549545
throw TExternalSourceException{} << value.Issues().ToOneLineString();
550546
});
547+
} catch (const std::exception&) {
548+
return NThreading::MakeErrorFuture<std::shared_ptr<TMetadata>>(std::current_exception());
551549
}
552550

553551
virtual bool CanLoadDynamicMetadata() const override {

ydb/core/external_sources/s3/ut/s3_aws_credentials_ut.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ Y_UNIT_TEST_SUITE(S3AwsCredentials) {
333333
UNIT_ASSERT_VALUES_EQUAL(resultSet.ColumnParser(0).GetUtf8(), "2");
334334
UNIT_ASSERT_VALUES_EQUAL(resultSet.ColumnParser(1).GetUtf8(), "hello world");
335335
}
336+
337+
{
338+
auto scriptExecutionOperation = db.ExecuteScript(fmt::format(R"(
339+
SELECT * FROM `{external_source}`.`{path}/` WITH (
340+
format="csv_with_names",
341+
`with_infer`="true",
342+
`data.datetime.format`="%Y-%m-%dT%H-%M"
343+
)
344+
)", "external_source"_a = externalDataSourceName, "path"_a = path)).ExtractValueSync();
345+
UNIT_ASSERT_VALUES_EQUAL_C(scriptExecutionOperation.Status().GetStatus(), EStatus::SUCCESS, scriptExecutionOperation.Status().GetIssues().ToString());
346+
UNIT_ASSERT(!scriptExecutionOperation.Metadata().ExecutionId.empty());
347+
348+
NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation(scriptExecutionOperation.Id(), kikimr->GetDriver());
349+
UNIT_ASSERT_EQUAL_C(readyOp.Metadata().ExecStatus, EExecStatus::Failed, readyOp.Status().GetIssues().ToString());
350+
UNIT_ASSERT_STRING_CONTAINS_C(readyOp.Status().GetIssues().ToString(), "parameter is not supported with type inference: data.datetime.format", readyOp.Status().GetIssues().ToString());
351+
}
336352
}
337353
}
338354

ydb/tests/fq/s3/test_formats.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,44 @@ def test_raw_empty_schema_query(self, kikimr, s3, client, unique_prefix):
548548
describe_result = client.describe_query(query_id).result
549549
describe_string = "{}".format(describe_result)
550550
assert r"Only one column in schema supported in raw format" in describe_string
551+
552+
@yq_v2
553+
@pytest.mark.parametrize("client", [{"folder_id": "my_folder"}], indirect=True)
554+
def test_with_infer_and_unsupported_option(self, kikimr, s3, client, unique_prefix):
555+
resource = boto3.resource(
556+
"s3", endpoint_url=s3.s3_url, aws_access_key_id="key", aws_secret_access_key="secret_key"
557+
)
558+
559+
bucket = resource.Bucket("fbucket")
560+
bucket.create(ACL='public-read')
561+
562+
s3_client = boto3.client(
563+
"s3", endpoint_url=s3.s3_url, aws_access_key_id="key", aws_secret_access_key="secret_key"
564+
)
565+
566+
fruits = '''Fruit,Price,Weight
567+
Banana,3,100
568+
Apple,2,22
569+
Pear,15,33'''
570+
s3_client.put_object(Body=fruits, Bucket='fbucket', Key='fruits.csv', ContentType='text/plain')
571+
kikimr.control_plane.wait_bootstrap(1)
572+
573+
storage_connection_name = unique_prefix + "fruitbucket"
574+
client.create_storage_connection(storage_connection_name, "fbucket")
575+
576+
# XXX replace with other unsupported parameter when/if this one become supported
577+
sql = f'''
578+
SELECT *
579+
FROM `{storage_connection_name}`.`fruits.csv`
580+
WITH (format="csv_with_names", with_infer="true", `data.datetime.format`="%Y-%m-%dT%H-%M");
581+
'''
582+
583+
query_id = client.create_query("simple", sql, type=fq.QueryContent.QueryType.ANALYTICS).result.query_id
584+
client.wait_query_status(query_id, fq.QueryMeta.FAILED)
585+
describe_result = client.describe_query(query_id).result
586+
logging.debug("Describe result: {}".format(describe_result))
587+
describe_string = "{}".format(describe_result)
588+
assert (
589+
"couldn\\'t load table metadata: parameter is not supported with type inference: data.datetime.format"
590+
in describe_string
591+
)

0 commit comments

Comments
 (0)