diff --git a/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java b/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java index ba1b036f3..fb375accb 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java @@ -70,7 +70,7 @@ public Map getAllSettings() { * @return */ public InsertSettings setDeduplicationToken(String token) { - rawSettings.put("insert_deduplication_token", token); + serverSetting("insert_deduplication_token", token); return this; } diff --git a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java index 7bae4a952..4515acb9d 100644 --- a/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java +++ b/client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java @@ -317,6 +317,33 @@ public void testLogComment(String logComment) throws Exception { Assert.assertEquals(logRecords.get(0).getString("log_comment"), logComment == null ? "" : logComment); } + @Test(groups = { "integration" }) + public void testInsertSettingsDeduplicationToken() throws Exception { + final String tableName = "insert_settings_database_test"; + final String createTableSQL = "CREATE TABLE " + tableName + " ( A Int64 ) ENGINE = MergeTree ORDER BY A SETTINGS " + + "non_replicated_deduplication_window = 100"; + final String deduplicationToken = RandomStringUtils.randomAlphabetic(36); + + dropTable(tableName); + createTable(createTableSQL); + + InsertSettings insertSettings = settings.setInputStreamCopyBufferSize(8198 * 2) + .setDeduplicationToken(deduplicationToken); + + for (int i = 0; i < 3; ++i) { + ByteArrayOutputStream data = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(data); + writer.printf("%d\n", i); + writer.flush(); + InsertResponse response = client.insert(tableName, new ByteArrayInputStream(data.toByteArray()), ClickHouseFormat.TSV, insertSettings) + .get(30, TimeUnit.SECONDS); + response.close(); + } + + List records = client.queryAll("SELECT * FROM " + tableName); + assertEquals(records.size(), 1); + } + @DataProvider( name = "logCommentDataProvider") public static Object[] logCommentDataProvider() { return new Object[][] {