Skip to content
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

addBatch / executeBatch does not support on cluster anymore #1261

Closed
den-crane opened this issue Feb 28, 2023 · 3 comments · Fixed by #1293
Closed

addBatch / executeBatch does not support on cluster anymore #1261

den-crane opened this issue Feb 28, 2023 · 3 comments · Fixed by #1293
Labels
Milestone

Comments

@den-crane
Copy link
Collaborator

den-crane commented Feb 28, 2023

final String DB_URL = "jdbc:clickhouse://localhost:8123";
final String USER = "default"
final String PASS = "";

ClickHouseDataSource dataSource = new ClickHouseDataSource(DB_URL);
ClickHouseConnection conn = dataSource.getConnection(USER, PASS);
ClickHouseStatement s =  conn.createStatement();

s.addBatch("drop table if exists aaa on cluster test_shard_localhost");
s.addBatch("create table if not exists aaa on cluster test_shard_localhost(a Int64) Engine=MergeTree order by a ;drop table if exists aaa on cluster test_shard_localhost;");
int[] results = s.executeBatch();
for (int i: results ) {
    System.out.print(i);
}
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.1</version>

import ru.yandex.clickhouse.ClickHouseConnection;
import ru.yandex.clickhouse.ClickHouseDataSource;
import ru.yandex.clickhouse.ClickHouseStatement;


output: 111
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.4.0</version>

import com.clickhouse.jdbc.ClickHouseConnection;
import com.clickhouse.jdbc.ClickHouseDataSource;
import com.clickhouse.jdbc.ClickHouseStatement;

Exception in thread "main" java.sql.BatchUpdateException: Query is not allowed in batch update

without on cluster test_shard_localhost -- it works / output: 000

@den-crane den-crane added the bug label Feb 28, 2023
@sondertara
Copy link

sondertara commented Mar 6, 2023

The version 0.4.1 still has this situation, in the package com.clickhouse.jdbc.internal all PreparedStatement implementations have similar code in the method executeAny :

      try {
                r = executeStatement(builder.toString(), null, null, null);
                if (updateResult(parsedStmt, r) != null && asBatch) {
                    throw SqlExceptionUtils.queryInBatchError(results);
                }
               ...
              
            } catch (Exception e) {
                ...
                if (!continueOnError) {
                    throw SqlExceptionUtils.batchUpdateError(e, results);
                }
                log.error("Failed to execute batch insertion of %d records", counter, e);
            } finally {
                if (asBatch && r != null) 
                    r.close();
                }
                clearBatch();
            }

When sql with on cluster , the updateResult always return response columns, we can add property (continueOnError =true ) to the jdbc connection make it continue.

But I still want to know if this is a bug, or some kind of specification or practice, who can tell me the specific design details?

@zhicwu
Copy link
Contributor

zhicwu commented Mar 6, 2023

But I still want to know if this is a bug, or some kind of specification or practice, who can tell me the specific design details?

Yes it's a bug. The assumption was DDL should have empty response, which is apparently not true when on cluster was used.

@zhicwu zhicwu added this to the 0.4.2 release milestone Mar 6, 2023
@sondertara
Copy link

@zhicwu Thank you for your prompt reply and looking forward to the v1 release. 🧋🧋

@zhicwu zhicwu linked a pull request Mar 21, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants