Skip to content

Commit

Permalink
YQ-3684 fix screts not found error handling (ydb-platform#9501)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyPA authored and rekby committed Sep 24, 2024
1 parent 0ed4aae commit 874b4bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ydb/core/kqp/gateway/kqp_metadata_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ NThreading::TFuture<TTableMetadataResult> TKqpTableMetadataLoader::LoadTableMeta
.Subscribe([promise, externalDataSourceMetadata, settings](const TFuture<TEvDescribeSecretsResponse::TDescription>& result) mutable
{
UpdateExternalDataSourceSecretsValue(externalDataSourceMetadata, result.GetValue());
if (!externalDataSourceMetadata.Success()) {
promise.SetValue(externalDataSourceMetadata);
return;
}

NExternalSource::IExternalSource::TPtr externalSource;
if (settings.ExternalSourceFactory) {
externalSource = settings.ExternalSourceFactory->GetOrCreate(externalDataSourceMetadata.Metadata->ExternalSource.Type);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/kqp/ut/federated_query/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace NKikimr::NKqp::NFederatedQueryTest {
NKikimrConfig::TFeatureFlags featureFlags;
featureFlags.SetEnableExternalDataSources(true);
featureFlags.SetEnableScriptExecutionOperations(true);
featureFlags.SetEnableExternalSourceSchemaInference(true);
if (!appConfig) {
appConfig.emplace();
}
Expand Down
42 changes: 42 additions & 0 deletions ydb/core/kqp/ut/federated_query/s3/kqp_federated_query_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,48 @@ Y_UNIT_TEST_SUITE(KqpFederatedQuery) {
UNIT_ASSERT_STRING_CONTAINS(readyOp.Status().GetIssues().ToString(), "File pattern '{' contains invalid wildcard:");
}
}

Y_UNIT_TEST(TestSecretsExistingValidation) {
const TString bucket = "test_bucket14";

CreateBucket(bucket);

NKikimrConfig::TAppConfig appConfig;
appConfig.MutableFeatureFlags()->SetEnableExternalSourceSchemaInference(true);
auto kikimr = NTestUtils::MakeKikimrRunner(appConfig);

auto tc = kikimr->GetTableClient();
auto session = tc.CreateSession().GetValueSync().GetSession();
const TString query = fmt::format(R"(
GRANT ALL ON `/Root` TO `test@builtin`;
CREATE OBJECT TestSecret (TYPE SECRET) WITH value = `test_value`;
CREATE EXTERNAL DATA SOURCE `/Root/external_data_source` WITH (
SOURCE_TYPE="ObjectStorage",
LOCATION="{location}",
AUTH_METHOD="SERVICE_ACCOUNT",
SERVICE_ACCOUNT_ID="TestSa",
SERVICE_ACCOUNT_SECRET_NAME="TestSecret"
);)",
"location"_a = GetBucketLocation(bucket)
);
auto result = session.ExecuteSchemeQuery(query).GetValueSync();
UNIT_ASSERT_C(result.GetStatus() == NYdb::EStatus::SUCCESS, result.GetIssues().ToString());

auto db = kikimr->GetQueryClient(NYdb::NQuery::TClientSettings().AuthToken("test@builtin"));

const TString sql = R"(
SELECT * FROM `/Root/external_data_source`.`/` WITH (
SCHEMA = (data String),
FORMAT = "csv_with_names"
))";

auto scriptExecutionOperation = db.ExecuteScript(sql).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(scriptExecutionOperation.Status().GetStatus(), EStatus::SUCCESS, scriptExecutionOperation.Status().GetIssues().ToString());

NYdb::NQuery::TScriptExecutionOperation readyOp = WaitScriptExecutionOperation(scriptExecutionOperation.Id(), kikimr->GetDriver());
UNIT_ASSERT_EQUAL_C(readyOp.Metadata().ExecStatus, EExecStatus::Failed, readyOp.Status().GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(readyOp.Status().GetIssues().ToString(), "secret with name 'TestSecret' not found");
}
}

} // namespace NKikimr::NKqp

0 comments on commit 874b4bf

Please sign in to comment.