clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

'Expect one SQL statement to execute but we got 3' error occurs when use ClickHouseClient.load() with custom settings

Open Ryze0827 opened this issue 2 years ago • 0 comments

Describe the bug

I want to import a csv file data to an existing table by use api ClickHouseClient.load() with custom settings 'insert_distributed_sync=1,insert_quorum=2'

Steps to reproduce

1.prepare a csv file 2.import by code below

Expected behaviour

import

Code example

    public static void importFileToTable(String table, String filePath) {
        try {
            ClickHouseClient
                    .load(createCommonServer(dataSourceProperties), table,
                            ClickHouseFormat.CSVWithNames, ClickHouseCompression.fromFileName(filePath), filePath)
                    .get();
        }
        catch (Exception e) {
            logger.error(e);
        }
    }

       private static ClickHouseNode createCommonServer(ClickHouseDataSourceProperties dataSourceProperties) {
        ClickHouseNode.Builder builder = ClickHouseNode.builder();
        String url = dataSourceProperties.getUrl();
        String clusterName = dataSourceProperties.getClusterName();
        try {
            // Remove 'jdbc:' prefix
            URI uri = new URI(url.substring(5));
            String host = uri.getHost();
            int port = uri.getPort();
            if (port == -1) {
                port = 80;
            }
            String database = uri.getPath().substring(1);

            String username = dataSourceProperties.getUsername();
            String password = dataSourceProperties.getPassword();
            builder.host(host)
                    .port(ClickHouseProtocol.HTTP, port)
                    .database(database)
                    .credentials(ClickHouseCredentials.fromUserAndPassword(username, password));
            if (StringUtils.isNotBlank(clusterName)) {
               // custom settings
                builder.cluster(clusterName)..addOption(ClickHouseClientOption.CUSTOM_SETTINGS.getKey(), "insert_distributed_sync=1,insert_quorum=2");
            }
        }
        catch (Exception e) {
            logger.error(e);
        }
        return builder.build();
    }

Error log

Caused by: java.lang.IllegalArgumentException: Expect one SQL statement to execute but we got 3 at com.clickhouse.client.http.ClickHouseHttpClient.send(ClickHouseHttpClient.java:98) ~[clickhouse-http-client-0.4.0.jar:clickhouse-http-client 0.4.0 (revision: 3a53cf1)] at com.clickhouse.client.AbstractClient.sendAsync(AbstractClient.java:158) ~[clickhouse-client-0.4.0.jar:clickhouse-client 0.4.0 (revision: 3a53cf1)] at com.clickhouse.client.AbstractClient.lambda$execute$0(AbstractClient.java:291) ~[clickhouse-client-0.4.0.jar:clickhouse-client 0.4.0 (revision: 3a53cf1)] ... 5 common frames omitted image

Configuration

Environment

  • Client version: 0.4.0
  • Language version: java8

Ryze0827 avatar Dec 12 '23 11:12 Ryze0827