Repository navigation
Insert function is not working #1401
Description
Activity
@shabir1 did you managed?
@mzitnik I used the below method to upload the local file on clickhouse.
static long insert(String tableName, String csvFilePath) throws Exception { ClickHouseNode server = getServer(); try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(csvFilePath))) { ClickHousePassThruStream stream = ClickHousePassThruStream.of( bufferedInputStream, ClickHouseCompression.NONE, 0, ClickHouseFormat.CSVWithNames ); CompletableFuture<ClickHouseResponseSummary> load = ClickHouseClient.load(server, tableName, stream); ClickHouseResponseSummary clickHouseResponse = load.get(); return clickHouseResponse.getWrittenRows(); } catch (Exception e) { System.out.println("Failed to load"); e.printStackTrace(); throw new Exception(); } }But on huge files, it failed with memory issues, Most failures occurred on the file that contained more than 300 columns.
ERROR [2023-07-27 06:20:36,451] com.datoin.library.dataset.sql.utility.commons.abstracts.sql.AbstractDBEngine: Failed to load dataset java.util.concurrent.ExecutionException: com.clickhouse.client.ClickHouseException: Code: 241. DB::Exception: Memory limit (total) exceeded: would use 3.36 GiB (attempt to allocate chunk of 4360384 bytes), maximum: 3.24 GiB. OvercommitTracker decision: Query was selected to stop by OvercommitTracker. (MEMORY_LIMIT_EXCEEDED) (version 23.6.2.18 (official build)) , server ClickHouseNode [uri=http://localhost:8123/cayleytest95814, options={connect_timeout=5000000,socket_timeout=5000000}]@75218225 at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357) at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)@shabir1 from here it looks like a ClickHouse server limit issue did you tried to set memory
@mzitnik How to set memory in the above method?
and if I set max_memory_usage_for_user = 10, Is it 10 Bytes/MB/GB ?@shabir1 It is bytes
@mzitnik How to set memory in the below method?
like max_memory_usage_for_user, max_memory_usage, etcstatic long insert(String tableName, String csvFilePath) throws Exception { ClickHouseNode server = ClickHouseNode.builder() .host(System.getProperty("chHost", "localhost")) .port(ClickHouseProtocol.HTTP, Integer.getInteger("chPort", 8123)) .database("ShabirBhat_project") .addOption("connect_timeout", String.valueOf(1350 * 1000)) .addOption("socket_timeout", String.valueOf(1350 * 1000)) .credentials(ClickHouseCredentials.fromUserAndPassword( System.getProperty("chUser", "default"), System.getProperty("chPassword", ""))) .build(); try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(csvFilePath))) { ClickHousePassThruStream stream = ClickHousePassThruStream.of( bufferedInputStream, ClickHouseCompression.NONE, 0, ClickHouseFormat.CSVWithNames ); CompletableFuture<ClickHouseResponseSummary> load = ClickHouseClient.load(server, tableName, stream); ClickHouseResponseSummary clickHouseResponse = load.get(); return clickHouseResponse.getWrittenRows(); } catch (Exception e) { System.out.println("Failed to load"); e.printStackTrace(); throw new Exception(); } }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!
I am not able to insert the CSV data into the existing table in click house. using clickhouse-java
I run the below code but it throws the errro:
Error
I tried to replace the below code with my csv data