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

[client-v2] InsertSettings::SetDatabase not working #1868

Closed
Am-phi opened this issue Oct 16, 2024 · 1 comment · Fixed by #1869
Closed

[client-v2] InsertSettings::SetDatabase not working #1868

Am-phi opened this issue Oct 16, 2024 · 1 comment · Fixed by #1869

Comments

@Am-phi
Copy link
Contributor

Am-phi commented Oct 16, 2024

Describe the bug

According to the javadoc in the InsertSettings the option addDatabase allows to query another database than the one defined in the client. Which is not the case

Steps to reproduce

  1. Create a client with any database
  2. Create a table in another database
  3. Create an insertSetting with the option setDatabase with the database where you created your table
  4. Insert data

Expected behaviour

It's expected that the data would be inserted in the correct table

Code example

Client client = new Client.Builder()
            .addEndpoint(Protocol.HTTP, "localhost", 8123, false)
            .setUsername("default")
            .setPassword("")
            .useNewImplementation(System.getProperty("client.tests.useNewImplementation", "true").equals("true"))
            .build();
        final String tableName = "insert_settings_database_test";
        final String new_database = "new_database";
        client.query("CREATE DATABASE " + new_database);
        client.query("CREATE TABLE " + new_database + "." + tableName + " (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()");
        InsertSettings insertSettings = settings.setDatabase(new_database); ByteArrayOutputStream data = new ByteArrayOutputStream();
        PrintWriter writer = new PrintWriter(data);
        for (int i = 0; i < 1000; i++) {
            writer.printf("%d\t%s\t%s\t%d\t%s\n", i, "2021-01-01 00:00:00", "name" + i, i, "p2");
        }
        writer.flush();
        InsertResponse response = client.insert(tableName, new ByteArrayInputStream(data.toByteArray()),
            ClickHouseFormat.TSV, insertSettings).get(30, TimeUnit.SECONDS);

Error log

com.clickhouse.client.api.ServerException: Code: 60. DB::Exception: Table default.insert_settings_database_test does not exist. Maybe you meant new_database.insert_settings_database_test?. (UNKNOWN_TABLE) (version 24.9.2.42 (official build))

at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:314)
at com.clickhouse.client.api.internal.HttpAPIClientHelper.executeRequest(HttpAPIClientHelper.java:357)
at com.clickhouse.client.api.Client.lambda$insert$7(Client.java:1331)
at com.clickhouse.client.api.Client.runAsyncOperation(Client.java:1864)
at com.clickhouse.client.api.Client.insert(Client.java:1418

Configuration

Environment

  • Client version:
  • Language version:
  • OS:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants