Skip to content

Commit 70cf5f9

Browse files
authored
Merge pull request #1073 from zhicwu/develop
Respect custom format for mutation
2 parents fedb151 + 0de58f9 commit 70cf5f9

File tree

43 files changed

+412
-280
lines changed

Some content is hidden

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

43 files changed

+412
-280
lines changed

clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import com.clickhouse.client.ClickHouseClient;
44
import com.clickhouse.client.ClickHouseClientBuilder;
5+
import com.clickhouse.client.ClickHouseException;
56
import com.clickhouse.client.ClickHouseNode;
67
import com.clickhouse.client.ClickHouseProtocol;
78
import com.clickhouse.client.ClickHouseServerForTest;
89
import com.clickhouse.client.ClientIntegrationTest;
910
import com.clickhouse.client.cli.config.ClickHouseCommandLineOption;
1011

12+
import java.io.IOException;
13+
1114
import org.testcontainers.containers.GenericContainer;
1215
import org.testng.Assert;
1316
import org.testng.SkipException;
@@ -49,19 +52,19 @@ protected ClickHouseNode getServer() {
4952

5053
@Test(groups = { "integration" })
5154
@Override
52-
public void testCustomLoad() throws Exception {
55+
public void testCustomLoad() throws ClickHouseException {
5356
throw new SkipException("Skip due to time out error");
5457
}
5558

5659
@Test(groups = { "integration" })
5760
@Override
58-
public void testLoadRawData() throws Exception {
61+
public void testLoadRawData() throws ClickHouseException, IOException {
5962
throw new SkipException("Skip due to response summary is always empty");
6063
}
6164

6265
@Test(groups = { "integration" })
6366
@Override
64-
public void testMultipleQueries() throws Exception {
67+
public void testMultipleQueries() throws ClickHouseException {
6568
// FIXME not sure if the occasional "Stream closed" exception is related to
6669
// zeroturnaround/zt-exec#30 or not
6770
/*

clickhouse-client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</executions>
8989
<configuration>
9090
<excludes>
91-
<exclude>META-INF/services</exclude>
91+
<exclude>META-INF/services/*</exclude>
9292
</excludes>
9393
</configuration>
9494
</plugin>

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseRequest.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public static class Mutation extends ClickHouseRequest<Mutation> {
6565
protected Mutation(ClickHouseRequest<?> request, boolean sealed) {
6666
super(request.getClient(), request.server, request.serverRef, request.options, sealed);
6767

68+
// use headless format if possible
69+
if (!sealed) {
70+
format(request.getFormat().defaultInputFormat());
71+
}
72+
6873
this.settings.putAll(request.settings);
6974
this.txRef.set(request.txRef.get());
7075

@@ -117,8 +122,7 @@ protected String getQuery() {
117122
}
118123

119124
return builder.length() > 0 && index == len ? sql
120-
: new StringBuilder().append(sql).append("\n FORMAT ").append(getInputFormat().name())
121-
.toString();
125+
: new StringBuilder().append(sql).append("\n FORMAT ").append(getFormat().name()).toString();
122126
}
123127

124128
return super.getQuery();
@@ -239,6 +243,11 @@ public Mutation data(ClickHouseDeferredValue<ClickHouseInputStream> input) {
239243
return this;
240244
}
241245

246+
@Override
247+
public ClickHouseFormat getInputFormat() {
248+
return getFormat();
249+
}
250+
242251
@Override
243252
public CompletableFuture<ClickHouseResponse> execute() {
244253
if (writer != null) {
@@ -646,7 +655,10 @@ public ClickHouseFormat getFormat() {
646655
* Gets data format used for input(e.g. writing data into server).
647656
*
648657
* @return data format for input
658+
* @deprecated will be removed in v0.3.3, please use
659+
* {@code getFormat().defaultInputFormat()} instead
649660
*/
661+
@Deprecated
650662
public ClickHouseFormat getInputFormat() {
651663
return getFormat().defaultInputFormat();
652664
}

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClientTest.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import org.testng.annotations.Test;
55

66
import java.io.ByteArrayOutputStream;
7+
import java.io.IOException;
8+
import java.util.concurrent.ExecutionException;
79

810
import com.clickhouse.client.ClickHouseRequest.Mutation;
911

1012
public class ClickHouseClientTest {
1113
@Test(groups = { "unit" })
12-
public void testGetAsyncRequestOutputStream() throws Exception {
14+
public void testGetAsyncRequestOutputStream() throws IOException {
1315
ClickHouseConfig config = new ClickHouseConfig();
1416
for (int i = 0; i < 256; i++) {
1517
ByteArrayOutputStream bas = new ByteArrayOutputStream();
@@ -21,7 +23,7 @@ public void testGetAsyncRequestOutputStream() throws Exception {
2123
}
2224

2325
@Test(groups = { "unit" })
24-
public void testGetRequestOutputStream() throws Exception {
26+
public void testGetRequestOutputStream() throws IOException {
2527
ClickHouseConfig config = new ClickHouseConfig();
2628
for (int i = 0; i < 256; i++) {
2729
ByteArrayOutputStream bas = new ByteArrayOutputStream();
@@ -33,7 +35,7 @@ public void testGetRequestOutputStream() throws Exception {
3335
}
3436

3537
@Test(groups = { "unit" })
36-
public void testQuery() throws Exception {
38+
public void testQuery() throws ExecutionException, InterruptedException {
3739
ClickHouseClient client = ClickHouseClient.builder().build();
3840
Assert.assertNotNull(client);
3941
ClickHouseRequest<?> req = client.connect(ClickHouseNode.builder().build());
@@ -48,7 +50,7 @@ public void testQuery() throws Exception {
4850
}
4951

5052
@Test(groups = { "unit" })
51-
public void testMutation() throws Exception {
53+
public void testMutation() throws ExecutionException, InterruptedException {
5254
ClickHouseClient client = ClickHouseClient.builder().build();
5355
Assert.assertNotNull(client);
5456
Mutation req = client.connect(ClickHouseNode.builder().build()).write();

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClusterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private Object[][] getNodeSelectors() {
3535
}
3636

3737
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
38-
public void testGetNode(ClickHouseNodeSelector nodeSelector) throws Exception {
38+
public void testGetNode(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
3939
int size = 5;
4040
int requests = 500;
4141
int len = size * requests;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void testReadNestedColumn() {
141141
}
142142

143143
@Test(groups = { "unit" })
144-
public void testParse() throws Exception {
144+
public void testParse() {
145145
ClickHouseColumn column = ClickHouseColumn.of("arr", "Nullable(Array(Nullable(UInt8))");
146146
Assert.assertNotNull(column);
147147

@@ -156,7 +156,7 @@ public void testParse() throws Exception {
156156
}
157157

158158
@Test(groups = { "unit" })
159-
public void testAggregationFunction() throws Exception {
159+
public void testAggregationFunction() {
160160
ClickHouseColumn column = ClickHouseColumn.of("aggFunc", "AggregateFunction(groupBitmap, UInt32)");
161161
Assert.assertTrue(column.isAggregateFunction());
162162
Assert.assertEquals(column.getDataType(), ClickHouseDataType.AggregateFunction);
@@ -178,7 +178,7 @@ public void testAggregationFunction() throws Exception {
178178
}
179179

180180
@Test(groups = { "unit" })
181-
public void testArray() throws Exception {
181+
public void testArray() {
182182
ClickHouseColumn column = ClickHouseColumn.of("arr",
183183
"Array(Array(Array(Array(Array(Map(LowCardinality(String), Tuple(Array(UInt8),LowCardinality(String))))))))");
184184
Assert.assertTrue(column.isArray());
@@ -204,7 +204,7 @@ public void testArray() throws Exception {
204204
}
205205

206206
@Test(dataProvider = "enumTypesProvider", groups = { "unit" })
207-
public void testEnum(String typeName) throws Exception {
207+
public void testEnum(String typeName) {
208208
Assert.assertThrows(IllegalArgumentException.class,
209209
() -> ClickHouseColumn.of("e", typeName + "('Query''Start' = a)"));
210210
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseColumn.of("e", typeName + "(aa,1)"));
@@ -236,7 +236,7 @@ public void testObjectType(String typeName) {
236236
}
237237

238238
@Test(groups = { "unit" })
239-
public void testSimpleAggregationFunction() throws Exception {
239+
public void testSimpleAggregationFunction() {
240240
ClickHouseColumn c = ClickHouseColumn.of("a", "SimpleAggregateFunction(max, UInt64)");
241241
Assert.assertEquals(c.getDataType(), ClickHouseDataType.SimpleAggregateFunction);
242242
Assert.assertEquals(c.getNestedColumns().get(0).getDataType(), ClickHouseDataType.UInt64);

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseConfigTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testDefaultValues() {
3434
}
3535

3636
@Test(groups = { "unit" })
37-
public void testCustomValues() throws Exception {
37+
public void testCustomValues() {
3838
String clientName = "test client";
3939
String cluster = "test cluster";
4040
String database = "test_database";

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseDataStreamFactoryTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.clickhouse.client;
22

3+
import java.io.IOException;
34
import java.util.concurrent.CompletableFuture;
5+
import java.util.concurrent.ExecutionException;
46

57
import org.testng.Assert;
68
import org.testng.annotations.Test;
79

810
public class ClickHouseDataStreamFactoryTest {
911
@Test(groups = { "unit" })
10-
public void testGetInstance() throws Exception {
12+
public void testGetInstance() {
1113
Assert.assertNotNull(ClickHouseDataStreamFactory.getInstance());
1214
}
1315

1416
@Test(groups = { "unit" })
15-
public void testCreatePipedOutputStream() throws Exception {
17+
public void testCreatePipedOutputStream() throws ExecutionException, IOException, InterruptedException {
1618
ClickHouseConfig config = new ClickHouseConfig();
1719

1820
// read in worker thread

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseLoadBalancingPolicyTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testGetOrCreate() {
7171
}
7272

7373
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
74-
public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
74+
public void testDummy(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
7575
int size = 5;
7676
int requests = 500;
7777
int len = size * requests;
@@ -130,7 +130,7 @@ public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
130130
}
131131

132132
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
133-
public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception {
133+
public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
134134
int size = 5;
135135
int requests = 500;
136136
int len = size * requests;
@@ -189,7 +189,7 @@ public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception
189189
}
190190

191191
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
192-
public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws Exception {
192+
public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
193193
int size = 5;
194194
int requests = 500;
195195
int len = size * requests;
@@ -238,7 +238,7 @@ public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) thro
238238
}
239239

240240
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
241-
public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception {
241+
public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
242242
int size = 5;
243243
int requests = 500;
244244
int len = size * requests;
@@ -297,7 +297,7 @@ public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception
297297
}
298298

299299
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
300-
public void testRandom(ClickHouseNodeSelector nodeSelector) throws Exception {
300+
public void testRandom(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
301301
int size = 5;
302302
int requests = 500;
303303
int len = size * requests;

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.testng.annotations.Test;
55

66
import java.net.URI;
7+
import java.net.URISyntaxException;
78
import java.util.Arrays;
89
import java.util.Collections;
910
import java.util.HashMap;
@@ -367,7 +368,7 @@ public void testCaseInsensitiveEnumValue() {
367368
}
368369

369370
@Test(groups = { "unit" })
370-
public void testQueryWithSlash() throws Exception {
371+
public void testQueryWithSlash() throws URISyntaxException {
371372
ClickHouseNode server = ClickHouseNode.of("http://localhost?a=/b/c/d");
372373
Assert.assertEquals(server.getDatabase().orElse(null), null);
373374
Assert.assertEquals(server.getOptions(), Collections.singletonMap("a", "/b/c/d"));

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodesTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import java.util.Optional;
88
import java.util.Properties;
99
import java.util.TreeMap;
10+
import java.util.concurrent.ExecutionException;
1011
import java.util.concurrent.ScheduledFuture;
1112
import java.util.concurrent.TimeUnit;
13+
import java.util.concurrent.TimeoutException;
1214

1315
import com.clickhouse.client.ClickHouseNode.Status;
1416
import com.clickhouse.client.config.ClickHouseClientOption;
@@ -185,7 +187,7 @@ public void testGetNodes() {
185187
}
186188

187189
@Test(groups = { "unit" })
188-
public void testNodeGrouping() throws Exception {
190+
public void testNodeGrouping() throws ExecutionException, InterruptedException, TimeoutException {
189191
ClickHouseNodes nodes = ClickHouseNodes
190192
.of("http://(a?node_group_size=1),(tcp://b?x=1)/test?x=2&node_group_size=0");
191193
Assert.assertTrue(nodes.getPolicy() == ClickHouseLoadBalancingPolicy.DEFAULT,
@@ -213,7 +215,7 @@ public void testNodeGrouping() throws Exception {
213215
}
214216

215217
@Test(groups = { "unit" })
216-
public void testQueryWithSlash() throws Exception {
218+
public void testQueryWithSlash() {
217219
ClickHouseNodes servers = ClickHouseNodes
218220
.of("https://node1?a=/b/c/d,node2/db2?/a/b/c=d,node3/db1?a=/d/c.b");
219221
Assert.assertEquals(servers.nodes.get(0).getDatabase().orElse(null), "db1");

clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseValuesTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public void testConvertToDateTime() {
142142
}
143143

144144
@Test(groups = { "unit" })
145-
public void testConvertToIpv4() throws Exception {
145+
public void testConvertToIpv4() throws UnknownHostException {
146146
Assert.assertEquals(ClickHouseValues.convertToIpv4((String) null), null);
147147
Assert.assertEquals(ClickHouseValues.convertToIpv4("127.0.0.1"), Inet4Address.getByName("127.0.0.1"));
148148
Assert.assertEquals(ClickHouseValues.convertToIpv4("0:0:0:0:0:ffff:7f00:1"),
149149
Inet4Address.getByName("127.0.0.1"));
150150
}
151151

152152
@Test(groups = { "unit" })
153-
public void testConvertToIpv6() throws Exception {
153+
public void testConvertToIpv6() throws UnknownHostException {
154154
Assert.assertEquals(ClickHouseValues.convertToIpv6((String) null), null);
155155
Assert.assertEquals(ClickHouseValues.convertToIpv6("::1"), Inet6Address.getByName("::1"));
156156
Assert.assertEquals(ClickHouseValues.convertToIpv6("127.0.0.1").getClass(), Inet6Address.class);

0 commit comments

Comments
 (0)