diff options
author | tsmax2004 <tsmax2004@yandex-team.com> | 2023-10-13 18:22:54 +0300 |
---|---|---|
committer | tsmax2004 <tsmax2004@yandex-team.com> | 2023-10-13 18:57:43 +0300 |
commit | 5491a4bbfe9c10211bcce661eca0386adc738cc1 (patch) | |
tree | ebfae2218ef64e13ab9be05b897546f7a9b29882 | |
parent | 653f57be2e8bf12d7657506bc0d108196cc500b5 (diff) | |
download | ydb-5491a4bbfe9c10211bcce661eca0386adc738cc1.tar.gz |
[YQ] encapsulation of db name in connection
4 files changed, 36 insertions, 14 deletions
diff --git a/ydb/core/fq/libs/actors/clusters_from_connections.cpp b/ydb/core/fq/libs/actors/clusters_from_connections.cpp index f74382da7c..ae1cdb40ca 100644 --- a/ydb/core/fq/libs/actors/clusters_from_connections.cpp +++ b/ydb/core/fq/libs/actors/clusters_from_connections.cpp @@ -101,6 +101,7 @@ void FillGenericClusterConfig( clusterCfg.SetKind(dataSourceKind); clusterCfg.SetName(connectionName); clusterCfg.SetDatabaseId(connection.database_id()); + clusterCfg.SetDatabaseName(connection.database_name()); clusterCfg.mutable_credentials()->mutable_basic()->set_username(connection.login()); clusterCfg.mutable_credentials()->mutable_basic()->set_password(connection.password()); FillClusterAuth(clusterCfg, connection.auth(), authToken, accountIdSignatures); diff --git a/ydb/library/yql/providers/generic/provider/yql_generic_cluster_config.cpp b/ydb/library/yql/providers/generic/provider/yql_generic_cluster_config.cpp index 542cebc9f5..6bf01f1bea 100644 --- a/ydb/library/yql/providers/generic/provider/yql_generic_cluster_config.cpp +++ b/ydb/library/yql/providers/generic/provider/yql_generic_cluster_config.cpp @@ -110,13 +110,13 @@ namespace NYql { NYql::TGenericClusterConfig& clusterConfig) { auto it = properties.find("database_name"); if (it == properties.cend()) { - // TODO: make this property required during https://st.yandex-team.ru/YQ-2184 + // TODO: make this property required during https://st.yandex-team.ru/YQ-2494 // ythrow yexception() << "missing 'DATABASE_NAME' value"; return; } if (!it->second) { - // TODO: make this property required during https://st.yandex-team.ru/YQ-2184 + // TODO: make this property required during https://st.yandex-team.ru/YQ-2494 // ythrow yexception() << "invalid 'DATABASE_NAME' value: '" << it->second << "'"; return; } @@ -353,7 +353,7 @@ namespace NYql { } // TODO: validate Credentials.basic.password after ClickHouse recipe fix - // TODO: validate DatabaseName field when it is supported on frontend + // TODO: validate DatabaseName field during https://st.yandex-team.ru/YQ-2494 if (clusterConfig.GetProtocol() == EProtocol::PROTOCOL_UNSPECIFIED) { return ValidationError(clusterConfig, context, "empty field 'Protocol'"); diff --git a/ydb/library/yql/providers/generic/provider/yql_generic_dq_integration.cpp b/ydb/library/yql/providers/generic/provider/yql_generic_dq_integration.cpp index 30c17ac2d1..a73e527176 100644 --- a/ydb/library/yql/providers/generic/provider/yql_generic_dq_integration.cpp +++ b/ydb/library/yql/providers/generic/provider/yql_generic_dq_integration.cpp @@ -101,16 +101,16 @@ namespace NYql { Generic::TSource srcDesc; srcDesc.set_token(token); + // for backward compability full path can be used (cluster_name.`db_name.table`) + // TODO: simplify during https://st.yandex-team.ru/YQ-2494 TStringBuf db, dbTable; if (!TStringBuf(table).TrySplit('.', db, dbTable)) { - db = "default"; dbTable = table; } YQL_CLOG(INFO, ProviderGeneric) << "Filling source settings" << ": cluster: " << clusterName - << ", database: " << db << ", table: " << table << ", endpoint: " << endpoint.ShortDebugString(); diff --git a/ydb/library/yql/providers/generic/provider/yql_generic_load_meta.cpp b/ydb/library/yql/providers/generic/provider/yql_generic_load_meta.cpp index 8b1da767f0..421e626262 100644 --- a/ydb/library/yql/providers/generic/provider/yql_generic_load_meta.cpp +++ b/ydb/library/yql/providers/generic/provider/yql_generic_load_meta.cpp @@ -107,23 +107,44 @@ namespace NYql { YQL_ENSURE(State_->Configuration->ClusterNamesToClusterConfigs.cend() != it, "cluster not found: " << clusterName); const auto& clusterConfig = it->second; + const auto dataSourceKind = clusterConfig.GetKind(); auto dsi = request.mutable_data_source_instance(); dsi->mutable_endpoint()->CopyFrom(clusterConfig.GetEndpoint()); - dsi->set_kind(clusterConfig.GetKind()); + dsi->set_kind(dataSourceKind); dsi->mutable_credentials()->CopyFrom(clusterConfig.GetCredentials()); dsi->set_use_tls(clusterConfig.GetUseSsl()); dsi->set_protocol(clusterConfig.GetProtocol()); - const auto& table = item.second; - TStringBuf db, dbTable; - if (!TStringBuf(table).TrySplit('.', db, dbTable)) { - db = "default"; - dbTable = table; - } + // for backward compability full path can be used (cluster_name.`db_name.table`) + // TODO: simplify during https://st.yandex-team.ru/YQ-2494 + const auto& tablePath = item.second; + const auto& dbNameFromConfig = clusterConfig.GetDatabaseName(); + TStringBuf dbNameTarget, tableName; + auto isFullPath = TStringBuf(tablePath).TrySplit('.', dbNameTarget, tableName); + + if (!dbNameFromConfig.empty()) { + dbNameTarget = dbNameFromConfig; + if (!isFullPath) { + tableName = tablePath; + } + } else if (!isFullPath) { + tableName = tablePath; + switch (dataSourceKind) { + case NYql::NConnector::NApi::CLICKHOUSE: + dbNameTarget = "default"; + break; + case NYql::NConnector::NApi::POSTGRESQL: + dbNameTarget = "postgres"; + break; + default: + ythrow yexception() << "Unexpected data source kind: '" + << NYql::NConnector::NApi::EDataSourceKind_Name(dataSourceKind) << "'"; + } + } // else take database name from table path - dsi->set_database(TString(db)); - request.set_table(TString(dbTable)); + dsi->set_database(TString(dbNameTarget)); + request.set_table(TString(tableName)); // NOTE: errors will be checked further in DoApplyAsyncChanges Results_.emplace(item, TGenericTableDescription(request.data_source_instance(), State_->GenericClient->DescribeTable(request))); |