client-v1 (clickhouse-data): "Duplicate key" IllegalStateException on result sets with duplicate column names (0.9.8)
まだ誰も着手していません。
評価
調査の方向性
スタックトレースで報告されているコンストラクターの位置にある ClickHouseDataProcessor$DefaultSerDe から開始し、提供された重複カラムのクエリを使って RowBinaryWithNamesAndTypes で再現します。カラム名からインデックスへのマップが重複した名前をどのように処理するかを確認し、位置ベースの読み取りが正常に完了することを検証します。重複した出力名によってレスポンスの構築や位置ベースのアクセスが妨げられなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
The v1 client (clickhouse-client / clickhouse-http-client 0.9.8) throws java.lang.IllegalStateException: Duplicate key ... when a query returns a result set with duplicate column names (which is valid SQL).
com.clickhouse.data.ClickHouseDataProcessor$DefaultSerDe builds a column-name → index map with Collectors.toMap (no merge function) at construction time, so any repeated column name fails immediately — before the caller can read anything, even when reading purely by position.
This reproduces with RowBinaryWithNamesAndTypes (the format that carries column names). A trivial SELECT key1, key1 FROM (SELECT 1 AS key1) is enough. Real-world trigger: a reporting tool that lets a user select the same projection twice (e.g. two Date columns), producing SQL like SELECT toDate(...) AS Date, toDate(...) AS Date, ....
This looks related to #2336 (reported on 0.8.4, marked fixed in 0.9.3 via #2618), but that fix was in the JDBC TableSchema (Guava ImmutableMap, "Multiple entries with same key"). The failure here is a different code path — ClickHouseDataProcessor using the JDK Collectors.toMap ("attempted merging values") — and still fails in 0.9.8.
Steps to reproduce
- Use
com.clickhouse:clickhouse-http-client:0.9.8(v1 client). - Execute a query whose result has two columns with the same name, e.g.
SELECT key1, key1 FROM (SELECT 1 AS key1), with formatRowBinaryWithNamesAndTypes. executeAndWait()/ iteratingresponse.records()throws.
Error Log or Exception StackTrace
java.lang.IllegalStateException: Duplicate key key1 (attempted merging values 0 and 1)
at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135)
at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$0(Collectors.java:182)
at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.base/java.util.stream.IntPipeline$1$1.accept(IntPipeline.java:180)
at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:727)
at com.clickhouse.data.ClickHouseDataProcessor$DefaultSerDe.<init>(ClickHouseDataProcessor.java:72)
at com.clickhouse.client.http.ApacheHttpConnectionImpl ...
at com.clickhouse.client.ClickHouseClient.executeAndWait(ClickHouseClient.java:894)
Expected Behaviour
Duplicate column names are valid in ClickHouse/SQL, so building the response must not throw. Reading values by position should always work; name-based lookup of a duplicated name can reasonably return the first match (or be documented). Suggestion: build the name→index map with a merge function (keep the first index) instead of the throwing Collectors.toMap.
Code Example
import com.clickhouse.client.*;
import com.clickhouse.data.ClickHouseFormat;
import com.clickhouse.data.ClickHouseRecord;
public class DuplicateColumnRepro {
public static void main(String[] args) throws Exception {
ClickHouseNode server = ClickHouseNode.builder()
.host("localhost")
.port(ClickHouseProtocol.HTTP, 8123)
.build();
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol());
ClickHouseResponse response = client.read(server)
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
.query("SELECT key1, key1 FROM (SELECT 1 AS key1)") // duplicate output column name
.executeAndWait()) {
for (ClickHouseRecord r : response.records()) {
System.out.println(r.getValue(0).asString() + ", " + r.getValue(1).asString());
}
}
// throws: java.lang.IllegalStateException: Duplicate key key1 (attempted merging values 0 and 1)
}
}
v2 — works (returns 1, 1):
Configuration
Client Configuration
client.read(server)
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
// Reproduces with the default provider; also confirmed with both
// HttpConnectionProvider.APACHE_HTTP_CLIENT and HttpConnectionProvider.HTTP_URL_CONNECTION.
Environment
- Cloud
- Client version: 0.9.8 (
clickhouse-http-client/clickhouse-client/clickhouse-data) - Language version: Java 24.0.2 (also reproduces on Java 17)
- OS: macOS (Darwin arm64); also Linux
ClickHouse Server
- ClickHouse Server version: 26.3.10.60
- ClickHouse Server non-default settings, if any: none relevant
CREATE TABLEstatements for tables involved: none needed —SELECT key1, key1 FROM (SELECT 1 AS key1)reproduces it without any table- Sample data for all these tables: n/a
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 637
- 平均マージ
- 2日 12時間
- マージ済み PR(30日)
- 28
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-java のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ClickHouse/clickhouse-java#3143 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
ClickHouse/clickhouse-java#3111 ·
-
area:data-type bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-java#3098 · コメント 1 件 ·
-
bug client-api-v2 test
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
ClickHouse/clickhouse-java#3076 ·
-
area:sql-parser bug client-v1
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
ClickHouse/clickhouse-java#3066 ·
ClickHouse/clickhouse-java の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
1.0.0-alpha2 Type/Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
wso2/dpdp-accelerator#272 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
infinispan/infinispan#18150 ·
-
area/frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100