Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[client-v2] Writer API with custom insert statement. #2071

Open
chernser opened this issue Jan 7, 2025 · 1 comment
Open

[client-v2] Writer API with custom insert statement. #2071

chernser opened this issue Jan 7, 2025 · 1 comment

Comments

@chernser
Copy link
Contributor

chernser commented Jan 7, 2025

Use case

Current Writer API implementation allows to write custom data stream. There is a case of writing DTO with less set of fields into a table. However there is no way to specify INSERT statement to do so. Currently, INSERT statement is sent via query.

Describe the solution you'd like

There should be options:

  • set custom insert query
  • let application decide where query should go - in the payload or HTTP query parameters

Describe the alternatives you've considered

Additional context

Relates: #2010

@den-crane
Copy link
Collaborator

den-crane commented Jan 7, 2025

Kinda obvious solution is to add one more method (though several overloaded) - "insertQuery"

insertQuery(String query, DataStreamWriter writer, ClickHouseFormat format, InsertSettings settings)

insertQuery(String query, DataStreamWriter writer, InsertSettings settings)
sqlStmt = query;

If format <> null then 
  String sqlStmt += " FORMAT " + format.name();

And use it like

response = client.insertQuery("insert into table(a,c,d)", out -> { }, ClickHouseFormat.JSONEachRow, insertSettings).get()

or

response = client.insertQuery("insert into table(a,c,d) format Parquet", out -> { }, insertSettings).get()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants