Repository navigation
Closed
Description
- jdbc-v2
- sql-parser
Description
Reporting against 0.8.6.
ParsedPreparedStatement has argCount == 0 and ArrayIndexOutOfBoundsException occurs while trying to assign values of named/positional parameters - even though the SQL query template contains the parameters. The trigger for the issue appears to be using a keyword as a column alias, not prefixed with "AS".
Steps to reproduce
- create table test(val integer, dt date) ENGINE=MergeTree() ORDER BY val;
- select toYear(dt) year from test WHERE val=1; /* works without problems in CLI */
- Try parsing "select toYear(dt) year from test WHERE val=?" - no parameters detected!
- Try parsing "select toYear(dt) AS year from test WHERE val=?" - the parameter is detected correctly.
- Try parsing "select toYear(dt) yearx from test WHERE val=?" - the parameter is also detected correctly.
Error Log or Exception StackTrace
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.clickhouse.jdbc.PreparedStatementImpl.setLong(PreparedStatementImpl.java:173)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:123)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:123)
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:46)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
at org.hibernate.loader.custom.sql.NamedParamBinder.bind(NamedParamBinder.java:34)
at org.hibernate.loader.custom.CustomLoader.bindParameterValues(CustomLoader.java:475)
at org.hibernate.loader.Loader.bindPreparedStatement(Loader.java:2150)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2127)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2059)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2037)
at org.hibernate.loader.Loader.doQuery(Loader.java:956)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:357)
at org.hibernate.loader.Loader.doList(Loader.java:2868)
at org.hibernate.loader.Loader.doList(Loader.java:2850)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
at org.hibernate.loader.Loader.list(Loader.java:2677)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
at org.hibernate.internal.StatelessSessionImpl.listCustomQuery(StatelessSessionImpl.java:680)
at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1204)
at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:177)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
... 21 more
Expected Behaviour
Parsing both versions of the query (with or without AS) should result in one assignable positional parameter.
Code Example
Not included as my test case comes from Hibernate context. But I'm pretty sure Hibernate is not required to reproduce this because I see the named parameter of the query correctly translated to a positional parameter (?) in ConnectionImpl.prepareStatement.
Configuration
Not relevant
Client Configuration
Not relevant
Environment
- Cloud
- Client version: 0.8.6
- Language version: Java
- OS: not relevant
ClickHouse Server
- ClickHouse Server version: not relevant (24.12.1.1614)
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved: see above in steps to reproduce- Sample data for all these tables: not required
Activity
jploski commentedon Jun 30, 2025
Note: this issue did not exist in version 0.2.6 of the JDBC driver, we spotted it as regression while trying to upgrade.
jploski commentedon Jul 19, 2025
Adding patch for PreparedStatementTest.java to demonstrate/reproduce this bug:
test_jdbc_select_as_2478.patch.txt
chernser commentedon Jul 24, 2025
@jploski
Thank you for reporting the problem!
Is it because alias uses interval name
year. We will look into it.