summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql
diff options
context:
space:
mode:
authorVasily Gerasimov <[email protected]>2025-05-21 12:38:34 +0300
committerrobot-piglet <[email protected]>2025-05-21 12:56:47 +0300
commita3559d6fde15102e1c1731e4bf7ee5cb0040a59d (patch)
tree269b93f8748ade18662fab8c12281e290b11bc01 /yql/essentials/sql
parent0a389f06b20b9bf1811bf0c3228fa32d0375a1c2 (diff)
Fix parsing INDEX GLOBAL (SYNC|ASYNC)
* Changelog entry Type: fix Component: yql Fix parsing unique index type. There was an error that, if not specified explicitly (SYNC or ASYNC), index type remained with the default value GLOBAL SYNC, despite that it was explicitly specified as UNIQUE in query. https://github.com/ydb-platform/ydb/issues/17885 --- Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1287 commit_hash:60de1b723fb1229f2197087fe21db67c72ccbd13
Diffstat (limited to 'yql/essentials/sql')
-rw-r--r--yql/essentials/sql/v1/sql_translation.cpp26
-rw-r--r--yql/essentials/sql/v1/sql_ut_common.h108
2 files changed, 124 insertions, 10 deletions
diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp
index df9f48f262a..264601ed460 100644
--- a/yql/essentials/sql/v1/sql_translation.cpp
+++ b/yql/essentials/sql/v1/sql_translation.cpp
@@ -661,24 +661,30 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector<TI
if (globalIndex.HasBlock2()) {
uniqIndex = true;
}
+ bool sync = true;
if (globalIndex.HasBlock3()) {
const TString token = to_lower(Ctx.Token(globalIndex.GetBlock3().GetToken1()));
if (token == "sync") {
- if (uniqIndex) {
- indexes.back().Type = TIndexDescription::EType::GlobalSyncUnique;
- } else {
- indexes.back().Type = TIndexDescription::EType::GlobalSync;
- }
+ sync = true;
} else if (token == "async") {
- if (uniqIndex) {
- AltNotImplemented("unique", indexType);
- return false;
- }
- indexes.back().Type = TIndexDescription::EType::GlobalAsync;
+ sync = false;
} else {
Y_ABORT("You should change implementation according to grammar changes");
}
}
+ if (sync) {
+ if (uniqIndex) {
+ indexes.back().Type = TIndexDescription::EType::GlobalSyncUnique;
+ } else {
+ indexes.back().Type = TIndexDescription::EType::GlobalSync;
+ }
+ } else {
+ if (uniqIndex) {
+ AltNotImplemented("unique", indexType);
+ return false;
+ }
+ indexes.back().Type = TIndexDescription::EType::GlobalAsync;
+ }
}
break;
// "LOCAL"
diff --git a/yql/essentials/sql/v1/sql_ut_common.h b/yql/essentials/sql/v1/sql_ut_common.h
index 8b160dab1b5..15ef58b8d86 100644
--- a/yql/essentials/sql/v1/sql_ut_common.h
+++ b/yql/essentials/sql/v1/sql_ut_common.h
@@ -2957,6 +2957,114 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
#endif
}
+ Y_UNIT_TEST(CreateTableAddIndexGlobalUnique) {
+ NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
+ CREATE TABLE table (
+ pk INT32 NOT NULL,
+ col String,
+ INDEX idx GLOBAL UNIQUE ON(col),
+ PRIMARY KEY (pk))
+ )sql");
+ UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
+ UNIT_ASSERT(result.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ Y_UNUSED(word);
+ UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
+ };
+
+ TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
+ VerifyProgram(result, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
+ }
+
+ Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueSync) {
+ NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
+ CREATE TABLE table (
+ pk INT32 NOT NULL,
+ col String,
+ INDEX idx GLOBAL UNIQUE SYNC ON(col),
+ PRIMARY KEY (pk))
+ )sql");
+ UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
+ UNIT_ASSERT(result.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ Y_UNUSED(word);
+ UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
+ };
+
+ TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
+ VerifyProgram(result, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
+ }
+
+ Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueAsync) {
+#if ANTLR_VER == 3
+ ExpectFailWithFuzzyError(R"sql(USE plato;
+ CREATE TABLE table (
+ pk INT32 NOT NULL,
+ col String,
+ INDEX idx GLOBAL UNIQUE ASYNC ON(col),
+ PRIMARY KEY (pk))
+ )sql",
+ "<main>:5:41: Error: unique: alternative is not implemented yet: \\d+:\\d+: global_index\\n");
+#else
+ ExpectFailWithError(R"sql(USE plato;
+ CREATE TABLE table (
+ pk INT32 NOT NULL,
+ col String,
+ INDEX idx GLOBAL UNIQUE ASYNC ON(col),
+ PRIMARY KEY (pk))
+ )sql",
+ "<main>:5:41: Error: unique: alternative is not implemented yet: \n");
+#endif
+ }
+
+ Y_UNIT_TEST(AlterTableAddIndexGlobalUnique) {
+ NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
+ ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ON(col))sql");
+ UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
+ UNIT_ASSERT(result.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ Y_UNUSED(word);
+ UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
+ };
+
+ TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
+ VerifyProgram(result, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
+ }
+
+ Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueSync) {
+ NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
+ ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE SYNC ON(col))sql");
+ UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
+ UNIT_ASSERT(result.Root);
+
+ TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
+ Y_UNUSED(word);
+ UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
+ };
+
+ TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
+ VerifyProgram(result, elementStat, verifyLine);
+ UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
+ }
+
+ Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueAsync) {
+#if ANTLR_VER == 3
+ ExpectFailWithFuzzyError(R"sql(USE plato;
+ ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ASYNC ON(col))sql",
+ "<main>:2:59: Error: unique: alternative is not implemented yet: \\d+:\\d+: global_index\\n");
+#else
+ ExpectFailWithError(R"sql(USE plato;
+ ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ASYNC ON(col))sql",
+ "<main>:2:59: Error: unique: alternative is not implemented yet: \n");
+#endif
+ }
+
Y_UNIT_TEST(CreateTableAddIndexVector) {
const auto result = SqlToYql(R"(USE plato;
CREATE TABLE table (