Map(K, V) type support issue
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start in client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java at readMap(..), then trace the JDBC ResultSet getObject overloads named in the issue. Reproduce the duplicate-key query and inspect how top-level, nested, and array-contained maps are read. Done means the default behavior remains compatible while the requested type hints preserve duplicate key-value entries in each stated scenario.
Written by the indexing model from the issue text.
Description
Description
In Clickhouse Map(K, V) is not a collection of unique-by-key pairs, see https://clickhouse.com/docs/sql-reference/data-types/map :
i.e. a map can contain two elements with the same key
But there is no way to obtain any representation other than a Map<,> of unique entries.
All the key-value pairs are being delivered by the underlying protocol, but they are effectively merged while reading an instance of a map in the corresponding readMap(..) method.
The issue affects all scenarios of map usage: top-level value, nested map-in-map, map-in-array, etc.
Steps to reproduce
- Execute minimal reproduction program:
public class Program {
public static void main(String[] args) throws SQLException {
String queryText = "select map('key', 'X', 'key', 'Y')";
try (
Connection cnn = DriverManager.getConnection("jdbc:clickhouse://localhost:11049/default", "default", "");
PreparedStatement stmt = cnn.prepareStatement(queryText);
ResultSet rs = stmt.executeQuery()
) {
if (rs.next()) {
System.out.println(rs.getObject(1)); // gives {key=Y}
} else {
throw new IllegalStateException();
}
}
}
}
- Observe only one value per key returned.
- Any attempt to get other value representations than what
getObject()does gives the same or results in an exception being thrown.
Expected Behavior
Supporting existing behavior by default, it is expected to be able to use type hints to affect the actual return value of the getObject(..) method of the java.sql.ResultSet implementation (such overloads as <T> T getObject(int columnIndex, Class<T> type) and Object getObject(int columnIndex, java.util.Map<String,Class<?>> map) specifically, including their counterparts having columnLabel instead of columnIndex):
public class Program {
public static void main(String[] args) throws SQLException {
String queryText = "select map('key', 'X', 'key', 'Y')";
try (
Connection cnn = DriverManager.getConnection("jdbc:clickhouse://localhost:11049/default", "default", "");
PreparedStatement stmt = cnn.prepareStatement(queryText);
ResultSet rs = stmt.executeQuery()
) {
if (rs.next()) {
System.out.println(rs.getObject(1)); // gives {key=Y} by default
System.out.println(rs.getObject(1, List.class)); // to give [key=X, key=Y] only for top level
System.out.println(rs.getObject(1, Map.of("Map", List.class))); // to give [key=X, key=Y] same as above including nested values
} else {
throw new IllegalStateException();
}
}
}
}
Consider changing the default behavior by the time of a certain upcoming major release.
Code Example
select map('key', 'X', 'key', 'Y');
Environment
- Cloud
- Client version: 0.10.0-rc2
- Language version: 21
- OS: Windows 11
ClickHouse Server
- ClickHouse Server version: 24.5.3.5
- Dominant language
- Java
- Stars
- 1.6k
- Forks
- 637
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/clickhouse-java
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ClickHouse/clickhouse-java#3143 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
ClickHouse/clickhouse-java#3111 ·
-
area:data-type bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-java#3098 · 1 comment ·
-
bug client-api-v2 test
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
ClickHouse/clickhouse-java#3076 ·
-
area:sql-parser bug client-v1
Difficulty 1/5 1-3 hours Newbie friendliness 92/100
ClickHouse/clickhouse-java#3066 ·
All issues in ClickHouse/clickhouse-java
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
1.0.0-alpha2 Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#272 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100