Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vitstn committed Oct 31, 2024
1 parent 55a88ca commit e9a26cb
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ydb/library/yql/parser/pg_catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,24 @@ void EnumProc(std::function<void(ui32, const TProcDesc&)> f) {
}
}

bool HasProc(const TString& name, EProcKind kind) {
const auto& catalog = TCatalog::Instance();
auto procIdPtr = catalog.State->ProcByName.FindPtr(to_lower(name));
if (!procIdPtr) {
return false;
}

for (const auto& id : *procIdPtr) {
const auto& d = catalog.State->Procs.FindPtr(id);
Y_ENSURE(d);
if (d->Kind == kind) {
return true;
}
}

return false;
}

bool HasReturnSetProc(const TString& name) {
const auto& catalog = TCatalog::Instance();
auto procIdPtr = catalog.State->ProcByName.FindPtr(to_lower(name));
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const TProcDesc& LookupProc(ui32 procId);
std::variant<const TProcDesc*, const TTypeDesc*> LookupProcWithCasts(const TString& name, const TVector<ui32>& argTypeIds);
bool HasReturnSetProc(const TString& name);
void EnumProc(std::function<void(ui32, const TProcDesc&)> f);
bool HasProc(const TString& name, EProcKind kind);

bool HasType(const TString& name);
bool HasType(ui32 typeId);
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_catalog/safe_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"postgis_lib_version",
"st_interiorringn",
"st_collectionhomogenize",
"st_makeline",

//dbeaver
"pg_get_expr",
Expand Down
28 changes: 26 additions & 2 deletions ydb/library/yql/sql/v1/builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3422,15 +3422,39 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec
}
} else if (ns == "datetime2" && (name == "Parse")) {
return BuildUdf(ctx, pos, nameSpace, name, args);
} else if (ns == "pg") {
const bool isAggregateFunc = NYql::NPg::HasAggregation(name, NYql::NPg::EAggKind::Normal);
} else if (ns == "pg" || ns == "pgagg" || ns == "pgproc") {
bool isAggregateFunc = NYql::NPg::HasAggregation(name, NYql::NPg::EAggKind::Normal);
bool isNormalFunc = NYql::NPg::HasProc(name, NYql::NPg::EProcKind::Function);
if (!isAggregateFunc && !isNormalFunc) {
return new TInvalidBuiltin(pos, TStringBuilder() << "Unknown function: " << name);
}

if (isAggregateFunc && isNormalFunc) {
if (ns == "pg") {
return new TInvalidBuiltin(pos, TStringBuilder() << "Ambigious function: " << name << ", use either PgAgg:: or PgProc:: namespace");
} else if (ns == "pgagg") {
isNormalFunc = false;
} else {
isAggregateFunc = false;
}
}

if (isAggregateFunc && ns == "pgproc") {
return new TInvalidBuiltin(pos, TStringBuilder() << "Invalid namespace for aggregation function: " << name << ", use either Pg:: or PgAgg:: namespace");
}

if (isNormalFunc && ns == "pgagg") {
return new TInvalidBuiltin(pos, TStringBuilder() << "Invalid namespace for normal function: " << name << ", use either Pg:: or PgProc:: namespace");
}

if (isAggregateFunc) {
if (aggMode == EAggregateMode::Distinct) {
return new TInvalidBuiltin(pos, "Distinct is not supported yet for PG aggregation ");
}

return BuildAggrFuncFactoryCallback(name, "", EAggrFuncTypeCallback::PG)(pos, args, aggMode, false);
} else {
YQL_ENSURE(isNormalFunc);
TVector<TNodePtr> pgCallArgs;
pgCallArgs.push_back(BuildLiteralRawString(pos, name));
pgCallArgs.insert(pgCallArgs.end(), args.begin(), args.end());
Expand Down
44 changes: 44 additions & 0 deletions ydb/library/yql/tests/sql/dq_file/part2/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,50 @@
}
],
"test.test[pg-join_using_multiple2--Results]": [],
"test.test[pg-pgns_agg-default.txt-Analyze]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Analyze_/plan.txt"
}
],
"test.test[pg-pgns_agg-default.txt-Debug]": [
{
"checksum": "c62f85fabe40a18829587ccbbdbaee91",
"size": 446,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg-pgns_agg-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_agg-default.txt-Results]": [],
"test.test[pg-pgns_proc-default.txt-Analyze]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Analyze_/plan.txt"
}
],
"test.test[pg-pgns_proc-default.txt-Debug]": [
{
"checksum": "2fcd7306a350cf965b03048751c38368",
"size": 344,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg-pgns_proc-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1871002/e16c2456d2585dc5260dae8153efad865802ebff/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_proc-default.txt-Results]": [],
"test.test[pg-select_agg-default.txt-Analyze]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
Expand Down
28 changes: 28 additions & 0 deletions ydb/library/yql/tests/sql/hybrid_file/part0/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,34 @@
"uri": "https://{canondata_backend}/1936947/581aa6d896ffe57e25bdb8006459e912860e61fa/resource.tar.gz#test.test_pg-pg_in_expr-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_agg-default.txt-Debug]": [
{
"checksum": "7c56fcc35df8e04017352ad60d1ca319",
"size": 445,
"uri": "https://{canondata_backend}/1942525/5034185140ffa064b6ff5f40aec4f177acd3c5a1/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg-pgns_agg-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1942525/5034185140ffa064b6ff5f40aec4f177acd3c5a1/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_proc-default.txt-Debug]": [
{
"checksum": "8a265371cc480c231744f2eb58cebd6a",
"size": 343,
"uri": "https://{canondata_backend}/1942525/5034185140ffa064b6ff5f40aec4f177acd3c5a1/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[pg-pgns_proc-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1942525/5034185140ffa064b6ff5f40aec4f177acd3c5a1/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-select_agg_expr_order-default.txt-Debug]": [
{
"checksum": "dd4cae1f250ec04efe611cc4e2f7e505",
Expand Down
28 changes: 28 additions & 0 deletions ydb/library/yql/tests/sql/sql2yql/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -12942,6 +12942,20 @@
"uri": "https://{canondata_backend}/1881367/79a71c1478c556da1931a7565c12bdd14cc63567/resource.tar.gz#test_sql2yql.test_pg-pg_view_/sql.yql"
}
],
"test_sql2yql.test[pg-pgns_agg]": [
{
"checksum": "d8084a6545a07f42528921be288eb18a",
"size": 1622,
"uri": "https://{canondata_backend}/1942278/f9767af57fb40678ebac7071b53e03ed182ae745/resource.tar.gz#test_sql2yql.test_pg-pgns_agg_/sql.yql"
}
],
"test_sql2yql.test[pg-pgns_proc]": [
{
"checksum": "8c7e5172b26cd5d3be6d582c0f8d9ab0",
"size": 1014,
"uri": "https://{canondata_backend}/1942278/f9767af57fb40678ebac7071b53e03ed182ae745/resource.tar.gz#test_sql2yql.test_pg-pgns_proc_/sql.yql"
}
],
"test_sql2yql.test[pg-point]": [
{
"checksum": "eb9eb97cbb091b3417869b7e742edaa5",
Expand Down Expand Up @@ -32115,6 +32129,20 @@
"uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_pg-pg_types_literal_with_length_/formatted.sql"
}
],
"test_sql_format.test[pg-pgns_agg]": [
{
"checksum": "76c561d4b5ced5a600630822124835a2",
"size": 57,
"uri": "https://{canondata_backend}/1942278/f9767af57fb40678ebac7071b53e03ed182ae745/resource.tar.gz#test_sql_format.test_pg-pgns_agg_/formatted.sql"
}
],
"test_sql_format.test[pg-pgns_proc]": [
{
"checksum": "24413a1cdf3177e0adea1760335ec372",
"size": 32,
"uri": "https://{canondata_backend}/1942278/f9767af57fb40678ebac7071b53e03ed182ae745/resource.tar.gz#test_sql_format.test_pg-pgns_proc_/formatted.sql"
}
],
"test_sql_format.test[pg-reflection]": [
{
"checksum": "65481055414382285e38644c195cc090",
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/yql/tests/sql/suites/pg/pgns_agg.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select PgAgg::count() from (select 1);

1 change: 1 addition & 0 deletions ydb/library/yql/tests/sql/suites/pg/pgns_proc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select PgProc::upper('a'u);
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,48 @@
"uri": "https://{canondata_backend}/1946324/7d1d6b1f697cbe9fb62c81047eb61d3fa72baf62/resource.tar.gz#test.test_pg-join_using_multiple2--Results_/results.txt"
}
],
"test.test[pg-pgns_agg-default.txt-Debug]": [
{
"checksum": "1a4923d66dd787df594ce62653e213a9",
"size": 378,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Debug_/opt.yql"
}
],
"test.test[pg-pgns_agg-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_agg-default.txt-Results]": [
{
"checksum": "6a00eb838183e16098feefe4a7d81bed",
"size": 733,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_agg-default.txt-Results_/results.txt"
}
],
"test.test[pg-pgns_proc-default.txt-Debug]": [
{
"checksum": "af182fe1c8fc87eeb63c9a584dcaf30a",
"size": 276,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Debug_/opt.yql"
}
],
"test.test[pg-pgns_proc-default.txt-Plan]": [
{
"checksum": "b4dd508a329723c74293d80f0278c705",
"size": 505,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Plan_/plan.txt"
}
],
"test.test[pg-pgns_proc-default.txt-Results]": [
{
"checksum": "deb8e87729873be62e40545c9b57a906",
"size": 733,
"uri": "https://{canondata_backend}/1942525/526b4d04c2d9ca7b67c4128634cdf050f1482988/resource.tar.gz#test.test_pg-pgns_proc-default.txt-Results_/results.txt"
}
],
"test.test[pg-select_agg-default.txt-Debug]": [
{
"checksum": "b9d62afa0b411dfbe3a9e7d76f997c60",
Expand Down

0 comments on commit e9a26cb

Please sign in to comment.