diff options
author | aneporada <aneporada@yandex-team.com> | 2024-11-12 20:02:10 +0300 |
---|---|---|
committer | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2024-11-12 22:40:29 +0300 |
commit | 06791fb116406f98a10593436968aabe51d1a856 (patch) | |
tree | 3a4c8f662423b3602767da02508ce5df0f54a2f2 /yql/essentials/sql/v1/sql_ut.cpp | |
parent | 4e4600bae44c02ba4a94c8f7a397a2c63c3cc235 (diff) | |
download | ydb-06791fb116406f98a10593436968aabe51d1a856.tar.gz |
Merge PR #10831, #11068, #11075, #11152
#11152 - Allow to choose normal or aggreation PG function
#11075 - Handle invalid base
#11068 - Allow more postgis functions
#10831 - Views: if exists / if not exists for DDL
commit_hash:0ebf35e45ac6de147c9000440ca25237db061d2e
Diffstat (limited to 'yql/essentials/sql/v1/sql_ut.cpp')
-rw-r--r-- | yql/essentials/sql/v1/sql_ut.cpp | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/yql/essentials/sql/v1/sql_ut.cpp b/yql/essentials/sql/v1/sql_ut.cpp index 6663fe9765..a4251890a7 100644 --- a/yql/essentials/sql/v1/sql_ut.cpp +++ b/yql/essentials/sql/v1/sql_ut.cpp @@ -2533,8 +2533,8 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { const auto result = SqlToYql(R"(USE plato; CREATE TABLE table ( pk INT32 NOT NULL, - col String, - INDEX idx GLOBAL USING vector_kmeans_tree + col String, + INDEX idx GLOBAL USING vector_kmeans_tree ON (col) COVER (col) WITH (distance=cosine, vector_type=float, vector_dimension=1024,), PRIMARY KEY (pk)) @@ -2543,11 +2543,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { } Y_UNIT_TEST(AlterTableAddIndexVector) { - const auto result = SqlToYql(R"(USE plato; - ALTER TABLE table ADD INDEX idx - GLOBAL USING vector_kmeans_tree + const auto result = SqlToYql(R"(USE plato; + ALTER TABLE table ADD INDEX idx + GLOBAL USING vector_kmeans_tree ON (col) COVER (col) - WITH (distance=cosine, vector_type="float", vector_dimension=1024) + WITH (distance=cosine, vector_type="float", vector_dimension=1024) )"); UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString()); } @@ -2558,11 +2558,11 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { } Y_UNIT_TEST(AlterTableAddIndexMissedParameter) { - ExpectFailWithError(R"(USE plato; - ALTER TABLE table ADD INDEX idx - GLOBAL USING vector_kmeans_tree + ExpectFailWithError(R"(USE plato; + ALTER TABLE table ADD INDEX idx + GLOBAL USING vector_kmeans_tree ON (col) - WITH (distance=cosine, vector_type=float) + WITH (distance=cosine, vector_type=float) )", "<main>:5:52: Error: vector_dimension should be set\n"); } @@ -2790,7 +2790,7 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) { auto req = Sprintf(reqTpl, key.c_str(), value.c_str()); auto res = SqlToYql(req); UNIT_ASSERT(res.Root); - + TVerifyLineFunc verifyLine = [&key, &value](const TString& word, const TString& line) { if (word == "Write") { UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("MyReplication")); @@ -6716,6 +6716,28 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) { UNIT_ASSERT_C(res.Root, res.Issues.ToString()); } + Y_UNIT_TEST(CreateViewIfNotExists) { + constexpr const char* name = "TheView"; + NYql::TAstParseResult res = SqlToYql(std::format(R"( + USE plato; + CREATE VIEW IF NOT EXISTS {} WITH (security_invoker = TRUE) AS SELECT 1; + )", name + )); + UNIT_ASSERT_C(res.Root, res.Issues.ToString()); + + TVerifyLineFunc verifyLine = [&](const TString& word, const TString& line) { + if (word == "Write!") { + UNIT_ASSERT_STRING_CONTAINS(line, name); + UNIT_ASSERT_STRING_CONTAINS(line, "createObjectIfNotExists"); + } + }; + + TWordCountHive elementStat = { {"Write!"} }; + VerifyProgram(res, elementStat, verifyLine); + + UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1); + } + Y_UNIT_TEST(CreateViewFromTable) { constexpr const char* path = "/PathPrefix/TheView"; constexpr const char* query = R"( @@ -6795,6 +6817,28 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) { UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1); } + Y_UNIT_TEST(DropViewIfExists) { + constexpr const char* name = "TheView"; + NYql::TAstParseResult res = SqlToYql(std::format(R"( + USE plato; + DROP VIEW IF EXISTS {}; + )", name + )); + UNIT_ASSERT_C(res.Root, res.Issues.ToString()); + + TVerifyLineFunc verifyLine = [&](const TString& word, const TString& line) { + if (word == "Write!") { + UNIT_ASSERT_STRING_CONTAINS(line, name); + UNIT_ASSERT_STRING_CONTAINS(line, "dropObjectIfExists"); + } + }; + + TWordCountHive elementStat = { {"Write!"} }; + VerifyProgram(res, elementStat, verifyLine); + + UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1); + } + Y_UNIT_TEST(CreateViewWithTablePrefix) { NYql::TAstParseResult res = SqlToYql(R"( USE plato; @@ -6838,7 +6882,7 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) { UNIT_ASSERT_VALUES_EQUAL(elementStat["Write!"], 1); } - + Y_UNIT_TEST(YtAlternativeSchemaSyntax) { NYql::TAstParseResult res = SqlToYql(R"( SELECT * FROM plato.Input WITH schema(y Int32, x String not null); @@ -6907,7 +6951,7 @@ Y_UNIT_TEST_SUITE(CompactNamedExprs) { pragma CompactNamedExprs; pragma ValidateUnusedExprs; - define subquery $x() as + define subquery $x() as select count(1, 2); end define; select 1; @@ -6930,7 +6974,7 @@ Y_UNIT_TEST_SUITE(CompactNamedExprs) { pragma CompactNamedExprs; pragma DisableValidateUnusedExprs; - define subquery $x() as + define subquery $x() as select count(1, 2); end define; select 1; |