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] Exception when trying to read data from an empty result GenericRecord #1788

Closed
unlimited-creative14 opened this issue Aug 25, 2024 · 3 comments · Fixed by #1845
Closed
Assignees
Milestone

Comments

@unlimited-creative14
Copy link

Describe your feedback

It should not go inside the for loop because the query return empty dataset. See my example below

Code example

        Client clickhouseV2Client = new Client.Builder()
                .addEndpoint("http://localhost:8123")
                .setDefaultDatabase("default")
                .setUsername("")
                .setPassword("")
                .build();
        CompletableFuture<Records> query = clickhouseV2Client.queryRecords("SELECT 1 LIMIT 0");
        for (GenericRecord record : query.get()) {
            System.out.println("record.c1 = " + record.getInteger(1));
        }

There are stack traces:
java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "this.currentRecord" is null
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.readValue(AbstractBinaryFormatReader.java:104) ~[client-v2-0.6.4.jar:client-v2 0.6.4 (revision: fc8d92e)]
at com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.getString(AbstractBinaryFormatReader.java:169) ~[client-v2-0.6.4.jar:client-v2 0.6.4 (revision: fc8d92e)]
at com.clickhouse.client.api.data_formats.internal.BinaryReaderBackedRecord.getString(BinaryReaderBackedRecord.java:32) ~[client-v2-0.6.4.jar:client-v2 0.6.4 (revision: fc8d92e)]

@mzitnik
Copy link
Contributor

mzitnik commented Sep 3, 2024

@unlimited-creative14 Thanks for the feedback

@chernser chernser self-assigned this Sep 3, 2024
@chernser chernser added this to the 0.7.0 milestone Sep 3, 2024
@tiagociprianopires
Copy link

This issue occurs on all query() method, including:
public CompletableFuture query(String sqlQuery, Map<String, Object> queryParams, QuerySettings settings)

This is still happening in 0.6.5

As a workaround for those who found this issue before it's fixed, check the number of records prior to iterate:

   CompletableFuture<Records> query = clickhouseV2Client.queryRecords("SELECT 1 LIMIT 0");
    Records genericRecords = query.get();
    if (genericRecords.getResultRows() > 0) {
      for (GenericRecord record : genericRecords) {
        System.out.println("record.c1 = " + record.getInteger(1));
      }
    }

@chernser
Copy link
Contributor

Thank you, @tiagociprianopires !

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.

4 participants