Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 6a65322

Browse files
authored
Merge pull request #106 from zhicwu/fix-parsing-issues
Fix parsing issues
2 parents 8aaa52a + 925fd44 commit 6a65322

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# KIND, either express or implied. See the License for the
1818
# specific language governing permissions and limitations
1919
# under the License.
20-
FROM adoptopenjdk/openjdk8-openj9:jre8u282-b08_openj9-0.24.0-ubuntu
20+
FROM adoptopenjdk/openjdk8-openj9:jre8u292-b10_openj9-0.26.0-ubuntu
2121

2222
ARG revision=latest
2323
ARG repository=ClickHouse/clickhouse-jdbc-bridge
@@ -38,6 +38,11 @@ RUN apt-get update \
3838
apt-transport-https curl htop iftop iptraf iputils-ping jq lsof net-tools tzdata wget \
3939
&& apt-get clean \
4040
&& if [ "$revision" = "latest" ] ; then export JDBC_BRIDGE_VERSION=$(curl -s https://repo1.maven.org/maven2/ru/yandex/clickhouse/clickhouse-jdbc-bridge/maven-metadata.xml | grep '<latest>' | sed -e 's|^.*>\(.*\)<.*$|\1|'); else export JDBC_BRIDGE_VERSION=${revision}; fi \
41+
&& export DOWNLOAD_URL=https://github.com/ClickHouse/clickhouse-jdbc/releases/download \
42+
DRIVER_VER=$(curl -sL https://repo1.maven.org/maven2/ru/yandex/clickhouse/clickhouse-jdbc/maven-metadata.xml \
43+
| grep '<release>' | sed -e 's|.*>\(.*\)<.*|\1|') \
44+
&& wget -P $JDBC_BRIDGE_HOME/drivers \
45+
$DOWNLOAD_URL/v$DRIVER_VER/clickhouse-jdbc-$DRIVER_VER-shaded.jar \
4146
&& export JDBC_BRIDGE_REL_URL=$JDBC_BRIDGE_REL_URL/v$JDBC_BRIDGE_VERSION \
4247
&& wget -q -P $JDBC_BRIDGE_HOME $JDBC_BRIDGE_REL_URL/LICENSE $JDBC_BRIDGE_REL_URL/NOTICE \
4348
$JDBC_BRIDGE_REL_URL/clickhouse-jdbc-bridge-${JDBC_BRIDGE_VERSION}-shaded.jar \

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>ru.yandex.clickhouse</groupId>
66
<artifactId>clickhouse-jdbc-bridge</artifactId>
77
<packaging>jar</packaging>
8-
<version>2.0.2-SNAPSHOT</version>
8+
<version>2.0.3-SNAPSHOT</version>
99
<name>ClickHouse JDBC Bridge</name>
1010
<url>https://github.com/ClickHouse/clickhouse-jdbc-bridge</url>
1111
<description>JDBC bridge for ClickHouse.</description>

src/main/java/ru/yandex/clickhouse/jdbcbridge/core/QueryParser.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class QueryParser {
5757
private static final String MULTILINE_COMMENT_END = "*/";
5858
private static final String DOUBLE_QUOTES_STRING = "''";
5959
private static final String ESCAPED_QUOTE_STRING = "\\'";
60+
private static final String ESCAPED_BACKTICK_STRING = "\\`";
6061

6162
private final String uri;
6263
private final String schema;
@@ -193,7 +194,8 @@ static String extractTableName(String query) {
193194
} else if (MULTILINE_COMMENT_BEGIN.equals(nextTwo)) {
194195
int newIdx = query.indexOf(MULTILINE_COMMENT_END, i);
195196
i = newIdx != -1 ? newIdx + 1 : len;
196-
} else if (DOUBLE_QUOTES_STRING.equals(nextTwo) || ESCAPED_QUOTE_STRING.equals(nextTwo)) {
197+
} else if (DOUBLE_QUOTES_STRING.equals(nextTwo) || ESCAPED_QUOTE_STRING.equals(nextTwo)
198+
|| ESCAPED_BACKTICK_STRING.equals(nextTwo)) {
197199
// ignore escaped single quote
198200
i += nextTwo.length() - 1;
199201
} else if (nextTwo.charAt(0) == '\'') {
@@ -331,23 +333,15 @@ static String normalizeQuery(String query) {
331333
if (index > 0 && len > (index = index + EXPR_FROM.length())) {
332334
// assume quote is just one character and it always exists
333335
char quote = query.charAt(index++);
336+
boolean isQuote = quote == '"' || quote == '`';
334337

335-
int dotIndex = query.indexOf('.', index);
338+
int dotIndex = isQuote ? query.indexOf('.', index) : -1;
336339

337-
if (dotIndex > index && len > dotIndex && query.charAt(dotIndex - 1) == quote
338-
&& query.charAt(dotIndex + 1) == quote) { // has schema
340+
if (dotIndex > index && query.charAt(dotIndex - 1) == quote && query.charAt(dotIndex + 1) == quote) { // has
341+
// schema
339342
dotIndex += 2;
340-
/*
341-
* int endIndex = query.indexOf(quote, dotIndex); // .lastIndexOf(quote); if
342-
* (endIndex > dotIndex) { extractedQuery = query.substring(dotIndex, endIndex);
343-
* }
344-
*/
345-
} else if (quote == '"' || quote == '`') {
343+
} else if (isQuote) {
346344
dotIndex = index;
347-
/*
348-
* int endIndex = query.indexOf(quote, index); // query.lastIndexOf(quote); if
349-
* (endIndex > index) { extractedQuery = query.substring(index, endIndex); }
350-
*/
351345
} else {
352346
dotIndex = len;
353347
}
@@ -362,7 +356,8 @@ static String normalizeQuery(String query) {
362356
} else if (MULTILINE_COMMENT_BEGIN.equals(nextTwo)) {
363357
int newIdx = query.indexOf(MULTILINE_COMMENT_END, i);
364358
i = newIdx != -1 ? newIdx + 1 : len;
365-
} else if (DOUBLE_QUOTES_STRING.equals(nextTwo) || ESCAPED_QUOTE_STRING.equals(nextTwo)) {
359+
} else if (DOUBLE_QUOTES_STRING.equals(nextTwo) || ESCAPED_QUOTE_STRING.equals(nextTwo)
360+
|| ESCAPED_BACKTICK_STRING.equals(nextTwo)) {
366361
// ignore escaped single quote
367362
i += nextTwo.length() - 1;
368363
} else if (nextTwo.charAt(0) == '\'') {
@@ -387,6 +382,7 @@ static String normalizeQuery(String query) {
387382
// \f Insert a formfeed in the text at this point.
388383
// \' Insert a single quote character in the text at this point.
389384
// \" Insert a double quote character in the text at this point.
385+
// \` Insert a backtick character in the text at this point.
390386
// \\ Insert a backslash character in the text at this point.
391387
StringBuilder builder = new StringBuilder();
392388
for (int i = 0; i < len; i++) {
@@ -422,6 +418,10 @@ static String normalizeQuery(String query) {
422418
builder.append('"');
423419
i++;
424420
break;
421+
case '`':
422+
builder.append('`');
423+
i++;
424+
break;
425425
case '\\':
426426
builder.append('\\');
427427
i++;

src/main/java/ru/yandex/clickhouse/jdbcbridge/impl/JdbcDataSource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class JdbcDataSource extends NamedDataSource {
7070
private static final Properties DEFAULT_DATASOURCE_PROPERTIES = new Properties();
7171

7272
private static final String PROP_DRIVER_CLASS = "driverClassName";
73+
private static final String PROP_INITIALIZATION_FAIL_TIMEOUT = "initializationFailTimeout";
7374
private static final String PROP_POOL_NAME = "poolName";
7475
private static final String PROP_PASSWORD = "password";
7576

@@ -405,6 +406,9 @@ protected JdbcDataSource(String id, Repository<NamedDataSource> resolver, JsonOb
405406
}
406407
}
407408

409+
if (!props.containsKey(PROP_INITIALIZATION_FAIL_TIMEOUT)) {
410+
props.setProperty(PROP_INITIALIZATION_FAIL_TIMEOUT, "0");
411+
}
408412
props.setProperty(PROP_POOL_NAME, id);
409413

410414
this.jdbcUrl = null;

src/test/java/ru/yandex/clickhouse/jdbcbridge/core/QueryParserTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public void testNormalizeQuery() {
7979

8080
query = "SELECT \"col1\", \"col2\" FROM \"some_schema\".\"" + embeddedQuery + "\"";
8181
assertEquals(QueryParser.normalizeQuery(query), embeddedQuery);
82+
83+
query = "SELECT * FROM test.test_table";
84+
assertEquals(QueryParser.normalizeQuery(query), query);
85+
86+
embeddedQuery = "SELECT 1 as \\`a\\`, ''\\`2'' as \\`b\\`";
87+
query = "SELECT `col1`, `col2` FROM `" + embeddedQuery + "`";
88+
assertEquals(QueryParser.normalizeQuery(query), embeddedQuery.replace("\\", ""));
8289
}
8390

8491
@Test(groups = { "unit" })

0 commit comments

Comments
 (0)