Skip to content

Commit 0f0d954

Browse files
authored
Fix parsing INDEX GLOBAL (SYNC|ASYNC) (#18647)
2 parents e18f0dd + 359b511 commit 0f0d954

File tree

3 files changed

+198
-10
lines changed

3 files changed

+198
-10
lines changed

yql/essentials/sql/v1/sql_translation.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,24 +662,30 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector<TI
662662
if (globalIndex.HasBlock2()) {
663663
uniqIndex = true;
664664
}
665+
bool sync = true;
665666
if (globalIndex.HasBlock3()) {
666667
const TString token = to_lower(Ctx.Token(globalIndex.GetBlock3().GetToken1()));
667668
if (token == "sync") {
668-
if (uniqIndex) {
669-
indexes.back().Type = TIndexDescription::EType::GlobalSyncUnique;
670-
} else {
671-
indexes.back().Type = TIndexDescription::EType::GlobalSync;
672-
}
669+
sync = true;
673670
} else if (token == "async") {
674-
if (uniqIndex) {
675-
AltNotImplemented("unique", indexType);
676-
return false;
677-
}
678-
indexes.back().Type = TIndexDescription::EType::GlobalAsync;
671+
sync = false;
679672
} else {
680673
Y_ABORT("You should change implementation according to grammar changes");
681674
}
682675
}
676+
if (sync) {
677+
if (uniqIndex) {
678+
indexes.back().Type = TIndexDescription::EType::GlobalSyncUnique;
679+
} else {
680+
indexes.back().Type = TIndexDescription::EType::GlobalSync;
681+
}
682+
} else {
683+
if (uniqIndex) {
684+
AltNotImplemented("unique", indexType);
685+
return false;
686+
}
687+
indexes.back().Type = TIndexDescription::EType::GlobalAsync;
688+
}
683689
}
684690
break;
685691
// "LOCAL"

yql/essentials/sql/v1/sql_ut.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,97 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
27172717
"<main>:1:40: Error: local: alternative is not implemented yet: \\d+:\\d+: local_index\\n");
27182718
}
27192719

2720+
Y_UNIT_TEST(CreateTableAddIndexGlobalUnique) {
2721+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2722+
CREATE TABLE table (
2723+
pk INT32 NOT NULL,
2724+
col String,
2725+
INDEX idx GLOBAL UNIQUE ON(col),
2726+
PRIMARY KEY (pk))
2727+
)sql");
2728+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2729+
UNIT_ASSERT(result.Root);
2730+
2731+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2732+
Y_UNUSED(word);
2733+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2734+
};
2735+
2736+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
2737+
VerifyProgram(result, elementStat, verifyLine);
2738+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
2739+
}
2740+
2741+
Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueSync) {
2742+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2743+
CREATE TABLE table (
2744+
pk INT32 NOT NULL,
2745+
col String,
2746+
INDEX idx GLOBAL UNIQUE SYNC ON(col),
2747+
PRIMARY KEY (pk))
2748+
)sql");
2749+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2750+
UNIT_ASSERT(result.Root);
2751+
2752+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2753+
Y_UNUSED(word);
2754+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2755+
};
2756+
2757+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
2758+
VerifyProgram(result, elementStat, verifyLine);
2759+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
2760+
}
2761+
2762+
Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueAsync) {
2763+
ExpectFailWithFuzzyError(R"sql(USE plato;
2764+
CREATE TABLE table (
2765+
pk INT32 NOT NULL,
2766+
col String,
2767+
INDEX idx GLOBAL UNIQUE ASYNC ON(col),
2768+
PRIMARY KEY (pk))
2769+
)sql",
2770+
"<main>:5:41: Error: unique: alternative is not implemented yet: \\d+:\\d+: global_index\\n");
2771+
}
2772+
2773+
Y_UNIT_TEST(AlterTableAddIndexGlobalUnique) {
2774+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2775+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ON(col))sql");
2776+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2777+
UNIT_ASSERT(result.Root);
2778+
2779+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2780+
Y_UNUSED(word);
2781+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2782+
};
2783+
2784+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
2785+
VerifyProgram(result, elementStat, verifyLine);
2786+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
2787+
}
2788+
2789+
Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueSync) {
2790+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2791+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE SYNC ON(col))sql");
2792+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2793+
UNIT_ASSERT(result.Root);
2794+
2795+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2796+
Y_UNUSED(word);
2797+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2798+
};
2799+
2800+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
2801+
VerifyProgram(result, elementStat, verifyLine);
2802+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
2803+
}
2804+
2805+
Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueAsync) {
2806+
ExpectFailWithFuzzyError(R"sql(USE plato;
2807+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ASYNC ON(col))sql",
2808+
"<main>:2:59: Error: unique: alternative is not implemented yet: \\d+:\\d+: global_index\\n");
2809+
}
2810+
27202811
Y_UNIT_TEST(CreateTableAddIndexVector) {
27212812
const auto result = SqlToYql(R"(USE plato;
27222813
CREATE TABLE table (

yql/essentials/sql/v1/sql_ut_antlr4.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,97 @@ Y_UNIT_TEST_SUITE(SqlParsingOnly) {
29592959
"<main>:1:40: Error: local: alternative is not implemented yet: \n");
29602960
}
29612961

2962+
Y_UNIT_TEST(CreateTableAddIndexGlobalUnique) {
2963+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2964+
CREATE TABLE table (
2965+
pk INT32 NOT NULL,
2966+
col String,
2967+
INDEX idx GLOBAL UNIQUE ON(col),
2968+
PRIMARY KEY (pk))
2969+
)sql");
2970+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2971+
UNIT_ASSERT(result.Root);
2972+
2973+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2974+
Y_UNUSED(word);
2975+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2976+
};
2977+
2978+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
2979+
VerifyProgram(result, elementStat, verifyLine);
2980+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
2981+
}
2982+
2983+
Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueSync) {
2984+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
2985+
CREATE TABLE table (
2986+
pk INT32 NOT NULL,
2987+
col String,
2988+
INDEX idx GLOBAL UNIQUE SYNC ON(col),
2989+
PRIMARY KEY (pk))
2990+
)sql");
2991+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
2992+
UNIT_ASSERT(result.Root);
2993+
2994+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
2995+
Y_UNUSED(word);
2996+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
2997+
};
2998+
2999+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
3000+
VerifyProgram(result, elementStat, verifyLine);
3001+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
3002+
}
3003+
3004+
Y_UNIT_TEST(CreateTableAddIndexGlobalUniqueAsync) {
3005+
ExpectFailWithError(R"sql(USE plato;
3006+
CREATE TABLE table (
3007+
pk INT32 NOT NULL,
3008+
col String,
3009+
INDEX idx GLOBAL UNIQUE ASYNC ON(col),
3010+
PRIMARY KEY (pk))
3011+
)sql",
3012+
"<main>:5:41: Error: unique: alternative is not implemented yet: \n");
3013+
}
3014+
3015+
Y_UNIT_TEST(AlterTableAddIndexGlobalUnique) {
3016+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
3017+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ON(col))sql");
3018+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
3019+
UNIT_ASSERT(result.Root);
3020+
3021+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
3022+
Y_UNUSED(word);
3023+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
3024+
};
3025+
3026+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
3027+
VerifyProgram(result, elementStat, verifyLine);
3028+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
3029+
}
3030+
3031+
Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueSync) {
3032+
NYql::TAstParseResult result = SqlToYql(R"sql(USE plato;
3033+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE SYNC ON(col))sql");
3034+
UNIT_ASSERT_C(result.IsOk(), result.Issues.ToString());
3035+
UNIT_ASSERT(result.Root);
3036+
3037+
TVerifyLineFunc verifyLine = [](const TString& word, const TString& line) {
3038+
Y_UNUSED(word);
3039+
UNIT_ASSERT_STRING_CONTAINS(line, R"('indexType 'syncGlobalUnique)");
3040+
};
3041+
3042+
TWordCountHive elementStat({TString("\'indexName \'\"idx\"")});
3043+
VerifyProgram(result, elementStat, verifyLine);
3044+
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["\'indexName \'\"idx\""]);
3045+
}
3046+
3047+
Y_UNIT_TEST(AlterTableAddIndexGlobalUniqueAsync) {
3048+
ExpectFailWithError(R"sql(USE plato;
3049+
ALTER TABLE table ADD INDEX idx GLOBAL UNIQUE ASYNC ON(col))sql",
3050+
"<main>:2:59: Error: unique: alternative is not implemented yet: \n");
3051+
}
3052+
29623053
Y_UNIT_TEST(CreateTableAddIndexVector) {
29633054
const auto result = SqlToYql(R"(USE plato;
29643055
CREATE TABLE table (

0 commit comments

Comments
 (0)