Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions history/latest/3457.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Bug Fixes

- **[jdbc-v2]** With the `ANTLR4` and `ANTLR4_PARAMS_PARSER` SQL parser backends, 64 keywords that the lexer
knows but the grammar did not accept as identifiers (for example `CLIENT`, `SCHEMA`, `MODEL`, `CONDITION`,
`PAGE`, `CONFIG`) can now be used as unquoted column and table names. Before, an `INSERT` with such a column
failed to parse, its `VALUES` list was discarded, and `PreparedStatement#executeBatch()` silently sent one
`INSERT` per row instead of a single multi-row `INSERT`. The default `JAVACC` backend was not affected.
(https://github.com/ClickHouse/clickhouse-java/issues/3457)
Original file line number Diff line number Diff line change
Expand Up @@ -1230,44 +1230,54 @@ keyword
| AFTER
| ALIAS
| ALL
| ALLOW
| ALTER
| AND
| ANTI
| ANY
| ARBITRARY
| ARGUMENTS
| ARRAY
| AS
| ASCENDING
| ASOF
| AST
| ASYNC
| ASYNCHRONOUS
| ATTACH
| AVG
| AZURE
| BACKUP
| BCRYPT_HASH
| BCRYPT_PASSWORD
| BETWEEN
| BLOCKING
| BOTH
| BY
| CACHE
| CACHES
| CANCEL
| CASE
| CAST
| CHANGEABLE_IN_READONLY
| CHANGED
| CHECK
| CLEANUP
| CLEAR
| CLIENT
| CLUSTER
| CLUSTERS
| CN
| CODEC
| COLLATE
| COLLECTION
| COLLECTIONS
| COLUMN
| COLUMNS
| COMMENT
| COMPILED
| CONDITION
| CONFIG
| CONNECTIONS
| CONST
| CONSTRAINT
Expand All @@ -1276,6 +1286,7 @@ keyword
| CUBE
| CURRENT
| CURRENT_USER
| CUSTOM
| DATABASE
| DATABASES
| DATE
Expand All @@ -1294,11 +1305,13 @@ keyword
| DISK
| DISTINCT
| DISTRIBUTED
| DNS
| DOUBLE_SHA1_HASH
| DOUBLE_SHA1_PASSWORD
| DROP
| DRY
| ELSE
| EMBEDDED
| ENABLED
| END
| ENGINE
Expand All @@ -1312,6 +1325,7 @@ keyword
| EXPRESSION
| EXTENDED
| EXTRACT
| FAILPOINT
| FETCH
| FETCHES
| FILE
Expand All @@ -1328,18 +1342,22 @@ keyword
| FULL
| FUNCTION
| FUNCTIONS
| FUZZER
| GLOBAL
| GRANT
| GRANTEES
| GRANTS
| GRANULARITY
| GROUP
| GRPC
| HAVING
| HDFS
| HIERARCHICAL
| HIVE
| HOST
| HOUR
| HTTP
| HTTPS
| ID
| IDENTIFIED
| IF
Expand All @@ -1355,12 +1373,16 @@ keyword
| INSERT
| INTERVAL
| INTO
| INTROSPECTION
| IP
| IS
| IS_OBJECT_ID
| JDBC
| JEMALLOC
| JOIN
| JSON_FALSE
| JSON_TRUE
| KAFKA
| KERBEROS
| KEY
| KEYED
Expand All @@ -1377,29 +1399,41 @@ keyword
| LIKE
| LIMIT
| LIMITS
| LISTEN
| LIVE
| LOAD
| LOADING
| LOCAL
| LOG
| LOGS
| MANAGEMENT
| MARK
| MATERIALIZE
| MATERIALIZED
| MAX
| MERGES
| METRICS
| MIN
| MINUTE
| MMAP
| MODEL
| MODIFY
| MONGO
| MONTH
| MOVE
| MOVES
| MUTATION
| MYSQL
| NAME
| NAMED
| NATS
| NO
| NONE
| NO_PASSWORD
| NOT
| NULL_SQL
| NULLS
| ODBC
| OFFSET
| ON
| ONLY
Expand All @@ -1411,32 +1445,46 @@ keyword
| OUTFILE
| OVER
| OVERRIDE
| PAGE
| PART
| PARTITION
| PARTS
| PERMISSIVE
| PIPELINE
| PLAINTEXT_PASSWORD
| PLAN
| POLICIES
| POLICY
| POPULATE
| POSTGRES
| POSTGRESQL
| PRECEDING
| PREWHERE
| PRIMARY
| PROCESSLIST
| PROFILE
| PROFILES
| PROJECTION
| PROMETHEUS
| PROXY
| PULL
| PULLING
| QUARTER
| QUERIES
| QUERY
| QUEUE
| QUEUES
| QUOTA
| QUOTAS
| RABBITMQ
| RANDOMIZED
| RANGE
| READINESS
| READONLY
| REALM
| RECURSIVE
| REDIS
| REDUCE
| REFRESH
| REGEXP
| RELOAD
Expand All @@ -1445,8 +1493,11 @@ keyword
| RENAME
| REPLACE
| REPLICA
| REPLICAS
| REPLICATED
| REPLICATION
| RESOURCE
| RESTART
| RESTORE
| RESTRICTIVE
| RETURNS
Expand All @@ -1460,9 +1511,12 @@ keyword
| RUN
| S3
| SAMPLE
| SCHEMA
| SCRAM_SHA256_HASH
| SCRAM_SHA256_PASSWORD
| SECOND
| SECRETS
| SECURE
| SECURITY
| SELECT
| SEMI
Expand All @@ -1474,9 +1528,13 @@ keyword
| SHA256_HASH
| SHA256_PASSWORD
| SHARD
| SHARDS
| SHOW
| SHUTDOWN
| SOURCE
| SOURCES
| SQL
| SQLITE
| SSH_KEY
| SSL_CERTIFICATE
| START
Expand All @@ -1491,6 +1549,7 @@ keyword
| TABLE
| TABLES
| TAG
| TCP
| TEMPORARY
| TEST
| THEN
Expand All @@ -1510,9 +1569,11 @@ keyword
| TTL
| TYPE
| UNBOUNDED
| UNCOMPRESSED
| UNDROP
| UNFREEZE
| UNION
| UNLOAD
| UNTIL
| UPDATE
| URL
Expand All @@ -1524,7 +1585,10 @@ keyword
| VALID
| VALUES
| VIEW
| VIEWS
| VIRTUAL
| VOLUME
| WAIT
| WATCH
| WEEK
| WHEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,57 @@ public void testKeywordAliasesAsTableNames() throws Exception {
}
}

@DataProvider
public static Object[][] keywordColumnNamesDP() {
// lexer keywords that were missing from the grammar's `keyword` rule, so they could not be used
// as unquoted identifiers; several are common column names (CLIENT, SCHEMA, MODEL, CONDITION, PAGE)
return Arrays.stream(new String[] {
"ALLOW", "ARBITRARY", "ASYNCHRONOUS", "BLOCKING", "CANCEL", "CLIENT", "COLLECTIONS", "COMPILED",
"CONDITION", "CONFIG", "CUSTOM", "DNS", "EMBEDDED", "FAILPOINT", "FUZZER", "GRPC", "HIVE", "HTTPS",
"INTROSPECTION", "JDBC", "JEMALLOC", "KAFKA", "LISTEN", "LOAD", "LOADING", "MANAGEMENT", "MARK",
"MMAP", "MODEL", "MONGO", "MOVES", "MYSQL", "NATS", "ODBC", "PAGE", "POLICIES", "POSTGRES",
"POSTGRESQL", "PROMETHEUS", "PROXY", "PULLING", "QUEUE", "QUEUES", "QUOTAS", "RABBITMQ",
"READINESS", "REDIS", "REDUCE", "REPLICAS", "REPLICATION", "RESTART", "SCHEMA", "SECRETS",
"SECURE", "SHARDS", "SHUTDOWN", "SOURCES", "SQLITE", "TCP", "UNCOMPRESSED", "UNLOAD", "VIEWS",
"VIRTUAL", "WAIT"
}).map(k -> new Object[] {k}).toArray(Object[][]::new);
}

/**
* A keyword used as an unquoted column name must not break parsing: with errors the VALUES list is
* discarded and PreparedStatement#executeBatch sends one INSERT per row instead of a single INSERT.
*/
@Test(dataProvider = "keywordColumnNamesDP")
public void testKeywordAsColumnName(String keyword) {
String insert = "INSERT INTO t (id, " + keyword + ", v) VALUES (?, ?, now())";
ParsedPreparedStatement parsedInsert = parser.parsePreparedStatement(insert);
assertFalse(parsedInsert.isHasErrors(), insert);
assertTrue(parsedInsert.isInsert(), insert);
assertEquals(parsedInsert.getArgCount(), 2, insert);
assertEquals(parsedInsert.getAssignValuesGroups(), 1, insert);
assertTrue(parsedInsert.getAssignValuesListStartPosition() > -1, insert);
assertTrue(parsedInsert.getAssignValuesListStopPosition() > -1, insert);

String lowerInsert = "insert into t (id, " + keyword.toLowerCase() + ") values (?, ?)";
ParsedPreparedStatement parsedLowerInsert = parser.parsePreparedStatement(lowerInsert);
assertFalse(parsedLowerInsert.isHasErrors(), lowerInsert);
assertEquals(parsedLowerInsert.getAssignValuesGroups(), 1, lowerInsert);

String select = "SELECT id, " + keyword + " FROM t WHERE " + keyword + " = ?";
ParsedPreparedStatement parsedSelect = parser.parsePreparedStatement(select);
assertFalse(parsedSelect.isHasErrors(), select);
assertEquals(parsedSelect.getArgCount(), 1, select);
}

@Test
public void testKeywordColumnNameInBrokenInsert() {
// still an error when the statement itself is malformed: the column list is never closed
String sql = "INSERT INTO t (id, CLIENT VALUES (?, ?)";
ParsedPreparedStatement parsed = parser.parsePreparedStatement(sql);
assertTrue(parsed.isHasErrors(), sql);
assertEquals(parsed.getAssignValuesListStartPosition(), -1, sql);
}

/**
* Test that keywords allowed as table names can be used as table names.
*/
Expand Down