Conversation
ClickHouse precedes the data blocks of a SELECT with a single schema-only header block (columns present, zero rows). `stream_blocks()` skips this first block because for non-empty results the subsequent data blocks already carry the full column schema. However, when the result set is empty (e.g. a SELECT over an empty table) the header is the *only* block sent, so skipping it made the stream yield nothing and callers lost all column information. `fetch_all()` was unaffected because it does not skip the first block. Buffer the header block instead of discarding it and flush it on EOF when no data block ever arrived. Empty results now expose their columns while non-empty results keep their existing behaviour. Fixes suharev7#222
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #222.
Problem
For a
SELECTover an empty table,QueryResult::stream_blocks()yields no blocks at all, so callers lose all column/schema information.fetch_all()is unaffected.Root cause
ClickHouse precedes a query's data blocks with a single schema-only header block (columns present,
num_rows == 0).stream_blocks()deliberately skips this first block (viablock_index > 1) because for non-empty results the following data blocks already carry the full schema, so the empty header would just be noise.When the result set is empty, however, the header is the only block the server sends before EOF. Skipping it leaves the stream empty and the caller has no way to learn the columns/types. (
fetch_all()avoids this because it drives the internal stream withskip_first_block = false.)Fix
Buffer the header block instead of discarding it:
Testing
Added
test_empty_select_stream_blocks, which streamsSELECT 1 AS a WHERE 1 <> 1and asserts a single 1-column, 0-row block is produced. Confirmed it fails before this change and passes after.Verified against a local
clickhouse-server; the new test and the existing streaming/empty-select tests pass, with no regressions introduced by this change.