Repository navigation
Memoise the min-encoded-bytes walk and expose whether the bound is in force - #36
Merged
Merged
Conversation
… force Two defects in c488095, both reported on ClickHouse/ClickHouse#121211. The walk had no memoisation. A schema is a DAG: one field can inline a type that another field names, so both arms reach the same node and the work doubles per level. It runs from readHeader(), i.e. in the reader's constructor, before a caller can reject the file for any other reason. On a schema that names each next level twice, reader construction took 0.028 / 0.109 / 0.437 / 1.75 / 28.3 s at depth 20 / 22 / 24 / 26 / 30. It is now 0.2 ms at each of those, and at depth 40. Memoising by resolved node identity, with the on-path set as a cycle guard, also removes the need for the depth cap - and that cap was the second defect. Past 64 levels the walk returned 0, which disables checkObjectCountFitsPayload entirely. A 10-object snappy file with a second block declaring 10^9 objects over the same payload was rejected at depth 60 and 64 but accepted at 65 and 80; all four are rejected now. ClickHouse allows schemas up to 256 levels, so this was reachable. Zero is still returned wherever no usable bound can be derived, but it is no longer the caller's only signal: checksDeclaredObjectCount reports whether this reader cross-checks a block's declared object count at all. A caller answering a row count from block headers alone needs exactly that, and cannot derive it - a bound recomputed outside the library can be positive where this one is zero, and the codec string is a different condition. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The test declared a six-long record and then wrote a single uint32_t through it, so the header promised at least six bytes per record over a four-byte payload. Since #34 the reader cross-checks a block's declared object count against the payload it carries, and rejects that file: Object count 1 in block header cannot fit in 4 payload byte(s) for this schema Rejecting it is the check working - the file is internally inconsistent - so fix the test rather than the check. Write a conforming record through the Pair/GenericRecord idiom the rest of the file already uses. All six doc assertions, which are what the test is for, are unchanged. Bisected by running this suite in isolation: it passes at 7b7f6a5 and at f2d65e1 (#33) and fails from 57985a1 (#34) on. Isolation was needed because boost aborts the run at the first fatal error, and an unrelated test0/testWrite segfault on those older commits - fixed since - hides this one. DataFileTests is now 69/69. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Member
Author
|
This PR is needed to continue ClickHouse/ClickHouse#121211 @alexey-milovidov #34 broke a test and this PR has the fix. Someone should review quickly |
Member
Author
|
I just merged another PR with the test fix |
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Oct 2, 2026
Moves the pin from the ClickHouse/avro#39 commit to the current master (merge of ClickHouse/avro#36). Besides ClickHouse#39 (already pinned), this brings in ClickHouse#34 (bound the declared object count by a schema-derived minimum record size), ClickHouse#36 (memoise that walk, so it terminates on recursive schemas) and ClickHouse#37 (test fix). Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai
added a commit
to groeneai/ClickHouse
that referenced
this pull request
Oct 3, 2026
ClickHouse/avro#36 memoises the minimum-encoded-size walk instead of cutting it at 64 levels, and adds `checksDeclaredObjectCount`, which is true only when every block's declared count is checked against a decoded payload size: snappy, with a schema whose records cannot encode to zero bytes. `supportsCountRows` now asks that instead of comparing the codec name, so the condition lives next to the check it depends on. On the previous pin, a snappy file whose schema nests more than 64 records and whose block declares 10^9 objects in 8 bytes counted 1000000010 with optimize_count_from_files = 1; it is now rejected at the block header with both settings. The test gains that case at depth 65. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Make sure you have checked all steps below.
Jira
Tests
Commits
Documentation