Skip to content

Commit 9f3eec9

Browse files
committed
added a few more tests
1 parent d775333 commit 9f3eec9

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ keyword
901901
| NO
902902
| NOT
903903
| NULLS
904+
| NULL_SQL
904905
| NAME
905906
| OFFSET
906907
| ON

jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,4 +1080,33 @@ public void testParamWithCast() throws Exception {
10801080
}
10811081
}
10821082
}
1083+
1084+
@Test(groups = {"integration"})
1085+
public void testSelectWithTableAliasAsKeyword() throws Exception {
1086+
try (Connection conn = getJdbcConnection()) {
1087+
String[] keywords = {
1088+
"ALL", "AND", "ANY", "AS", "ASC", "BY", "CREATE", "DATABASE", "DELETE", "DESC", "DISTINCT", "DROP", "EXISTS", "FROM", "GRANT", "GROUP", "HAVING", "INSERT", "INTO", "LIMIT", "NOT", "NULL", "ON", "ORDER", "REVOKE", "SELECT", "SET", "TABLE", "TO", "UPDATE", "VALUES", "VIEW", "WHILE", "WITH", "WHERE"
1089+
};
1090+
1091+
for (String keyword : keywords) {
1092+
final String table = keyword;
1093+
try (Statement stmt = conn.createStatement()) {
1094+
stmt.execute("DROP TABLE IF EXISTS " + table);
1095+
stmt.execute("CREATE TABLE " + table + " (v1 Int32, v2 String) Engine MergeTree ORDER BY ()");
1096+
stmt.execute("INSERT INTO `" + table + "` VALUES (1000, 'test')");
1097+
}
1098+
1099+
try (PreparedStatement stmt = conn.prepareStatement("SELECT v1, v2 FROM " + table + " AS " + keyword + " WHERE v1 = ? AND v2 = ?")) {
1100+
stmt.setInt(1, 1000);
1101+
stmt.setString(2, "test");
1102+
stmt.execute();
1103+
try (ResultSet rs = stmt.getResultSet()) {
1104+
assertTrue(rs.next());
1105+
Assert.assertEquals(rs.getInt(1), 1000);
1106+
Assert.assertEquals(rs.getString(2), "test");
1107+
}
1108+
}
1109+
}
1110+
}
1111+
}
10831112
}

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.clickhouse.client.api.ClientConfigProperties;
44
import com.clickhouse.client.api.query.GenericRecord;
5+
import com.clickhouse.jdbc.internal.ClickHouseParser;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78
import org.testng.Assert;
@@ -729,4 +730,27 @@ public void testDDLStatements() throws Exception {
729730
}
730731
}
731732
}
733+
734+
@Test(groups = {"integration"})
735+
public void testSelectWithKeywordsAsTableAlias() throws Exception {
736+
String[] keywords = {
737+
"ALL", "AND", "ANY", "AS", "ASC", "BY", "CREATE", "DATABASE", "DELETE", "DESC", "DISTINCT", "DROP", "EXISTS", "FROM", "GRANT", "GROUP", "HAVING", "INSERT", "INTO", "LIMIT", "NOT", "NULL", "ON", "ORDER", "REVOKE", "SELECT", "SET", "TABLE", "TO", "UPDATE", "VALUES", "VIEW", "WHILE", "WITH", "WHERE"
738+
};
739+
740+
try (Connection conn = getJdbcConnection()) {
741+
for (String keyword : keywords) {
742+
String createSql = "CREATE TABLE IF NOT EXISTS " + getDatabase() + "." + keyword + "(id UInt8) ENGINE = MergeTree ORDER BY id";
743+
String insertSql = "INSERT INTO " + getDatabase() + "." + keyword + " VALUES (1)";
744+
String selectSql = "SELECT * FROM " + getDatabase() + "." + keyword + " AS " + keyword;
745+
try (Statement stmt = conn.createStatement()) {
746+
Assert.assertFalse(stmt.execute(createSql));
747+
Assert.assertFalse(stmt.execute(insertSql));
748+
try (ResultSet rs = stmt.executeQuery(selectSql)) {
749+
Assert.assertTrue(rs.next());
750+
Assert.assertEquals(rs.getInt(1), 1);
751+
}
752+
}
753+
}
754+
}
755+
}
732756
}

0 commit comments

Comments
 (0)