ClickHouse / ClickHouse/clickhouse-java

Enhance insert() API to support SELECT with input() for computed columns v2

Ouverte
#2,726 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Java
Étoiles
1.6k
Forks
636
Merge moyen
2 j 23 h
PR mergées (30 j)
29

Description

### Current Limitation
The `insert()` method only supports direct table insertion, not SELECT statements
with transformations.

### Desired Enhancement
Allow `insert()` to accept SELECT statements with input() function:
```java
client.insert()
.table("target_table")
.query("SELECT col1, col2, col1 + col2 as computed FROM input('col1 Int32, col2 Int32')")
.data(inputStream)
.format(ClickHouseFormat.CSV)
.send();
```

Or alternative syntax:
```java
client.insert("INSERT INTO target_table SELECT col1, col2, col1 + col2 as computed FROM input('col1 Int32, col2 Int32')")
.data(inputStream)
.format(ClickHouseFormat.CSV)
.send();
```

### Use Case
We need to stream data with computed columns during insertion:
- Stream large datasets efficiently
- Apply transformations/computed columns on the fly
- Leverage ClickHouse's input() function capabilities
- Maintain the performance benefits of the streaming insert() API

### Business Value
This is a common pattern in ClickHouse for ETL workloads where data needs
transformation during insertion without materializing intermediate results.

### Current Workaround (Working but Undocumented)

We're successfully using this pattern in production:
```java
String loadQuery = tableName + "(" + headers + ")" +
" select " + parametersQuery + "* from input('" + csvHeadersStructure + "')";

try (InputStream inputStream = Files.newInputStream(Paths.get(filepath))) {
InsertResponse response = client.insert(loadQuery, inputStream, ClickHouseFormat.CSVWithNames)
.get(1200, TimeUnit.SECONDS);
}
```

**This works but:**
- Not documented in official API docs
- Unclear if this is intended behavior or might break in future versions
- No IDE autocomplete/type safety for this pattern

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par les points d’entrée de l’API insert() du client Java et la gestion existante des chaînes de requête, puis comparez les formes builder et overload avec le workaround input() fonctionnel décrit ici. Définissez et testez la syntaxe SELECT/input() prise en charge avec des données en streaming et des colonnes calculées, et documentez si le modèle existant est intentionnel.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
api, backend-api-design
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.