Skip to content

Read the Parquet metadata of ParquetMetadata and Hive without parquet-cpp - #131763

Open
alexey-milovidov wants to merge 13 commits into
masterfrom
parquet-metadata-without-arrow
Open

alexey-milovidov wants to merge 13 commits into
masterfrom
parquet-metadata-without-arrow

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Part of removing the Apache Arrow C++ library and parquet-cpp: the ParquetMetadata format and the min/max index of Parquet files in the Hive engine read the footer with the Thrift structures of the native Parquet reader instead of parquet-cpp.

The new Parquet::FooterMetadata presents the footer the way parquet-cpp did, so the output of ParquetMetadata stays the same: the leaf columns with their levels and logical types (LogicalType::ToString spelling, including types derived from converted types), the compression names (Parquet LZ4_RAW is shown as LZ4 and the deprecated LZ4 as LZ4_HADOOP, as before), metadata_size as the size of the serialized FileMetaData, and column chunk statistics trusted only as far as parquet-cpp trusted them: by column order, sort order and writer version (created_by, PARQUET-251 and the parquet-mr/parquet-cpp versions with incorrect statistics).

Checked by comparing SELECT * FROM file(..., ParquetMetadata) FORMAT JSONEachRow of a build of master and of this branch over all 378 Parquet files of contrib/parquet-testing, contrib/arrow-testing and tests/queries/0_stateless/data_parquet*: the output of all 372 readable files is identical, and the same 6 files fail with both. The stateless tests that use ParquetMetadata pass locally (except the ones needing S3/Azure, which do not run in my environment).

One intended difference: encodings are always named as in the Parquet format, so the deprecated GROUP_VAR_INT (1) is no longer shown as an empty string.

HiveFile uses the same statistics with the same rules, so the row groups it skips do not change. As before, DOUBLE columns are not used for the index: parquet-cpp's statistics were cast to the Float statistics type twice, so they never matched. ENABLE_HIVE no longer needs the Arrow library. test_hive_query is skipped on ARM, so it only ran in CI.

Malformed footers. Added during the review:

  • The enums of the footer are read as integers and validated before they are used (thriftEnumToInt), and negative or inconsistent counts in the statistics of a column chunk are rejected with INCORRECT_DATA instead of overflowing.
  • The Thrift code generated from parquet.thrift is compiled from a copy whose enums have the fixed underlying type int32_t, the type of a Thrift enum on the wire (contrib/arrow-cmake). A corrupted file can store any integer in an enum field, and the generated reader loads it before anything can validate it (e.g. when the vector of the schema elements grows past 1024 and moves them), which was undefined behavior. The native Parquet reader uses the same generated code, so this covers it too. Every target that exposes the Arrow source directory sees the rewritten headers first.
  • Reading a non-seekable input into memory stops when the query is cancelled, as it did with the previous reader.

Tests: 05839_parquet_metadata_invalid_schema_enums, 05840_parquet_metadata_invalid_counts, 05857_parquet_invalid_type_many_columns.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131763]

alexey-milovidov and others added 2 commits November 15, 2026 01:11
…quet-cpp

The `ParquetMetadata` format and the min/max index of Parquet files in the `Hive`
engine were the last users of parquet-cpp besides Arrow Flight, Vortex and Delta
Lake. Add `Parquet::FooterMetadata`, which reads the footer with the Thrift
structures of the native reader and presents it as parquet-cpp did: the leaf
columns with their levels and logical types, and the column chunk statistics,
trusted only as far as parquet-cpp trusted them (by column order, sort order
and writer version). Both now use it, and `ENABLE_HIVE` no longer needs the
Arrow library.

The encodings of a column are now always named as in the Parquet format, so the
deprecated `GROUP_VAR_INT` is no longer shown as an empty string.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e9c876d]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 3/6) FAIL Performance dashboard
utf8_ascii_prefix #0 FAIL dashboard
utf8_ascii_prefix #1 FAIL dashboard
utf8_ascii_prefix #2 FAIL dashboard
Performance Comparison (amd_release, master_head, 4/6) FAIL Performance dashboard
utf8_ascii_tails #1 FAIL dashboard
utf8_ascii_tails #3 FAIL dashboard
utf8_ascii_tails #5 FAIL dashboard
utf8_ascii_tails #6 FAIL dashboard

AI Review

Summary

The PR replaces parquet-cpp footer reads for ParquetMetadata and Hive with Parquet::FooterMetadata, preserving metadata presentation and statistics trust rules while removing their Arrow dependency. Reviewed head e9c876d5b4a402e06064d37a93b68b7e31a7c789, the current code, the diff, and all prior discussion. No remaining actionable findings; the previously reported issues are addressed. No new inline comments were posted.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary is available. Runtime evidence comes from the author's reported comparison of 372 readable files and the current-head Praktika reports, which report no failures and passing 05840_parquet_metadata_invalid_counts and 05857_parquet_invalid_type_many_columns cases in Fast test. Full sanitizer and Hive execution were not independently reproduced; their CI results would close that validation gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. labels Nov 15, 2026
Comment thread src/Storages/Hive/HiveFile.cpp Resolved
alexey-milovidov and others added 3 commits November 21, 2026 00:38
…thout-arrow

Conflicts in `ParquetMetadataInputFormat.cpp`: master added a schema depth check and a
lookup of unknown encodings for the parquet-cpp reader of the `ParquetMetadata` format,
which this branch replaces with `Parquet::FooterMetadata`. The parquet-cpp code is dropped,
and the encodings and the compression codec are read with `thriftEnumToInt`, as on master.
The schema depth limit is added to `FooterMetadata` in the next commit.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… index

Address review: `hyperrectangle` was sized by the number of leaf columns of the file but
indexed by the position in `index_names_and_types`, the non-partition columns of the table.
A table with more columns than the file, e.g. `(missing Int32, present Int32)` over a file
with only `present`, wrote past the end of the vector. Columns that the file does not have
stay unconstrained. The defect predates this pull request.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ata`

Address review:

- The schema walker recursed once per nested group with no limit, so a footer with a long
  chain of `REQUIRED` groups could exhaust the stack. It now has the limit of the native
  Parquet reader (`max_parser_depth`, 0 means unlimited) with `checkStackSize` as the
  backstop, and keeps one path for the whole walk instead of a copy at every level. This
  replaces the check that master added for the parquet-cpp reader, which needed a hard
  ceiling because the recursion inside parquet-cpp could not be guarded;
  `05773_parquet_metadata_schema_depth` is updated accordingly.
- The enums of the footer (physical, repetition and converted types, the type of a column
  chunk, the compression codec, the edge interpolation algorithm) are read with
  `thriftEnumToInt` before they are validated: loading a value out of the range of the
  enum, which a malformed file can have, is undefined behavior.

Also fix the clang-tidy errors of the arm_tidy build, including `modernize-use-nodiscard`
that was enabled on master in the meantime:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131763&sha=1c7c3dbc5321ed44a13b435bf963e32c71812ffa&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29
#131763

Co-Authored-By: Claude Fable 5.2 <[email protected]>
alexey-milovidov and others added 2 commits November 22, 2026 20:06
… `FooterMetadata`

`num_values` and `statistics.null_count` come from the file: a negative number of
values, or a null count out of [0, num_values], is now `INCORRECT_DATA` instead of
an overflowing subtraction (e.g. `1 - INT64_MIN`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits November 22, 2026 21:10
…g type

A corrupted footer may store any integer in an enum field such as `SchemaElement.type`. For an enum without a fixed
underlying type, a value outside its range is undefined behavior as soon as it is loaded, and the generated code loads
it before the reader can validate it: `FileMetaData::read` reserves 1024 schema elements, so appending more moves the
elements already read through the generated move constructor. This affects `ParquetMetadata` and the native
`Parquet` reader alike.

The generated sources are now copied into the build directory with `enum type : int32_t`, the type of a Thrift enum on
the wire, so every value is valid. CMake fails if an enum is left without it. Test
`05857_parquet_invalid_type_many_columns` reads a footer with 1100 columns and an invalid type of the first one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…` when the query is cancelled

When the input is not seekable, the whole file is read into memory before the footer. `ParquetMetadataInputFormat`
sets a flag in `onCancel` again, and `Prefetcher::init` hands an optional flag to `copyData`, which stops between
buffers. `FooterMetadata::read` with a flag returns `std::nullopt` when cancelled, and the format returns an empty
chunk, as before this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ParquetMetadata` shows an invalid physical type of a column as it is, like the parquet-cpp based implementation
did (see `05839_parquet_metadata_invalid_schema_enums`); only the `Parquet` reader rejects it.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=131763&sha=212ed646f3d71a4c354e0e9121cf191855cda94e&name_0=PR
PR: #131763

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread contrib/arrow-cmake/CMakeLists.txt Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e9c876d5b with master 127ab3ce4 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of c93b9302b; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: binary sizes, object file sizes.

Binary sizes ⚠️
Binary Master PR Δ
programs/clickhouse-stripped 812.64 MiB 802.28 MiB -10.36 MiB (-1.27%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

14 object files changed (+741.16 KiB total), 2 added.

Object file Master PR Δ
contrib/arrow-cmake/CMakeFiles/_parquet_format.dir/parquet_format_include/generated/parquet_types.c… new 614.03 KiB +614.03 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/FooterMetadata.cpp.o new 214.52 KiB +214.52 KiB
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ParquetMetadataInputFormat.cpp.o 409.01 KiB 339.76 KiB -69.25 KiB (-16.93%)
src/CMakeFiles/dbms.dir/Storages/Hive/HiveFile.cpp.o 185.40 KiB 166.24 KiB -19.16 KiB (-10.33%)

717 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

90 translation units recompiled, 486 s compile time in total, 88 of them have a recent master baseline.

Symbol sizes
Binary Symbol Master PR Δ
programs/clickhouse arrow::compute::internal::GetNumericCasts() 124.21 KiB removed -124.21 KiB (-100.00%)

Job report

…larations

`_arrow`, `_parquet` and `_arrow_ipc_metadata` expose the Arrow source directory, which has the original
`generated/parquet_types.h`. Each of them now puts the copy with the fixed underlying types of the enums first, so that
no translation unit sees the other declaration (an ODR violation), whatever the order in which a consumer links them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 23, 2026
…thout-arrow

# Conflicts:
#	src/Processors/Formats/Impl/Parquet/Prefetcher.cpp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant