Skip to content

Commit bd51734

Browse files
authored
Fix backtick matching for antlr4 (#8941)
1 parent 24b4631 commit bd51734

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

ydb/library/yql/sql/v1/SQLv1Antlr4.g.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ STRING_VALUE: ((STRING_SINGLE | STRING_DOUBLE | STRING_MULTILINE) (S | U | Y | J
20492049

20502050
ID_PLAIN: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | DIGIT)*;
20512051

2052-
fragment ID_QUOTED_CORE: '``' | '\\`' | ~'`';
2052+
fragment ID_QUOTED_CORE: '\\'. | '``' | ~('`' | '\\');
20532053
ID_QUOTED: BACKTICK ID_QUOTED_CORE* BACKTICK;
20542054

20552055
fragment DIGIT: '0'..'9';

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7203,6 +7203,30 @@ Y_UNIT_TEST_SUITE(ResourcePoolClassifier) {
72037203

72047204
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
72057205
}
7206+
7207+
Y_UNIT_TEST(BacktickMatching) {
7208+
auto req = "select\n"
7209+
" 1 as `Schema has \\`RealCost\\``\n"
7210+
" -- foo`bar";
7211+
auto res = SqlToYql(req);
7212+
UNIT_ASSERT(res.Root);
7213+
UNIT_ASSERT(res.IsOk());
7214+
UNIT_ASSERT(res.Issues.Size() == 0);
7215+
res = SqlToYqlWithAnsiLexer(req);
7216+
UNIT_ASSERT(res.Root);
7217+
UNIT_ASSERT(res.IsOk());
7218+
UNIT_ASSERT(res.Issues.Size() == 0);
7219+
7220+
req = "select 1 as `a``b`, 2 as ````, 3 as `\\x60a\\x60`, 4 as ```b```, 5 as `\\`c\\``";
7221+
res = SqlToYql(req);
7222+
UNIT_ASSERT(res.Root);
7223+
UNIT_ASSERT(res.IsOk());
7224+
UNIT_ASSERT(res.Issues.Size() == 0);
7225+
res = SqlToYqlWithAnsiLexer(req);
7226+
UNIT_ASSERT(res.Root);
7227+
UNIT_ASSERT(res.IsOk());
7228+
UNIT_ASSERT(res.Issues.Size() == 0);
7229+
}
72067230
}
72077231

72087232
Y_UNIT_TEST_SUITE(OlapPartitionCount) {

ydb/library/yql/sql/v1/sql_ut_antlr4.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7200,4 +7200,28 @@ Y_UNIT_TEST_SUITE(ResourcePoolClassifier) {
72007200

72017201
UNIT_ASSERT_VALUES_EQUAL(1, elementStat["Write"]);
72027202
}
7203+
7204+
Y_UNIT_TEST(BacktickMatching) {
7205+
auto req = "select\n"
7206+
" 1 as `Schema has \\`RealCost\\``\n"
7207+
" -- foo`bar";
7208+
auto res = SqlToYql(req);
7209+
UNIT_ASSERT(res.Root);
7210+
UNIT_ASSERT(res.IsOk());
7211+
UNIT_ASSERT(res.Issues.Size() == 0);
7212+
res = SqlToYqlWithAnsiLexer(req);
7213+
UNIT_ASSERT(res.Root);
7214+
UNIT_ASSERT(res.IsOk());
7215+
UNIT_ASSERT(res.Issues.Size() == 0);
7216+
7217+
req = "select 1 as `a``b`, 2 as ````, 3 as `\\x60a\\x60`, 4 as ```b```, 5 as `\\`c\\``";
7218+
res = SqlToYql(req);
7219+
UNIT_ASSERT(res.Root);
7220+
UNIT_ASSERT(res.IsOk());
7221+
UNIT_ASSERT(res.Issues.Size() == 0);
7222+
res = SqlToYqlWithAnsiLexer(req);
7223+
UNIT_ASSERT(res.Root);
7224+
UNIT_ASSERT(res.IsOk());
7225+
UNIT_ASSERT(res.Issues.Size() == 0);
7226+
}
72037227
}

0 commit comments

Comments
 (0)