Closed as not planned
Closed as not planned
Copy link
Labels
clientModule: the client (client-v2; with legacy: the v1 client)documentationImprovements or additions to documentationlegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemqueriesArea: how the client builds and runs statements (parameters, quoting, batches)questionstale
Milestone
Description
What's an efficient way to insert CSV file data into an existing table in ClickHouse?
I need an optimal way to insert CSV data in existing tables In terms of memory as well as time.
Every time data should be appended into the existing table, I tried the below code but it replaces the existing data.
ClickHouseClient.load(
ClickHouseNode.of(uri),
tableName,
// will parse file name later so that you don't have to specify compression and format
ClickHouseFile.of(filePath, ClickHouseCompression.NONE, 0, ClickHouseFormat.CSV)).get();
Metadata
Metadata
Assignees
Labels
clientModule: the client (client-v2; with legacy: the v1 client)documentationImprovements or additions to documentationlegacyOnly the v1 stack (clickhouse-client, clickhouse-http-client, clickhouse-jdbc) has the problemqueriesArea: how the client builds and runs statements (parameters, quoting, batches)questionstale
Activity
shabir1 commentedon Jul 13, 2023
I tried this also but the same issue it overwrites the data.
shabir1 commentedon Jul 13, 2023
I tried this also but the same issue it overwrites the data.
zhicwu commentedon Jul 13, 2023
Hi @shabir1, you probably want to start with INSERT INFO FROM INFILE. Please check example below and this test.
Why are you certain the data was overwritten if it consists entirely of insert statements? Which table engine are you using? You may check
system.query_logto review the queries.shabir1 commentedon Jul 13, 2023
@zhicwu Actually, I have very huge files more than 2GB, I want an efficient way to upload the CSV data into the existing table without any memory issues and with in less time.
Is there any way to load data from a disk not from memory, like streaming the data?
shabir1 commentedon Jul 13, 2023
@zhicwu And sometimes it throws an error when the file takes time to upload more than 30 secs.
zhicwu commentedon Jul 14, 2023
Using the
INSERT INTO FROM INFILEstatement is a streaming approach. While it's not zero-copy at this point, it is quite similar to using curl to load a file into ClickHouse.Please consider increasing the
socket_timeoutvalue, which is set to a default of 30 seconds.shabir1 commentedon Jul 14, 2023
@zhicwu Will you please share the code snippet of
INSERT INTO FROM INFILEusing Java ClickHouseClient.mshustov commentedon Aug 15, 2023
@shabir1 PTAL at this example
clickhouse-java/clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java
Line 1650 in d6eff62
The current implementation doesn't allow to provide a schema for the destination table, which might help to avoid problems like this #1413
WDYT @mzitnik @zhicwu ?
shabir1 commentedon Aug 15, 2023
@mshustov
How to set memory in the below method?
like max_memory_usage_for_user, max_memory_usage, etc
shabir1 commentedon Aug 15, 2023
@mshustov On huge files, the above method failed with memory issues, Most failures occurred on the file that contained more than 300 columns.
shabir1 commentedon Aug 15, 2023
If the file size is 5GB but the number of columns is less (less than 10 columns).then the above method works fine.
But if the file size is just 200MB but the number of columns is huge (greater than 800 columns) then the above method failed with memory issues.
github-actions commentedon Jan 8, 2025
This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!
github-actions commentedon Feb 8, 2025
This issue has been automatically closed because it has not had any further activity in the last 30 days. Thank you for your contributions!