ClickHouse / ClickHouse/clickhouse-java

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

Aperta
#2,732 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:general client-api-v2
Lingua principale
Java
Stelle
1.6k
Fork
636
Merge medio
2g 23h
PR unite (30g)
29

Descrizione

## 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da QuerySettings, in particolare dal percorso serverSetting, e traccia il modo in cui le impostazioni vengono assemblate prima che client.query invii la richiesta. Riproduci l’esempio fornito con profile e prefer_global_in_and_join usando client-v2-0.9.4, confrontando l’ordine dell’URL finale con 0.9.0. Il lavoro è completo quando viene preservato l’ordine di inserimento, così che le impostazioni successive mantengano la precedenza prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.