Repository navigation
Read the Parquet metadata of ParquetMetadata and Hive without parquet-cpp - #131763
alexey-milovidov wants to merge 13 commits into
Conversation
…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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [e9c876d] Summary: ❌
AI ReviewSummaryThe PR replaces parquet-cpp footer reads for Missing context / blind spots
Final VerdictStatus: ✅ Approve |
…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]>
… `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]>
…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]>
Build profile diff (arm_release)Comparing 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%) |
…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
left a comment
There was a problem hiding this comment.
This is good.
…thout-arrow # Conflicts: # src/Processors/Formats/Impl/Parquet/Prefetcher.cpp
Part of removing the Apache Arrow C++ library and parquet-cpp: the
ParquetMetadataformat and the min/max index of Parquet files in theHiveengine read the footer with the Thrift structures of the native Parquet reader instead of parquet-cpp.The new
Parquet::FooterMetadatapresents the footer the way parquet-cpp did, so the output ofParquetMetadatastays the same: the leaf columns with their levels and logical types (LogicalType::ToStringspelling, including types derived from converted types), the compression names (ParquetLZ4_RAWis shown asLZ4and the deprecatedLZ4asLZ4_HADOOP, as before),metadata_sizeas the size of the serializedFileMetaData, 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 JSONEachRowof a build of master and of this branch over all 378 Parquet files ofcontrib/parquet-testing,contrib/arrow-testingandtests/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 useParquetMetadatapass 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.HiveFileuses the same statistics with the same rules, so the row groups it skips do not change. As before,DOUBLEcolumns are not used for the index: parquet-cpp's statistics were cast to theFloatstatistics type twice, so they never matched.ENABLE_HIVEno longer needs the Arrow library.test_hive_queryis skipped on ARM, so it only ran in CI.Malformed footers. Added during the review:
thriftEnumToInt), and negative or inconsistent counts in the statistics of a column chunk are rejected withINCORRECT_DATAinstead of overflowing.parquet.thriftis compiled from a copy whose enums have the fixed underlying typeint32_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 nativeParquetreader uses the same generated code, so this covers it too. Every target that exposes the Arrow source directory sees the rewritten headers first.Tests:
05839_parquet_metadata_invalid_schema_enums,05840_parquet_metadata_invalid_counts,05857_parquet_invalid_type_many_columns.Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/131763]