Repository navigation
Labels
bugclientModule: the client (client-v2; with legacy: the v1 client)data-typesArea: type names, value encoding and decoding, row mapping, data formatsjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Milestone
Description
Describe the bug
After updating jdbc driver there is an error while trying to SELECT duplicated data.
Steps to reproduce
- "SELECT 'value1', 'value1'"
- Observe error
Expected behaviour
Correctly return duplicated data
Code example
Statement stmt = conn.createStatement();
stmt.executeQuery("""
SELECT 'value1', 'value1'
""");
ResultSet rs = stmt.getResultSet();Error log
java.sql.SQLException: Multiple entries with same key: 'value1'=1 and 'value1'=0
at com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:71)
at com.clickhouse.jdbc.internal.ExceptionUtils.toSqlState(ExceptionUtils.java:39)
at com.clickhouse.jdbc.StatementImpl.executeQuery(StatementImpl.java:207)
at com.clickhouse.jdbc.StatementImpl.executeQuery(StatementImpl.java:151)
at com.clickhouse.jdbc.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:110)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeQuery$2(kleisliinterpreter.scala:931)
at doobie.free.KleisliInterpreter.$anonfun$primitive$2(kleisliinterpreter.scala:104)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
at uncancelable @ doobie.WeakAsync$$anon$1.uncancelable(WeakAsync.scala:38)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
at suspend @ doobie.WeakAsync$$anon$1.suspend(WeakAsync.scala:36)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
at flatMap @ doobie.WeakAsync$$anon$1.flatMap(WeakAsync.scala:30)
at $anonfun$tailRecM$1 @ doobie.util.transactor$Transactor$$anon$4.$anonfun$apply$4(transactor.scala:169)
Caused by: java.lang.IllegalArgumentException: Multiple entries with same key: 'value1'=1 and 'value1'=0
at com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:382)
at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:376)
at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:246)
at com.google.common.collect.RegularImmutableMap.fromEntryArrayCheckingBucketOverflow(RegularImmutableMap.java:134)
at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:96)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:579)
at com.google.common.collect.ImmutableMap$Builder.buildOrThrow(ImmutableMap.java:607)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:594)
at com.clickhouse.client.api.metadata.TableSchema.<init>(TableSchema.java:41)
at com.clickhouse.client.api.metadata.TableSchema.<init>(TableSchema.java:26)
at com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader.readSchema(RowBinaryWithNamesAndTypesFormatReader.java:45)
at com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader.<init>(RowBinaryWithNamesAndTypesFormatReader.java:23)
at com.clickhouse.client.api.Client.newBinaryFormatReader(Client.java:2086)
at com.clickhouse.client.api.Client.newBinaryFormatReader(Client.java:2104)
at com.clickhouse.jdbc.StatementImpl.executeQuery(StatementImpl.java:202)
at com.clickhouse.jdbc.StatementImpl.executeQuery(StatementImpl.java:151)
at com.clickhouse.jdbc.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:110)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at doobie.free.KleisliInterpreter$PreparedStatementInterpreter.$anonfun$executeQuery$2(kleisliinterpreter.scala:931)
at doobie.free.KleisliInterpreter.$anonfun$primitive$2(kleisliinterpreter.scala:104)
at cats.effect.IOFiber.runLoop(IOFiber.scala:1004)
at cats.effect.IOFiber.execR(IOFiber.scala:1362)
at cats.effect.IOFiber.run(IOFiber.scala:112)
at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:702)Configuration
"com.clickhouse" % "clickhouse-jdbc" % "0.8.4"
ClickHouse server
ClickHouse version I use is: ver. 24.3.12.76
Reacted by Benas Jacikas, lraudonius-atlantis, Vakaris Baškirov, Sergey Vershinin, elbaz michael and Lukas Eder
Metadata
Metadata
Assignees
Labels
bugclientModule: the client (client-v2; with legacy: the v1 client)data-typesArea: type names, value encoding and decoding, row mapping, data formatsjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)
Activity
slvrtrn commentedon Apr 30, 2025
What is the expected behavior for the driver when calling
ResultSet.getObject("value1")in this case?We have several options, as it seems:
["value1", "value1"]Onajk commentedon Apr 30, 2025
I'm not sure what is the best way to handle that but I have a case in code when for simplicity I'm reading the same table column twice and it triggers this error.
It would be nice if you could make it possible in newest driver as it was in older one.
If not then let me know because obviously I can handle that manually on application side.
slvrtrn commentedon Apr 30, 2025
@chernser @Paultagoras @mzitnik WDYT?
Onajk commentedon May 12, 2025
Hi, could someone please comment on that?
chernser commentedon May 12, 2025
@Onajk thank you for reporting it!
Would it be a workaround for you to assign an alias to duplicate columns?
This should be easy to fix because we use this map to find column by name and can remember only first occurrence of it.
This should be a behavior for the example:
Would it work for you, @Onajk?
Thanks!
Onajk commentedon May 13, 2025
I'm not sure how that will behave in Doobie that I use in Scala code but let's try
Onajk commentedon May 19, 2025
Using alias fixes the problem and I guess we can live with it
chernser commentedon May 19, 2025
@Onajk thank you for updating!
I will keep the issue open so we fix it anyway.
Gerrit-K commentedon Jun 4, 2025
While the example above is a good MRE, let me add a more realistic use-case (using the JDBC driver in Metabase) where this regression has actually impeded our work:
In order to do quick exploration of data and iteratively build queries, our users sometimes run queries like:
select col1, * from table. Then they check the remaining columns and add another one they're interested in, e.g.select col1, col2, * from table. When they found all the columns they're interested in, they eventually remove the*to remove the unnecessary toil. While these queries work perfectly fine in plain SQL, the columns duplicated by the*trigger the above error in the JDBC driver.lukaseder commentedon Sep 9, 2025
This change introduced a regression in jOOQ's code generator after upgrading:
While it is easy to avoid the issue by aliasing individual columns, it's still important to note:
___col1,___col2, you get the idea. There are other ways of name mangling, but it should always be possible.lukaseder commentedon Sep 9, 2025
For the record, the server accepts:
But rejects:
With:
I think this is another, related problem. I don't see why this is forbidden.
chernser commentedon Sep 9, 2025
@lukaseder
we are working to solve the issue.