Skip to content

Commit 7b3b183

Browse files
ruanwenjunruanwenjun
authored andcommitted
[KYUUBI #7109] Ignore the ? in backticks
1 parent 31bbb53 commit 7b3b183

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static List<String> splitSqlStatement(String sql) {
124124
boolean inSingleQuote = false;
125125
boolean inDoubleQuote = false;
126126
boolean inComment = false;
127+
boolean inBackticks = false;
127128
int off = 0;
128129
boolean skip = false;
129130

@@ -148,8 +149,13 @@ static List<String> splitSqlStatement(String sql) {
148149
inDoubleQuote = !inDoubleQuote;
149150
}
150151
break;
151-
case '-':
152+
case '`':
152153
if (!inSingleQuote && !inDoubleQuote) {
154+
inBackticks = !inBackticks;
155+
}
156+
break;
157+
case '-':
158+
if (!inSingleQuote && !inDoubleQuote && !inBackticks) {
153159
if (i < sql.length() - 1 && sql.charAt(i + 1) == '-') {
154160
inComment = true;
155161
}
@@ -161,7 +167,7 @@ static List<String> splitSqlStatement(String sql) {
161167
}
162168
break;
163169
case '?':
164-
if (!inSingleQuote && !inDoubleQuote) {
170+
if (!inSingleQuote && !inDoubleQuote && !inIdentifierQuoted) {
165171
parts.add(sql.substring(off, i));
166172
off = i + 1;
167173
}

kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/UtilsTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,17 @@ public void testSplitSqlStatement() {
197197
assertEquals("--comments\n" + "select --? \n", splitSql.get(0));
198198
assertEquals(" from ", splitSql.get(1));
199199
assertEquals("", splitSql.get(2));
200+
201+
String inIdentifierQuoted =
202+
"SELECT "
203+
+ "regexp_replace(col2, '\\n|\\r|\\t', '') as col2, "
204+
+ "`(col2|col2)?+.+` "
205+
+ "FROM ?";
206+
splitSql = Utils.splitSqlStatement(inIdentifierQuoted);
207+
assertEquals(2, splitSql.size());
208+
assertEquals(
209+
"SELECT regexp_replace(col2, '\\n|\\r|\\t', '') as col2, `(col2|col2)?+.+` FROM ",
210+
splitSql.get(0));
211+
assertEquals("", splitSql.get(1));
200212
}
201213
}

0 commit comments

Comments
 (0)