ClickHouse / ClickHouse/clickhouse-java

Version client-v2-0.9.4 changes order of query settings as URL params in CH HTTP request

Abierto
#2,732 4 comentarios 0 reacciones 0 asignados Ver en GitHub
area:general client-api-v2
Lenguaje dominante
Java
Estrellas
1.6k
Forks
636
Merge medio
2 d 23 h
PR fusionados (30 d)
29

Descripción

## Once we upgraded from client-v2-0.9.0 to client-v2-0.9.4 we are seeing that in the final HTTP request made to clickhouse the order of the URL params is changing resulting in the change in behavior.

Since clickhouse processes the query settings in the same order, giving preference to the parameter coming later, in our case we are seeing the profile setting parameter going to the end resulting in the change in query result.

Query string in version 0.9.0

`http://localhost:18123?query_id=ddcb9fb8-b875-477f-b221-839b6ae2b375_http-nio-4010-exec-10_143&compress=1&role=event_interactive_reader&profile=event_interactive_reader_profile&prefer_global_in_and_join=0&log_comment=; role_s: [event_interactive_reader]; profile_s: event_interactive_reader_profile`

Query string in version 0.9.4
`http://localhost:18123?query_id=2dd8034a-c44f-4524-a51d-9022cb50b402_http-nio-4010-exec-1_449&compress=1&role=event_interactive_reader&log_comment=; role_s: [event_interactive_reader]; profile_s: event_interactive_reader_profile&prefer_global_in_and_join=1&profile=event_interactive_reader_profile`

If you see the profile parameter is going to the end resulting in the settings from the profile not allowing to override the prefer_global_in_and_join=1 value. Its defaulting to the value in the setting.

In version 0.9.0 the order of adding the setting to QuerySettings through serverSetting method was retained, but its breaking in 0.9.4

### Steps to reproduce
Have a profile settings and some query setting overriding the value in setting. Set the query setting on QuerySettings at the end in version 0.9.0 this is preserved in the final URL, but its not in 0.9.4.

### Error Log or Exception StackTrace

No errors as such, but due to the. different query settings being applied the result from clickhouse would vary. In our case the value of prefer_global_in_and_join was changing resulting in no data being returned.

### Expected Behaviour

### Code Example

```java

QuerySettings querySettings = new QuerySettings();
querySettings.setFormat(clickHouseFormat);
querySettings.setDBRoles(Set.of("event_interactive_reader"));

String readSettingsProfile = "event_interactive_reader_profile";
settings.put("profile", "event_interactive_reader_profile");
settings.put("prefer_global_in_and_join", "1");

querySettings.logComment("; role_s: [event_interactive_reader]; profile_s: event_interactive_reader_profile");
querySettings.setQueryId("2dd8034a-c44f-4524-a51d-9022cb50b402_http-nio-4010-exec-1_449");
QueryResponse queryResponse = client.query("select * from database.events", querySettings).get(getClientSocketTimeout(client), TimeUnit.MILLISECONDS);
```
If on the profile event_interactive_reader_profile if prefer_global_in_and_join is 0 then in client version 0.9.4 it will always be 0 as profile ends up in the end.

### Configuration

#### Client Configuration
```
com.clickhouse.client.api.Client client = new com.clickhouse.client.api.Client.Builder()
.addEndpoint(endpoint)
.setUsername(username)
.setPassword(password)
.setMaxConnections(10)

.setConnectionTTL(getPropertyOrDefault("clickhouse.client.connection.ttlMillis", 0L, Long::valueOf), ChronoUnit.MILLIS)
.setKeepAliveTimeout(getPropertyOrDefault("clickhouse.client.keepAlive.timeoutMillis", -1L, Long::valueOf), ChronoUnit.MILLIS)
.setConnectionReuseStrategy(ConnectionReuseStrategy.valueOf(getPropertyOrDefault("clickhouse.client.connection.reuseStrategy", "LIFO", String::valueOf)))
.setConnectTimeout(getPropertyOrDefault("clickhouse.client.connection.timeoutMillis", 5000L, Long::valueOf), ChronoUnit.MILLIS)
.setSocketTimeout(getPropertyOrDefault("clickhouse.client.default.socketTimeoutMillis", 30000L, Long::valueOf), ChronoUnit.MILLIS)
.build();
```

#### Environment
* [ ] Cloud
* Client version: client-v2-0.9.4
* Language version: Java
* OS: Debian

#### ClickHouse Server
* ClickHouse Server version: 25.3
* ClickHouse Server non-default settings, if any:
* `CREATE TABLE` statements for tables involved:
* Sample data for all these tables, use [clickhouse-obfuscator](https://github.com/ClickHouse/ClickHouse/blob/master/programs/obfuscator/Obfuscator.cpp#L42-L80) if necessary

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con QuerySettings, especialmente con la ruta serverSetting, y sigue cómo se ensamblan las opciones antes de que client.query envíe la solicitud. Reproduce el ejemplo proporcionado de profile y prefer_global_in_and_join con client-v2-0.9.4, comparando el orden de la URL final con 0.9.0. Se considera terminado cuando se conserva el orden de inserción, de modo que las opciones posteriores mantengan la precedencia prevista.

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

Evaluación

Stack tecnológico
java
Área
api, databases
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.