Skip to content

Commit

Permalink
Firstly search in system tables (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLolthe1st authored Feb 16, 2024
1 parent 506ecae commit 98f2f64
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
10 changes: 7 additions & 3 deletions ydb/library/yql/sql/pg/pg_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,11 @@ class TConverter : public IPGParseEvents {
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 "";
}
Expand Down Expand Up @@ -2603,7 +2607,7 @@ class TConverter : public IPGParseEvents {
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};
Expand All @@ -2630,7 +2634,7 @@ class TConverter : public IPGParseEvents {
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};
Expand Down
47 changes: 1 addition & 46 deletions ydb/library/yql/sql/pg/pg_sql_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{},
Expand All @@ -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);
}
}

0 comments on commit 98f2f64

Please sign in to comment.