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] Fixes handling empty results while using reader #1845

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

chernser
Copy link
Contributor

@chernser chernser commented Sep 30, 2024

Summary

BinaryFormatReader implementation is stateful and hold current record to be accessible before calling next(). Data is provided as stream and because of this reason handling hasNext() is complex because reader should read data upfront without affect current own position to avoid skipping records.
This PR fixes detecting if no data is present in data stream.

Note

There are two cases of empty result:

  • SELECT 1 LIMIT 0 - has no result data but has column name and type
  • CREATE TABLE test - has nothing at all, so readers that expect schema before data should also handle it correctly.

Closes #1788

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

Copy link

@@ -148,11 +151,16 @@ public <T> T readValue(String colName) {

@Override
public boolean hasNext() {
if (initialState) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have no results? IE can we be sure it SHOULD always be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible to have no results: empty dataset or completely no data in a response body.
Both cases are handled. The initialState is changed once any bytes are read from input stream).

@chernser chernser changed the title fixes handling empty results while using reader [client-v2] Fixes handling empty results while using reader Oct 1, 2024
@chernser chernser merged commit 38fe7fb into main Oct 1, 2024
59 of 60 checks passed
@chernser chernser deleted the clientv2_fix_emptyresponse_error branch October 1, 2024 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[client-v2] Exception when trying to read data from an empty result GenericRecord
2 participants