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

Passing settings when executing CSV bulk load #1258

Closed
obeah opened this issue Feb 28, 2023 · 2 comments
Closed

Passing settings when executing CSV bulk load #1258

obeah opened this issue Feb 28, 2023 · 2 comments

Comments

@obeah
Copy link

obeah commented Feb 28, 2023

Hi,

after upgrading to 0.4.1 as per instructions in another issue (#1001) I try the following code to bulk load csv:

st.unwrap(ClickHouseRequest.class)
	.write()
	.data(ClickHouseFile.of(new File(csvPath)))
	.table("table1")
	.format(ClickHouseFormat.CSVWithNames)
	.executeAndWait();

and it works
But I also need to pass some setting. After I add thew following to the chain:

.settings(ImmutableMap.of(
	"format_csv_delimiter", csvSeparator.toString(),
	"date_time_input_format", "best_effort"
	))

I get an exception:
Caused by: com.clickhouse.client.ClickHouseException: Expect one SQL statement to execute but we got 3, server ClickHouseNode

Before upgrading I used .option("date_time_input_format", "best_effort")

What would be the correct way of passing settings in this version?

@zhicwu
Copy link
Contributor

zhicwu commented Feb 28, 2023

Hi @obeah, thanks for the report. I think it's same as #1246. Since options/custom settings did not work, perhaps you can try to use custom query? For example:

.write()
	.data(ClickHouseFile.of(new File(csvPath)))
	.query("insert into table1 settings a=1,b=2 format CSV")
	.format(ClickHouseFormat.CSVWithNames)
	.executeAndWait();

@obeah
Copy link
Author

obeah commented Feb 28, 2023

Hi @zhicwu ,

thank you. Yes, it seems like duplicate. Will close it.
And you suggestion solves it for me. Final version

write()
.data(ClickHouseFile.of(new File(csvPath)))
.query(String.format("insert into %s settings %s='%s', %s='%s' format CSVWithNames", 
	"table1", "format_csv_delimiter", pCsvSeparator.toString(),
	"date_time_input_format", "best_effort"))
.executeAndWait();

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