Skip to content

Commit 9b4c5d0

Browse files
committed
Merge branch 'main' into jdbc_connection_impl
2 parents bf76f28 + e2cdc0d commit 9b4c5d0

File tree

49 files changed

+3457
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3457
-791
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
if: ${{ startsWith(github.repository, 'ClickHouse/') }}
2525
name: "Mininal JMH Benchmarks"
2626
runs-on: "ubuntu-latest"
27-
timeout-minutes: 20
27+
timeout-minutes: 30
2828
steps:
2929
- name: Check out Git repository
3030
uses: actions/checkout@v4

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseColumn.java

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737

3838
import java.io.Serializable;
3939
import java.lang.reflect.Array;
40-
import java.math.BigInteger;
4140
import java.time.OffsetDateTime;
4241
import java.util.ArrayList;
4342
import java.util.Arrays;
44-
import java.util.Collection;
4543
import java.util.Collections;
4644
import java.util.Comparator;
4745
import java.util.HashMap;
@@ -51,6 +49,7 @@
5149
import java.util.Objects;
5250
import java.util.Set;
5351
import java.util.TimeZone;
52+
import java.util.stream.Collectors;
5453

5554
/**
5655
* This class represents a column defined in database.
@@ -72,6 +71,7 @@ public final class ClickHouseColumn implements Serializable {
7271
private static final String KEYWORD_MAP = ClickHouseDataType.Map.name();
7372
private static final String KEYWORD_NESTED = ClickHouseDataType.Nested.name();
7473
private static final String KEYWORD_VARIANT = ClickHouseDataType.Variant.name();
74+
private static final String KEYWORD_JSON = ClickHouseDataType.JSON.name();
7575

7676
private int columnCount;
7777
private int columnIndex;
@@ -90,6 +90,7 @@ public final class ClickHouseColumn implements Serializable {
9090
private List<ClickHouseColumn> nested;
9191
private List<String> parameters;
9292
private ClickHouseEnum enumConstants;
93+
private Map<String, ClickHouseColumn> jsonPredefinedPaths;
9394

9495
private int arrayLevel;
9596
private ClickHouseColumn arrayBaseColumn;
@@ -504,6 +505,23 @@ protected static int readColumn(String args, int startIndex, int len, String nam
504505
}
505506
}
506507
}
508+
} else if (args.startsWith(KEYWORD_JSON, i)) {
509+
int index = args.indexOf('(', i + KEYWORD_JSON.length());
510+
if (index > i) {
511+
i = ClickHouseUtils.skipBrackets(args, index, len, '(');
512+
String originalTypeName = args.substring(startIndex, i);
513+
List<ClickHouseColumn> nestedColumns = new ArrayList<>();
514+
515+
List<String> parameters = new ArrayList<>();
516+
parseJSONColumn(args.substring(index + 1, i - 1), nestedColumns, parameters);
517+
nestedColumns.sort(Comparator.comparing(o -> o.getDataType().name()));
518+
column = new ClickHouseColumn(ClickHouseDataType.JSON, name, originalTypeName, nullable, lowCardinality,
519+
parameters, nestedColumns);
520+
column.jsonPredefinedPaths = nestedColumns.stream().collect(Collectors.toMap(ClickHouseColumn::getColumnName,
521+
c -> c));
522+
fixedLength = false;
523+
estimatedLength++;
524+
}
507525
}
508526

509527
if (column == null) {
@@ -658,6 +676,54 @@ public static List<ClickHouseColumn> parse(String args) {
658676
return Collections.unmodifiableList(c);
659677
}
660678

679+
public static final String JSON_MAX_PATHS_PARAM = "max_dynamic_paths";
680+
public static final String JSON_MAX_DYN_TYPES_PARAM = "max_dynamic_types";
681+
public static final String JSON_SKIP_MARKER = "SKIP";
682+
683+
public static void parseJSONColumn(String args, List<ClickHouseColumn> nestedColumns, List<String> parameters) {
684+
if (args == null || args.isEmpty()) {
685+
return;
686+
}
687+
688+
String name = null;
689+
ClickHouseColumn column = null;
690+
StringBuilder builder = new StringBuilder();
691+
int i =0;
692+
int len = args.length();
693+
while (i < len) {
694+
char ch = args.charAt(i);
695+
if (Character.isWhitespace(ch)) {
696+
i++;
697+
continue;
698+
}
699+
700+
if (name == null) { // column name
701+
i = ClickHouseUtils.readNameOrQuotedString(args, i, len, builder) - 1;
702+
name = builder.toString();
703+
if (name.startsWith(JSON_SKIP_MARKER)) {
704+
name = null; // skip parameters
705+
i = ClickHouseUtils.skipContentsUntil(args, i, len, ',') - 1;
706+
} else if ( name.startsWith(JSON_MAX_PATHS_PARAM) || name.startsWith(JSON_MAX_DYN_TYPES_PARAM)) {
707+
parameters.add(name);
708+
name = null;
709+
i = ClickHouseUtils.skipContentsUntil(args, i, len, ',') - 1;
710+
}
711+
builder.setLength(0);
712+
} else if (column == null) { // now type
713+
LinkedList<ClickHouseColumn> colList = new LinkedList<>();
714+
i = readColumn(args, i, len, name, colList) - 1;
715+
column = colList.getFirst();
716+
nestedColumns.add(column);
717+
} else { // prepare for next column
718+
i = ClickHouseUtils.skipContentsUntil(args, i, len, ',') - 1;
719+
name = null;
720+
column = null;
721+
}
722+
723+
i++;
724+
}
725+
}
726+
661727
public ClickHouseColumn(ClickHouseDataType dataType, String columnName, String originalTypeName, boolean nullable,
662728
boolean lowCardinality, List<String> parameters, List<ClickHouseColumn> nestedColumns) {
663729
this(dataType, columnName, originalTypeName, nullable, lowCardinality, parameters, nestedColumns, ClickHouseEnum.EMPTY);
@@ -954,6 +1020,10 @@ public ClickHouseAggregateFunction getAggregateFunction() {
9541020
return aggFuncType;
9551021
}
9561022

1023+
public Map<String, ClickHouseColumn> getJsonPredefinedPaths() {
1024+
return jsonPredefinedPaths;
1025+
}
1026+
9571027
public ClickHouseArraySequence newArrayValue(ClickHouseDataConfig config) {
9581028
int level = arrayLevel;
9591029
ClickHouseArraySequence value;

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import java.util.function.Supplier;
5252
import java.util.function.UnaryOperator;
5353

54-
@Deprecated
5554
public final class ClickHouseUtils {
5655
private static final boolean IS_UNIX;
5756
private static final boolean IS_WINDOWS;

clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseColumnTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.clickhouse.data;
22

33
import java.math.BigInteger;
4+
import java.util.Arrays;
45
import java.util.Collections;
56
import java.util.LinkedList;
67
import java.util.List;
8+
import java.util.Map;
79

810
import org.testng.Assert;
911
import org.testng.annotations.DataProvider;
@@ -441,4 +443,26 @@ public boolean isWidenUnsignedTypes() {
441443
}
442444
}
443445
}
446+
447+
@Test(groups = {"unit"}, dataProvider = "testJSONBinaryFormat_dp")
448+
public void testJSONBinaryFormat(String jsonDef, int params, List<String> predefinedPaths) throws Exception {
449+
ClickHouseColumn column = ClickHouseColumn.of("v", jsonDef);
450+
Assert.assertEquals(column.getNestedColumns().size(), predefinedPaths.size(), "predefined paths count mismatch");
451+
Assert.assertEquals(column.getParameters().size(), params, "parameters count mismatch");
452+
}
453+
454+
@DataProvider
455+
public Object[][] testJSONBinaryFormat_dp() {
456+
457+
return new Object[][] {
458+
{"JSON", 0, Collections.emptyList()},
459+
{"JSON()", 0, Collections.emptyList()},
460+
{"JSON(stat.name String, count Int32)", 0, Arrays.asList("stat.name", "count")},
461+
{"JSON(stat.name String, `comments` String)", 0, Arrays.asList("stat.name", "comments")},
462+
{"JSON(max_dynamic_paths=3, stat.name String, count Int8, SKIP alt_count)", 1, Arrays.asList("stat.name", "count")},
463+
{"JSON(max_dynamic_paths=3, stat.name String, SKIP REGEXP '^-.*')", 1, Arrays.asList("stat.name")},
464+
{"JSON(max_dynamic_paths=3,SKIP REGEXP '^-.*',SKIP ff, flags Array(Array(Array(Int8))), SKIP alt_count)", 1, Arrays.asList("flags")},
465+
{"JSON(max_dynamic_types=3,max_dynamic_paths=3, SKIP REGEXP '^-.*',SKIP ff, flags Array(Array(Array(Int8))), SKIP alt_count)", 2, Arrays.asList("flags")},
466+
};
467+
}
444468
}

clickhouse-jdbc/pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<path>
239239
<groupId>org.projectlombok</groupId>
240240
<artifactId>lombok</artifactId>
241-
<version>1.18.32</version>
241+
<version>1.18.38</version>
242242
</path>
243243
<path>
244244
<groupId>org.openjdk.jmh</groupId>
@@ -363,17 +363,29 @@
363363
<groupId>org.apache.maven.plugins</groupId>
364364
<artifactId>maven-assembly-plugin</artifactId>
365365
<configuration>
366+
<finalName>${project.artifactId}-${project.version}-all-dependencies</finalName>
367+
<appendAssemblyId>false</appendAssemblyId>
366368
<descriptorRefs>
367369
<descriptorRef>jar-with-dependencies</descriptorRef>
368370
</descriptorRefs>
369371
<archive>
372+
370373
<addMavenDescriptor>false</addMavenDescriptor>
371374
<manifest>
372375
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
373376
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
374377
</manifest>
375378
</archive>
376379
</configuration>
380+
<executions>
381+
<execution>
382+
<id>make-assembly</id>
383+
<phase>package</phase>
384+
<goals>
385+
<goal>single</goal>
386+
</goals>
387+
</execution>
388+
</executions>
377389
</plugin>
378390
<plugin>
379391
<groupId>org.apache.maven.plugins</groupId>

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public class ClickHouseDriver implements java.sql.Driver {
2020
}
2121

2222
public ClickHouseDriver() {
23-
// log.debug("Creating a new instance of the 'proxy' ClickHouseDriver");
24-
log.info("ClickHouse JDBC driver version: {}", ClickHouseDriver.class.getPackage().getImplementationVersion());
23+
log.debug("ClickHouse JDBC driver version: {}", ClickHouseDriver.class.getPackage().getImplementationVersion());
2524
urlFlagSent = false;
2625
this.driver = getDriver(null);
2726
}
@@ -52,21 +51,21 @@ public boolean isV2(String url) {
5251
log.debug("Checking if V1 driver is requested. V2 is the default driver.");
5352
boolean v1Flag = Boolean.parseBoolean(System.getProperty("clickhouse.jdbc.v1", "false"));
5453
if (v1Flag) {
55-
log.info("V1 driver is requested through system property.");
54+
log.debug("V1 driver is requested through system property.");
5655
return false;
5756
}
5857

5958
if (url != null && url.contains("clickhouse.jdbc.v")) {
6059
urlFlagSent = true;
6160

6261
if (url.contains("clickhouse.jdbc.v1=true")) {
63-
log.info("V1 driver is requested through URL.");
62+
log.debug("V1 driver is requested through URL.");
6463
return false;
6564
} if (url.contains("clickhouse.jdbc.v2=false")) {
66-
log.info("V1 driver is requested through URL.");
65+
log.debug("V1 driver is requested through URL.");
6766
return false;
6867
} else {
69-
log.info("V2 driver is requested through URL.");
68+
log.debug("V2 driver is requested through URL.");
7069
return true;
7170
}
7271
}
@@ -81,10 +80,10 @@ private java.sql.Driver getDriver(String url) {
8180
}
8281

8382
if (isV2(url)) {
84-
log.info("v2 driver");
83+
log.debug("v2 driver");
8584
driver = new com.clickhouse.jdbc.Driver();
8685
} else {
87-
log.info("v1 driver");
86+
log.debug("v1 driver");
8887
driver = new DriverV1();
8988
}
9089

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static String getFrameworksDetected() {
109109

110110
public static void load() {
111111
try {
112-
log.info("Registering ClickHouse JDBC driver v1 ({})", driverVersion);
112+
log.debug("Registering ClickHouse JDBC driver v1 ({})", driverVersion);
113113
DriverManager.registerDriver(new DriverV1());
114114
} catch (SQLException e) {
115115
throw new IllegalStateException(e);
@@ -120,7 +120,7 @@ public static void load() {
120120

121121
public static void unload() {
122122
try {
123-
log.info("Unregistering ClickHouse JDBC driver v1 ({})", driverVersion);
123+
log.debug("Unregistering ClickHouse JDBC driver v1 ({})", driverVersion);
124124
DriverManager.deregisterDriver(new DriverV1());
125125
} catch (SQLException e) {
126126
throw new IllegalStateException(e);

client-v2/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
<version>2.0.16</version>
136136
<scope>test</scope>
137137
</dependency>
138+
<dependency>
139+
<groupId>org.mockito</groupId>
140+
<artifactId>mockito-core</artifactId>
141+
<version>5.19.0</version>
142+
<scope>test</scope>
143+
</dependency>
138144
</dependencies>
139145

140146
<build>
@@ -153,7 +159,7 @@
153159
<path>
154160
<groupId>org.projectlombok</groupId>
155161
<artifactId>lombok</artifactId>
156-
<version>1.18.32</version>
162+
<version>1.18.38</version>
157163
</path>
158164
</annotationProcessorPaths>
159165
<release>8</release>

0 commit comments

Comments
 (0)