aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvvvv <vvvv@yandex-team.ru>2022-02-23 13:46:24 +0300
committervvvv <vvvv@yandex-team.ru>2022-02-23 13:46:24 +0300
commiteb3d75399185dcb1bf88ae2360fddbbfe9429390 (patch)
tree3394981f089f4b4c462e52ae5087471aaf7e34f4
parent3a74ef5bf5fe05fb703bfcb0c1f5adcb33d3252c (diff)
downloadydb-eb3d75399185dcb1bf88ae2360fddbbfe9429390.tar.gz
YQL-13710 don't build type string in catalog
ref:b8d91a0cac65c81b645ef64772ab56ed272fb79a
-rw-r--r--ydb/library/yql/parser/pg_catalog/catalog.cpp49
-rw-r--r--ydb/library/yql/parser/pg_catalog/catalog.h29
-rw-r--r--ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp16
3 files changed, 45 insertions, 49 deletions
diff --git a/ydb/library/yql/parser/pg_catalog/catalog.cpp b/ydb/library/yql/parser/pg_catalog/catalog.cpp
index 60e2c2ab30..6071c93c48 100644
--- a/ydb/library/yql/parser/pg_catalog/catalog.cpp
+++ b/ydb/library/yql/parser/pg_catalog/catalog.cpp
@@ -8,33 +8,8 @@
namespace NYql {
-enum class EOperKind {
- Binary,
- LeftUnary,
- RightUnary
-};
-
-struct TOperDesc {
- ui32 OperId = 0;
- EOperKind Kind = EOperKind::Binary;
- TString LeftType;
- TString RightType;
- TString ResultType;
- TString Code;
-};
-
using TOperators = THashMap<ui32, TOperDesc>;
-struct TProcDesc {
- ui32 ProcId = 0;
- TString Name;
- TString Src;
- TVector<TString> ArgTypes;
- TString ResultType;
- bool IsStrict = true;
- bool IsVariadic = false;
-};
-
using TProcs = THashMap<ui32, TProcDesc>;
class TParser {
@@ -217,8 +192,8 @@ struct TCatalog {
Operators = ParseOperators(opData);
Procs = ParseProcs(procData);
for (const auto& [k, v]: Procs) {
- ProcByName[v.Name].push_back(k);
- ProcBySrc[v.Src] = k;
+ ProcByName[v.Name].push_back(k);
+ ProcBySrc[v.Src] = k;
}
}
@@ -232,7 +207,7 @@ struct TCatalog {
THashMap<TString, ui32> ProcBySrc;
};
-TMaybe<TString> LookupFunctionSignature(const TString& name) {
+const TProcDesc* LookupFunctionSignature(const TString& name) {
const auto& catalog = TCatalog::Instance();
auto srcIdPtr = catalog.ProcBySrc.FindPtr(name);
ui32 procId;
@@ -241,7 +216,7 @@ TMaybe<TString> LookupFunctionSignature(const TString& name) {
} else {
auto procIdPtr = catalog.ProcByName.FindPtr(name);
if (!procIdPtr) {
- return Nothing();
+ return nullptr;
}
if (procIdPtr->size() != 1) {
@@ -253,21 +228,7 @@ TMaybe<TString> LookupFunctionSignature(const TString& name) {
auto desc = catalog.Procs.FindPtr(procId);
Y_ENSURE(desc);
- TStringBuilder builder;
- builder << "Callable<(";
- for (size_t i = 0; i < desc->ArgTypes.size(); ++i) {
- if (i) {
- builder << ',';
- }
-
- builder << "pg_" << desc->ArgTypes[i];
- }
-
- builder << ")->";
- builder << "pg_" << desc->ResultType;
- builder << ">";
-
- return builder;
+ return desc;
}
}
diff --git a/ydb/library/yql/parser/pg_catalog/catalog.h b/ydb/library/yql/parser/pg_catalog/catalog.h
index b57bf4c034..fbfaaf727d 100644
--- a/ydb/library/yql/parser/pg_catalog/catalog.h
+++ b/ydb/library/yql/parser/pg_catalog/catalog.h
@@ -1,9 +1,34 @@
#pragma once
-#include <util/generic/string.h>
#include <util/generic/maybe.h>
+#include <util/generic/string.h>
+#include <util/generic/vector.h>
namespace NYql {
-TMaybe<TString> LookupFunctionSignature(const TString& name);
+enum class EOperKind {
+ Binary,
+ LeftUnary,
+ RightUnary
+};
+
+struct TOperDesc {
+ ui32 OperId = 0;
+ EOperKind Kind = EOperKind::Binary;
+ TString LeftType;
+ TString RightType;
+ TString ResultType;
+ TString Code;
+};
+
+struct TProcDesc {
+ ui32 ProcId = 0;
+ TString Name;
+ TString Src;
+ TVector<TString> ArgTypes;
+ TString ResultType;
+ bool IsStrict = true;
+};
+
+const TProcDesc* LookupFunctionSignature(const TString& name);
}
diff --git a/ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp b/ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp
index 63d93fa9e3..89f0adb728 100644
--- a/ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp
+++ b/ydb/library/yql/parser/pg_catalog/ut/catalog_ut.cpp
@@ -17,14 +17,24 @@ Y_UNIT_TEST_SUITE(TFunctionsTests) {
Y_UNIT_TEST(TestOk) {
auto ret = LookupFunctionSignature("int4pl");
UNIT_ASSERT(ret);
- UNIT_ASSERT_NO_DIFF(*ret, "Callable<(pg_int4,pg_int4)->pg_int4>");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ResultType, "int4");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes.size(), 2);
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[0], "int4");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[1], "int4");
ret = LookupFunctionSignature("text_substr");
UNIT_ASSERT(ret);
- UNIT_ASSERT_NO_DIFF(*ret, "Callable<(pg_text,pg_int4,pg_int4)->pg_text>");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ResultType, "text");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes.size(), 3);
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[0], "text");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[1], "int4");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[2], "int4");
ret = LookupFunctionSignature("text_substr_no_len");
UNIT_ASSERT(ret);
- UNIT_ASSERT_NO_DIFF(*ret, "Callable<(pg_text,pg_int4)->pg_text>");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ResultType, "text");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes.size(), 2);
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[0], "text");
+ UNIT_ASSERT_VALUES_EQUAL(ret->ArgTypes[1], "int4");
}
}