diff options
author | Александр Новожилов <mrlolthe1st@ydb.tech> | 2024-02-16 15:09:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 15:09:19 +0300 |
commit | 98f2f64353081f6e236b560c292cf0f0de68fa51 (patch) | |
tree | c8a0b8b8f667366cea5e3dba01b99376d61b36cd | |
parent | 506ecaee93b52cc12c2e2f97c3d42e3ca2a7f59e (diff) | |
download | ydb-98f2f64353081f6e236b560c292cf0f0de68fa51.tar.gz |
Firstly search in system tables (#1991)
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql.cpp | 10 | ||||
-rw-r--r-- | ydb/library/yql/sql/pg/pg_sql_ut.cpp | 47 |
2 files changed, 8 insertions, 49 deletions
diff --git a/ydb/library/yql/sql/pg/pg_sql.cpp b/ydb/library/yql/sql/pg/pg_sql.cpp index 1c05938c66..b45ed33872 100644 --- a/ydb/library/yql/sql/pg/pg_sql.cpp +++ b/ydb/library/yql/sql/pg/pg_sql.cpp @@ -2549,7 +2549,11 @@ public: return true; } - TString ResolveCluster(const TStringBuf schemaname) { + TString ResolveCluster(const TStringBuf schemaname, TString name) { + if (NYql::NPg::GetStaticColumns().contains(NPg::TTableInfoKey{"pg_catalog", name})) { + return "pg_catalog"; + } + if (schemaname == "public") { return ""; } @@ -2603,7 +2607,7 @@ public: return {}; } - const auto cluster = ResolveCluster(schemaname); + const auto cluster = ResolveCluster(schemaname, TString(relname)); const auto sinkOrSource = BuildClusterSinkOrSourceExpression(isSink, cluster); const auto key = BuildTableKeyExpression(relname, cluster, isScheme); return {sinkOrSource, key}; @@ -2630,7 +2634,7 @@ public: return {}; } - const auto cluster = ResolveCluster(schemaname); + const auto cluster = ResolveCluster(schemaname, TString(objectName)); const auto sinkOrSource = BuildClusterSinkOrSourceExpression(true, cluster); const auto key = BuildPgObjectExpression(objectName, pgObjectType); return {sinkOrSource, key}; diff --git a/ydb/library/yql/sql/pg/pg_sql_ut.cpp b/ydb/library/yql/sql/pg/pg_sql_ut.cpp index d99fcfaa61..77fa0b91ec 100644 --- a/ydb/library/yql/sql/pg/pg_sql_ut.cpp +++ b/ydb/library/yql/sql/pg/pg_sql_ut.cpp @@ -518,18 +518,7 @@ from pg_catalog.pg_type)", UNIT_ASSERT(res.Root); res = SqlToYqlWithMode( - R"(select set_config('search_path', 'yql', false);)", - NSQLTranslation::ESqlMode::QUERY, - 10, - {}, - EDebugOutput::None, - false, - settings); - UNIT_ASSERT(!res.IsOk()); - UNIT_ASSERT(!res.Root); - - res = SqlToYqlWithMode( - R"(select set_config('search_path', 'pg_catalog', false);)", + R"(select * from pg_type;)", NSQLTranslation::ESqlMode::QUERY, 10, {}, @@ -538,39 +527,5 @@ from pg_catalog.pg_type)", settings); UNIT_ASSERT(res.IsOk()); UNIT_ASSERT(res.Root); - - res = SqlToYqlWithMode( - R"(rollback;)", - NSQLTranslation::ESqlMode::QUERY, - 10, - {}, - EDebugOutput::None, - false, - settings); - UNIT_ASSERT(res.IsOk()); - UNIT_ASSERT(res.Root); - - google::protobuf::Arena arena; - const auto service = TString(NYql::YtProviderName); - settings.ClusterMapping["hahn"] = NYql::YtProviderName; - settings.ClusterMapping["mon"] = NYql::SolomonProviderName; - settings.MaxErrors = 10; - settings.Mode = NSQLTranslation::ESqlMode::QUERY; - settings.Arena = &arena; - settings.AnsiLexer = false; - settings.SyntaxVersion = 1; - settings.PgParser = true; - - res = SqlToYql( - R"(select oid, -typinput::int4 as typinput, -typname, -typnamespace, -typtype -from pg_type)", - settings); - UNIT_ASSERT(res.Issues.ToString().Contains("Unknown cluster:")); - UNIT_ASSERT(!res.IsOk()); - UNIT_ASSERT(!res.Root); } } |