You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
jdbc-v2: the ANTLR4 SQL parser has no heredoc token, so a heredoc body is lexed as ordinary SQL #3031
With the ANTLR4 SQL parser backends (jdbc_sql_parser=ANTLR4 and ANTLR4_PARAMS_PARSER) a heredoc string
($$body$$, $tag$body$tag$) is not lexed as a literal. The ANTLR4 lexer has no $ handling at all, so every $ raises a token-recognition error and is silently dropped, and the heredoc body is then lexed as ordinary
SQL. The statement is therefore parsed as something entirely different from what the user wrote:
SQL
tokens produced today
INSERT INTO t VALUES ($$abc$$, 1)
... VALUES ( abc , 1 ) — body becomes an identifier
INSERT INTO t VALUES ($$a;b$$, 1)
... VALUES ( a ; b , 1 ) — statement is cut in half
INSERT INTO t VALUES ($$$$, 1)
... VALUES ( , 1 ) — empty body disappears
SELECT $$1+1$$
SELECT 1 + 1 — body becomes an expression
For a body that happens to look like a valid SQL fragment the statement still reports hasErrors=false, so the
mis-lex is silent (statement classification, table name and the VALUES-list positions are derived from the wrong
token stream). For a body that does not, the statement is reported as a parse error: $$a;b$$ and the empty
heredoc $$$$ both come back with hasErrors=true, which makes jdbc-v2 classify the INSERT as a
result-set-bearing statement with no values-list positions.
Steps to reproduce
Propertiesp = newProperties();
p.setProperty("jdbc_sql_parser", "ANTLR4");
// via SqlParserFacade / any jdbc-v2 connection using the ANTLR4 backendparser.parsePreparedStatement("INSERT INTO t VALUES ($$a;b$$, 1)").isHasErrors(); // trueparser.parsePreparedStatement("INSERT INTO t VALUES ($$$$, 1)").isHasErrors(); // true
The server accepts all of these:
SELECT $$a;b$$ -> a;b
SELECT $$$$ -> (empty string)
SELECT $$a$b$$ -> a$b (the untagged form ends at the first '$$')
SELECT $foo$bar -> Code 47 UNKNOWN_IDENTIFIER `$foo$bar` (an unterminated tag is an identifier)
Expected behaviour
A heredoc is a single string literal, accepted anywhere a string literal is accepted, and its body is opaque to
the SQL lexer.
Notes
Same defect class as #3029, which covers the JavaCC backend (the default parser). This issue is the ANTLR4
grammar side, which #3029's fix does not touch.
Configuration
Environment: any
ClickHouse server version: any (verified against 26.5)
Activity
Fix jdbc-v2: lex heredoc strings as a single literal in the ANTLR4 gr…