Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Map(K, V) type support issue

Abierto
#3,047 1 comentario 2 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java
Área
api, database

Línea de trabajo

Empieza en client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java, en readMap(..), y luego sigue las sobrecargas de JDBC ResultSet getObject mencionadas en el issue. Reproduce la consulta con claves duplicadas e inspecciona cómo se leen los mapas de nivel superior, los mapas anidados y los mapas contenidos en arrays. Se considera terminado cuando el comportamiento predeterminado sigue siendo compatible, mientras que las sugerencias de tipo solicitadas conservan las entradas duplicadas de clave-valor en cada escenario indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

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
  1. 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();
			}
		}
	}
}
  1. Observe only one value per key returned.
  2. 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
Lenguaje dominante
Java
Estrellas
1.6k
Forks
639
Merge medio
2 d 46 min
PR fusionados (30 d)
46

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ClickHouse/clickhouse-java

Todos los issues de ClickHouse/clickhouse-java

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.