Skip to content

Memoise the min-encoded-bytes walk and expose whether the bound is in force - #36

Merged
PedroTadim merged 3 commits into
masterfrom
update-limit
Oct 2, 2026
Merged

PedroTadim merged 3 commits into
masterfrom
update-limit

Conversation

@PedroTadim

Copy link
Copy Markdown
Member

Make sure you have checked all steps below.

Jira

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:

Commits

  • My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain Javadoc that explain what it does

PedroTadim and others added 2 commits September 21, 2026 13:25
… 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]>
@PedroTadim

Copy link
Copy Markdown
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

@PedroTadim

Copy link
Copy Markdown
Member Author

I just merged another PR with the test fix

@PedroTadim
PedroTadim merged commit a56fc2f into master Oct 2, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant