Skip to content

Commit 8533f46

Browse files
committed
Merge branch 'main' into fix_password_authentication
2 parents fcdda34 + 714dcf8 commit 8533f46

File tree

5 files changed

+62
-20
lines changed

5 files changed

+62
-20
lines changed

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ClickHouseHttpConnection.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@
1010
import java.nio.charset.Charset;
1111
import java.nio.charset.StandardCharsets;
1212
import java.util.Base64;
13-
import java.util.Collections;
14-
import java.util.HashSet;
15-
import java.util.LinkedHashMap;
16-
import java.util.List;
17-
import java.util.Locale;
18-
import java.util.Map;
19-
import java.util.Optional;
13+
import java.util.*;
2014
import java.util.Map.Entry;
21-
import java.util.Set;
2215

2316
import com.clickhouse.client.ClickHouseClient;
2417
import com.clickhouse.client.ClickHouseConfig;

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDriver.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
import java.sql.DriverPropertyInfo;
77
import java.sql.SQLException;
88
import java.sql.SQLFeatureNotSupportedException;
9-
import java.util.ArrayList;
10-
import java.util.Collections;
11-
import java.util.HashMap;
12-
import java.util.LinkedHashMap;
13-
import java.util.List;
14-
import java.util.Map;
15-
import java.util.Properties;
16-
import java.util.ServiceLoader;
9+
import java.util.*;
1710
import java.util.Map.Entry;
1811

1912
import com.clickhouse.client.ClickHouseClient;
@@ -49,6 +42,32 @@ public class ClickHouseDriver implements Driver {
4942

5043
static final java.util.logging.Logger parentLogger = java.util.logging.Logger.getLogger("com.clickhouse.jdbc");
5144

45+
public static String frameworksDetected = null;
46+
47+
public static class FrameworksDetection {
48+
private static final List<String> FRAMEWORKS_TO_DETECT = Arrays.asList("apache.spark");
49+
static volatile String frameworksDetected = null;
50+
51+
private FrameworksDetection() {
52+
}
53+
public static String getFrameworksDetected() {
54+
if (frameworksDetected == null) {
55+
Set<String> inferredFrameworks = new LinkedHashSet<>();
56+
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
57+
for (String framework : FRAMEWORKS_TO_DETECT) {
58+
if (ste.toString().contains(framework)) {
59+
inferredFrameworks.add(String.format("(%s)", framework));
60+
}
61+
}
62+
}
63+
64+
frameworksDetected = String.join("; ", inferredFrameworks);
65+
}
66+
return frameworksDetected;
67+
}
68+
69+
}
70+
5271
static {
5372
String str = ClickHouseDriver.class.getPackage().getImplementationVersion();
5473
if (str != null && !str.isEmpty()) {
@@ -115,7 +134,6 @@ public static Map<ClickHouseOption, Serializable> toClientOptions(Properties pro
115134
options.put(o, ClickHouseOption.fromString(e.getValue().toString(), o.getValueType()));
116135
}
117136
}
118-
119137
return options;
120138
}
121139

@@ -128,7 +146,7 @@ private DriverPropertyInfo create(ClickHouseOption option, Properties props) {
128146

129147
Class<?> clazz = option.getValueType();
130148
if (Boolean.class == clazz || boolean.class == clazz) {
131-
propInfo.choices = new String[] { "true", "false" };
149+
propInfo.choices = new String[]{"true", "false"};
132150
} else if (clazz.isEnum()) {
133151
Object[] values = clazz.getEnumConstants();
134152
String[] names = new String[values.length];

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ public ClickHouseConnectionImpl(String url, Properties properties) throws SQLExc
291291
public ClickHouseConnectionImpl(ConnectionInfo connInfo) throws SQLException {
292292
Properties props = connInfo.getProperties();
293293
jvmTimeZone = TimeZone.getDefault();
294-
294+
if (props.get("disable_frameworks_detection") == null || !props.get("disable_frameworks_detection").toString().equalsIgnoreCase("true")) {
295+
ClickHouseDriver.frameworksDetected = ClickHouseDriver.FrameworksDetection.getFrameworksDetected();
296+
if (ClickHouseDriver.frameworksDetected != null)
297+
props.setProperty(ClickHouseClientOption.PRODUCT_NAME.getKey(), props.getProperty(ClickHouseClientOption.PRODUCT_NAME.getKey()) + ClickHouseDriver.frameworksDetected);
298+
}
295299
ClickHouseClientBuilder clientBuilder = ClickHouseClient.builder()
296300
.options(ClickHouseDriver.toClientOptions(props))
297301
.defaultCredentials(connInfo.getDefaultCredentials());

client-v2/src/main/java/com/clickhouse/client/api/insert/InsertSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Map<String, Object> getAllSettings() {
7070
* @return
7171
*/
7272
public InsertSettings setDeduplicationToken(String token) {
73-
rawSettings.put("insert_deduplication_token", token);
73+
serverSetting("insert_deduplication_token", token);
7474
return this;
7575
}
7676

client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,33 @@ public void testLogComment(String logComment) throws Exception {
317317
Assert.assertEquals(logRecords.get(0).getString("log_comment"), logComment == null ? "" : logComment);
318318
}
319319

320+
@Test(groups = { "integration" })
321+
public void testInsertSettingsDeduplicationToken() throws Exception {
322+
final String tableName = "insert_settings_database_test";
323+
final String createTableSQL = "CREATE TABLE " + tableName + " ( A Int64 ) ENGINE = MergeTree ORDER BY A SETTINGS " +
324+
"non_replicated_deduplication_window = 100";
325+
final String deduplicationToken = RandomStringUtils.randomAlphabetic(36);
326+
327+
dropTable(tableName);
328+
createTable(createTableSQL);
329+
330+
InsertSettings insertSettings = settings.setInputStreamCopyBufferSize(8198 * 2)
331+
.setDeduplicationToken(deduplicationToken);
332+
333+
for (int i = 0; i < 3; ++i) {
334+
ByteArrayOutputStream data = new ByteArrayOutputStream();
335+
PrintWriter writer = new PrintWriter(data);
336+
writer.printf("%d\n", i);
337+
writer.flush();
338+
InsertResponse response = client.insert(tableName, new ByteArrayInputStream(data.toByteArray()), ClickHouseFormat.TSV, insertSettings)
339+
.get(30, TimeUnit.SECONDS);
340+
response.close();
341+
}
342+
343+
List<GenericRecord> records = client.queryAll("SELECT * FROM " + tableName);
344+
assertEquals(records.size(), 1);
345+
}
346+
320347
@DataProvider( name = "logCommentDataProvider")
321348
public static Object[] logCommentDataProvider() {
322349
return new Object[][] {

0 commit comments

Comments
 (0)