What would you like to happen?
Description
The current ClickHouseIO implementation manually fetches table schemas by executing DESCRIBE TABLE queries and parsing the results. However, the ClickHouse Java Client v2 already provides this functionality through Client.getTableSchema(String table, String database).
Current Implementation
public static TableSchema getTableSchema(
String clickHouseUrl, String database, String table, Properties properties) {
// ... setup client
String query = "DESCRIBE TABLE " + quoteIdentifier(table);
try (Records records = client.queryRecords(query).get()) {
for (GenericRecord record : records) {
// Manually parse name, type, default_type, default_expression
// Build TableSchema.Column objects
}
}
// Return TableSchema
}
Java Client v2 Provides This
The Java Client v2 already has:
Client client = new Client.Builder()
.addEndpoint(clickHouseUrl)
.setUsername(user)
.setPassword(password)
.setDefaultDatabase(database)
.build();
// Built-in method returns com.clickhouse.client.api.metadata.TableSchema
TableSchema schema = client.getTableSchema(table, database);
Proposed Solution
Leverage the client's built-in getTableSchema() method and convert the result to Beam's org.apache.beam.sdk.io.clickhouse.TableSchema:
public static TableSchema getTableSchema(
String clickHouseUrl, String database, String table, Properties properties) {
try (Client client = createClient(clickHouseUrl, database, properties)) {
com.clickhouse.client.api.metadata.TableSchema chSchema = client.getTableSchema(table, database);
return convertToBeamTableSchema(chSchema);
}
}
Benefits
- Less code: Remove manual DESCRIBE query execution and parsing logic
- Better compatibility: Client handles version-specific differences (e.g., ClickHouse 25.x backticks in tuple types)
- Reduced maintenance: Schema parsing logic maintained by ClickHouse team
- Consistency: Use the same schema representation as other Java Client v2 operations
Considerations
- Need to map between
com.clickhouse.client.api.metadata.TableSchema and Beam's org.apache.beam.sdk.io.clickhouse.TableSchema
- The tuple preprocessing logic may no longer be needed if the client handles it
Issue Priority
Priority: 3 (nice-to-have improvement)
Issue Components
What would you like to happen?
Description
The current ClickHouseIO implementation manually fetches table schemas by executing
DESCRIBE TABLEqueries and parsing the results. However, the ClickHouse Java Client v2 already provides this functionality throughClient.getTableSchema(String table, String database).Current Implementation
Java Client v2 Provides This
The Java Client v2 already has:
Proposed Solution
Leverage the client's built-in
getTableSchema()method and convert the result to Beam'sorg.apache.beam.sdk.io.clickhouse.TableSchema:Benefits
Considerations
com.clickhouse.client.api.metadata.TableSchemaand Beam'sorg.apache.beam.sdk.io.clickhouse.TableSchemaIssue Priority
Priority: 3 (nice-to-have improvement)
Issue Components