Skip to content

Respect custom format for mutation #1073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.clickhouse.client.ClickHouseClient;
import com.clickhouse.client.ClickHouseClientBuilder;
import com.clickhouse.client.ClickHouseException;
import com.clickhouse.client.ClickHouseNode;
import com.clickhouse.client.ClickHouseProtocol;
import com.clickhouse.client.ClickHouseServerForTest;
import com.clickhouse.client.ClientIntegrationTest;
import com.clickhouse.client.cli.config.ClickHouseCommandLineOption;

import java.io.IOException;

import org.testcontainers.containers.GenericContainer;
import org.testng.Assert;
import org.testng.SkipException;
Expand Down Expand Up @@ -49,19 +52,19 @@ protected ClickHouseNode getServer() {

@Test(groups = { "integration" })
@Override
public void testCustomLoad() throws Exception {
public void testCustomLoad() throws ClickHouseException {
throw new SkipException("Skip due to time out error");
}

@Test(groups = { "integration" })
@Override
public void testLoadRawData() throws Exception {
public void testLoadRawData() throws ClickHouseException, IOException {
throw new SkipException("Skip due to response summary is always empty");
}

@Test(groups = { "integration" })
@Override
public void testMultipleQueries() throws Exception {
public void testMultipleQueries() throws ClickHouseException {
// FIXME not sure if the occasional "Stream closed" exception is related to
// zeroturnaround/zt-exec#30 or not
/*
Expand Down
2 changes: 1 addition & 1 deletion clickhouse-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</executions>
<configuration>
<excludes>
<exclude>META-INF/services</exclude>
<exclude>META-INF/services/*</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public static class Mutation extends ClickHouseRequest<Mutation> {
protected Mutation(ClickHouseRequest<?> request, boolean sealed) {
super(request.getClient(), request.server, request.serverRef, request.options, sealed);

// use headless format if possible
if (!sealed) {
format(request.getFormat().defaultInputFormat());
}

this.settings.putAll(request.settings);
this.txRef.set(request.txRef.get());

Expand Down Expand Up @@ -117,8 +122,7 @@ protected String getQuery() {
}

return builder.length() > 0 && index == len ? sql
: new StringBuilder().append(sql).append("\n FORMAT ").append(getInputFormat().name())
.toString();
: new StringBuilder().append(sql).append("\n FORMAT ").append(getFormat().name()).toString();
}

return super.getQuery();
Expand Down Expand Up @@ -239,6 +243,11 @@ public Mutation data(ClickHouseDeferredValue<ClickHouseInputStream> input) {
return this;
}

@Override
public ClickHouseFormat getInputFormat() {
return getFormat();
}

@Override
public CompletableFuture<ClickHouseResponse> execute() {
if (writer != null) {
Expand Down Expand Up @@ -646,7 +655,10 @@ public ClickHouseFormat getFormat() {
* Gets data format used for input(e.g. writing data into server).
*
* @return data format for input
* @deprecated will be removed in v0.3.3, please use
* {@code getFormat().defaultInputFormat()} instead
*/
@Deprecated
public ClickHouseFormat getInputFormat() {
return getFormat().defaultInputFormat();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

import com.clickhouse.client.ClickHouseRequest.Mutation;

public class ClickHouseClientTest {
@Test(groups = { "unit" })
public void testGetAsyncRequestOutputStream() throws Exception {
public void testGetAsyncRequestOutputStream() throws IOException {
ClickHouseConfig config = new ClickHouseConfig();
for (int i = 0; i < 256; i++) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
Expand All @@ -21,7 +23,7 @@ public void testGetAsyncRequestOutputStream() throws Exception {
}

@Test(groups = { "unit" })
public void testGetRequestOutputStream() throws Exception {
public void testGetRequestOutputStream() throws IOException {
ClickHouseConfig config = new ClickHouseConfig();
for (int i = 0; i < 256; i++) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
Expand All @@ -33,7 +35,7 @@ public void testGetRequestOutputStream() throws Exception {
}

@Test(groups = { "unit" })
public void testQuery() throws Exception {
public void testQuery() throws ExecutionException, InterruptedException {
ClickHouseClient client = ClickHouseClient.builder().build();
Assert.assertNotNull(client);
ClickHouseRequest<?> req = client.connect(ClickHouseNode.builder().build());
Expand All @@ -48,7 +50,7 @@ public void testQuery() throws Exception {
}

@Test(groups = { "unit" })
public void testMutation() throws Exception {
public void testMutation() throws ExecutionException, InterruptedException {
ClickHouseClient client = ClickHouseClient.builder().build();
Assert.assertNotNull(client);
Mutation req = client.connect(ClickHouseNode.builder().build()).write();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private Object[][] getNodeSelectors() {
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testGetNode(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testGetNode(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testReadNestedColumn() {
}

@Test(groups = { "unit" })
public void testParse() throws Exception {
public void testParse() {
ClickHouseColumn column = ClickHouseColumn.of("arr", "Nullable(Array(Nullable(UInt8))");
Assert.assertNotNull(column);

Expand All @@ -156,7 +156,7 @@ public void testParse() throws Exception {
}

@Test(groups = { "unit" })
public void testAggregationFunction() throws Exception {
public void testAggregationFunction() {
ClickHouseColumn column = ClickHouseColumn.of("aggFunc", "AggregateFunction(groupBitmap, UInt32)");
Assert.assertTrue(column.isAggregateFunction());
Assert.assertEquals(column.getDataType(), ClickHouseDataType.AggregateFunction);
Expand All @@ -178,7 +178,7 @@ public void testAggregationFunction() throws Exception {
}

@Test(groups = { "unit" })
public void testArray() throws Exception {
public void testArray() {
ClickHouseColumn column = ClickHouseColumn.of("arr",
"Array(Array(Array(Array(Array(Map(LowCardinality(String), Tuple(Array(UInt8),LowCardinality(String))))))))");
Assert.assertTrue(column.isArray());
Expand All @@ -204,7 +204,7 @@ public void testArray() throws Exception {
}

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

@Test(groups = { "unit" })
public void testSimpleAggregationFunction() throws Exception {
public void testSimpleAggregationFunction() {
ClickHouseColumn c = ClickHouseColumn.of("a", "SimpleAggregateFunction(max, UInt64)");
Assert.assertEquals(c.getDataType(), ClickHouseDataType.SimpleAggregateFunction);
Assert.assertEquals(c.getNestedColumns().get(0).getDataType(), ClickHouseDataType.UInt64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testDefaultValues() {
}

@Test(groups = { "unit" })
public void testCustomValues() throws Exception {
public void testCustomValues() {
String clientName = "test client";
String cluster = "test cluster";
String database = "test_database";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.clickhouse.client;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import org.testng.Assert;
import org.testng.annotations.Test;

public class ClickHouseDataStreamFactoryTest {
@Test(groups = { "unit" })
public void testGetInstance() throws Exception {
public void testGetInstance() {
Assert.assertNotNull(ClickHouseDataStreamFactory.getInstance());
}

@Test(groups = { "unit" })
public void testCreatePipedOutputStream() throws Exception {
public void testCreatePipedOutputStream() throws ExecutionException, IOException, InterruptedException {
ClickHouseConfig config = new ClickHouseConfig();

// read in worker thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testGetOrCreate() {
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testDummy(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down Expand Up @@ -130,7 +130,7 @@ public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down Expand Up @@ -238,7 +238,7 @@ public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) thro
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception
}

@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
public void testRandom(ClickHouseNodeSelector nodeSelector) throws Exception {
public void testRandom(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.testng.annotations.Test;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -367,7 +368,7 @@ public void testCaseInsensitiveEnumValue() {
}

@Test(groups = { "unit" })
public void testQueryWithSlash() throws Exception {
public void testQueryWithSlash() throws URISyntaxException {
ClickHouseNode server = ClickHouseNode.of("http://localhost?a=/b/c/d");
Assert.assertEquals(server.getDatabase().orElse(null), null);
Assert.assertEquals(server.getOptions(), Collections.singletonMap("a", "/b/c/d"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import java.util.Optional;
import java.util.Properties;
import java.util.TreeMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.clickhouse.client.ClickHouseNode.Status;
import com.clickhouse.client.config.ClickHouseClientOption;
Expand Down Expand Up @@ -185,7 +187,7 @@ public void testGetNodes() {
}

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

@Test(groups = { "unit" })
public void testQueryWithSlash() throws Exception {
public void testQueryWithSlash() {
ClickHouseNodes servers = ClickHouseNodes
.of("https://node1?a=/b/c/d,node2/db2?/a/b/c=d,node3/db1?a=/d/c.b");
Assert.assertEquals(servers.nodes.get(0).getDatabase().orElse(null), "db1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ public void testConvertToDateTime() {
}

@Test(groups = { "unit" })
public void testConvertToIpv4() throws Exception {
public void testConvertToIpv4() throws UnknownHostException {
Assert.assertEquals(ClickHouseValues.convertToIpv4((String) null), null);
Assert.assertEquals(ClickHouseValues.convertToIpv4("127.0.0.1"), Inet4Address.getByName("127.0.0.1"));
Assert.assertEquals(ClickHouseValues.convertToIpv4("0:0:0:0:0:ffff:7f00:1"),
Inet4Address.getByName("127.0.0.1"));
}

@Test(groups = { "unit" })
public void testConvertToIpv6() throws Exception {
public void testConvertToIpv6() throws UnknownHostException {
Assert.assertEquals(ClickHouseValues.convertToIpv6((String) null), null);
Assert.assertEquals(ClickHouseValues.convertToIpv6("::1"), Inet6Address.getByName("::1"));
Assert.assertEquals(ClickHouseValues.convertToIpv6("127.0.0.1").getClass(), Inet6Address.class);
Expand Down
Loading