Skip to content

Commit 8c354f2

Browse files
committed
Merge branch 'main' into jdbc_impl_getResultSet_in_Array
2 parents 8408fdd + c0be415 commit 8c354f2

File tree

10 files changed

+292
-205
lines changed

10 files changed

+292
-205
lines changed

.github/workflows/test_head.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
27-
project: ["clickhouse-http-client", "client-v2", "clickhouse-jdbc"]
27+
project: ["clickhouse-http-client", "client-v2", "clickhouse-jdbc", "jdbc-v2"]
2828
fail-fast: false
2929
timeout-minutes: 15
3030
name: ${{ matrix.project }}
@@ -66,6 +66,9 @@ jobs:
6666
java-version: '17'
6767
distribution: 'temurin'
6868
architecture: x64
69+
- name: Build
70+
run: |
71+
mvn --also-make --batch-mode --no-transfer-progress -DclickhouseVersion=$CH_VERSION -Dmaven.javadoc.skip=true -DskipTests=true clean install
6972
- name: Test R2DBC ${{ matrix.r2dbc }}
7073
run: |
7174
mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc -DclickhouseVersion=$CH_VERSION \

clickhouse-client/src/test/resources/containers/clickhouse-server/users.d/users.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
</poorman2>
6363
<test>
6464
<profile>default</profile>
65-
<networks incl="networks" replace="replace">
66-
<ip>::/0</ip>
67-
</networks>
65+
<!-- <networks incl="networks" replace="replace">-->
66+
<!-- <ip>::/0</ip>-->
67+
<!-- </networks>-->
6868
<password>123</password>
6969
<quota>default</quota>
7070
<allow_databases>
@@ -78,9 +78,9 @@
7878
</me>
7979
<access_dba>
8080
<profile>default</profile>
81-
<networks incl="networks" replace="replace">
82-
<ip>::/0</ip>
83-
</networks>
81+
<!-- <networks incl="networks" replace="replace">-->
82+
<!-- <ip>::/0</ip>-->
83+
<!-- </networks>-->
8484
<password>123</password>
8585
<quota>default</quota>
8686
<access_management>1</access_management>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ public enum ClickHouseDataType implements SQLType {
106106
Ring(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Point)
107107
LineString( Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Point)
108108
MultiLineString(Object.class, false, true, true, 0, 0, 0, 0, 0, true), // same as Array(Ring)
109-
110109
JSON(Object.class, false, false, false, 0, 0, 0, 0, 0, true, 0x30),
111-
@Deprecated
110+
@Deprecated // (since = "CH 25.11")
112111
Object(Object.class, true, true, false, 0, 0, 0, 0, 0, true),
113112
String(String.class, false, true, false, 0, 0, 0, 0, 0, false, 0x15, "BINARY LARGE OBJECT", "BINARY VARYING", "BLOB",
114113
"BYTEA", "CHAR", "CHAR LARGE OBJECT", "CHAR VARYING", "CHARACTER", "CHARACTER LARGE OBJECT",
115-
"CHARACTER VARYING", "CLOB", "GEOMETRY", "LONGBLOB", "LONGTEXT", "MEDIUMBLOB", "MEDIUMTEXT",
114+
"CHARACTER VARYING", "CLOB", "LONGBLOB", "LONGTEXT", "MEDIUMBLOB", "MEDIUMTEXT",
116115
"NATIONAL CHAR", "NATIONAL CHAR VARYING", "NATIONAL CHARACTER", "NATIONAL CHARACTER LARGE OBJECT",
117116
"NATIONAL CHARACTER VARYING", "NCHAR", "NCHAR LARGE OBJECT", "NCHAR VARYING", "NVARCHAR", "TEXT",
118117
"TINYBLOB", "TINYTEXT", "VARBINARY", "VARCHAR", "VARCHAR2"),
@@ -131,6 +130,7 @@ public enum ClickHouseDataType implements SQLType {
131130
Time(LocalDateTime.class, true, false, false, 4, 9, 0, 0, 9, false, 0x32), // 0x33 for Time(Timezone)
132131
Time64(LocalDateTime.class, true, false, false, 8, 9, 0, 0, 0, false, 0x34), // 0x35 for Time64(P, Timezone)
133132
QBit(Double.class, true, true, false, 0, 0, 0, 0, 0, false, 0x36),
133+
Geometry(Object.class, false, false, false, 0, 0, 0, 0, 0, true),
134134
;
135135

136136
public static final List<ClickHouseDataType> ORDERED_BY_RANGE_INT_TYPES =

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,14 +1728,12 @@ public List<GenericRecord> queryAll(String sqlQuery, Map<String, Object> params,
17281728
CompletableFuture<QueryResponse> f = query(sqlQuery, params, requestSettings);
17291729
try (QueryResponse response = operationTimeout == 0 ? f.get() : f.get(operationTimeout, TimeUnit.MILLISECONDS)) {
17301730
List<GenericRecord> records = new ArrayList<>();
1731-
if (response.getResultRows() > 0) {
1732-
RowBinaryWithNamesAndTypesFormatReader reader =
1733-
(RowBinaryWithNamesAndTypesFormatReader) newBinaryFormatReader(response);
1731+
RowBinaryWithNamesAndTypesFormatReader reader =
1732+
(RowBinaryWithNamesAndTypesFormatReader) newBinaryFormatReader(response);
17341733

1735-
Map<String, Object> record;
1736-
while (reader.readRecord((record = new LinkedHashMap<>()))) {
1737-
records.add(new MapBackedRecord(record, reader.getConvertions(), reader.getSchema()));
1738-
}
1734+
Map<String, Object> record;
1735+
while (reader.readRecord((record = new LinkedHashMap<>()))) {
1736+
records.add(new MapBackedRecord(record, reader.getConvertions(), reader.getSchema()));
17391737
}
17401738
return records;
17411739
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.clickhouse.client.api.data_formats;
2+
3+
import com.clickhouse.client.BaseIntegrationTest;
4+
import com.clickhouse.client.ClickHouseNode;
5+
import com.clickhouse.client.ClickHouseProtocol;
6+
import com.clickhouse.client.ClickHouseServerForTest;
7+
import com.clickhouse.client.api.Client;
8+
import com.clickhouse.client.api.enums.Protocol;
9+
import com.clickhouse.client.api.query.GenericRecord;
10+
import lombok.Data;
11+
import org.testng.Assert;
12+
import org.testng.annotations.Test;
13+
14+
import java.util.Collections;
15+
import java.util.List;
16+
import java.util.Random;
17+
18+
@Test(groups = {"integration"})
19+
public class RowBinaryTest extends BaseIntegrationTest {
20+
21+
protected Client.Builder newClient() {
22+
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
23+
boolean isSecure = isCloud();
24+
return new Client.Builder()
25+
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isSecure)
26+
.setUsername("default")
27+
.setPassword(ClickHouseServerForTest.getPassword())
28+
.setDefaultDatabase(ClickHouseServerForTest.getDatabase());
29+
}
30+
31+
32+
@Test(groups = {"integration"})
33+
void testDefaultWithFunction() {
34+
final String table = "test_defaults_with_function";
35+
final String createTable = "CREATE TABLE " + table +" ( " +
36+
" name String," +
37+
" v Int64 DEFAULT 10, " +
38+
" fingerPrint UInt64 DEFAULT xxHash64(name)," +
39+
" comments String" +
40+
") ENGINE = MergeTree()" +
41+
"ORDER BY name;";
42+
43+
try (Client client = newClient().build()){
44+
45+
client.execute("DROP TABLE IF EXISTS " + table);
46+
client.execute(createTable);
47+
48+
client.register(DefaultWithFunctionPojo.class, client.getTableSchema(table));
49+
50+
DefaultWithFunctionPojo entity = new DefaultWithFunctionPojo();
51+
entity.setName("test");
52+
entity.setComments("test");
53+
List<DefaultWithFunctionPojo> data = Collections.singletonList(entity);
54+
client.insert(table, data);
55+
56+
List<GenericRecord> records = client.queryAll("SELECT * FROM " + table);
57+
Assert.assertEquals(records.size(), 1);
58+
GenericRecord record = records.get(0);
59+
Assert.assertEquals(record.getString("name"), "test");
60+
Assert.assertEquals(record.getLong("v"), 10);
61+
Assert.assertTrue(record.getLong("fingerPrint") > 0);
62+
Assert.assertEquals(record.getString("comments"), "test");
63+
}
64+
}
65+
66+
@Data
67+
public static class DefaultWithFunctionPojo {
68+
private String name;
69+
private Long fingerPrint;
70+
private Long v;
71+
private String comments;
72+
}
73+
}

client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public void testVariantWithSimpleDataTypes() throws Exception {
172172
switch (dataType) {
173173
case BFloat16:
174174
case QBit:
175+
case Geometry:
175176
// TODO: add support
176177
continue dataTypesLoop;
177178
// skipped
@@ -466,6 +467,7 @@ public void testDynamicWithPrimitives() throws Exception {
466467
switch (dataType) {
467468
case BFloat16:
468469
case QBit:
470+
case Geometry:
469471
// TODO: add support
470472
continue;
471473
case Array:

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,13 +1034,14 @@ private ClickHouseDataType sqlType2ClickHouseDataType(SQLType type) throws SQLEx
10341034
private String encodeObject(Object x, ClickHouseDataType clickHouseDataType, Integer scaleOrLength) throws SQLException {
10351035
String encodedObject = encodeObject(x);
10361036
if (clickHouseDataType != null) {
1037-
encodedObject += "::" + clickHouseDataType.name();
1037+
encodedObject = "CAST (" + encodedObject + " AS " + clickHouseDataType.name();
10381038
if (clickHouseDataType.hasParameter()) {
10391039
if (scaleOrLength == null) {
10401040
throw new SQLException("Target type " + clickHouseDataType + " requires a parameter");
10411041
}
10421042
encodedObject += "(" + scaleOrLength + ")";
10431043
}
1044+
encodedObject += ")";
10441045
}
10451046
return encodedObject;
10461047
}

0 commit comments

Comments
 (0)