You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2025/10/02 13:14:05 UTC
[PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
alamb opened a new pull request, #711:
URL: https://github.com/apache/arrow-site/pull/711
Part of the work to write a new metadata parser in Rust is to tell people about it:
- Part of https://github.com/apache/arrow-rs/issues/5854
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3407824475
Now we just need to implement the metadata index and parse the footer in parallel :rofl:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #711:
URL: https://github.com/apache/arrow-site/pull/711
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2440679988
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "3x-8x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly three times as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 3× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+parsed than are necessary. As discussed above, given the
+variable encoding used for the metadata, all metadata bytes must still be
+fetched and scanned; however, CPUs are (very) fast at scanning data, and
+skipping *parsing* of unneeded fields speeds up overall metadata performance
+significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of generated code, opportunities for specializing
+the behavior of generated Thrift parsers is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is very stable (hard to change), which is important for easy maintenance when a large number
Review Comment:
Added in 7621a3e44e5
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2417785914
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -1,8 +1,8 @@
---
layout: post
-title: "Reading Parquet Metadata in Rust got 2x faster"
+title: "Speeding up Parquet Metadata Parsing in Rust with a custom Thrift Parser"
date: "2025-10-08 00:00:00"
-author: "Andrew Lamb and Ed Seidl"
+author: "Andrew Lamb (InfluxData) and Ed Seidl (LLNL)"
Review Comment:
perfect -- I will remove your name and instead talk about all the great work you did in the implementation section 🚀
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3403316201
This post is now ready for review
You can see a rendered preview here (thanks @kou!): https://alamb.github.io/arrow-site/blog/2025/10/08/rust-parquet-metadata/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2420741449
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
-The custom parser is optimized for the specific subset of the Thrift format used
-by Parquet, and by using various performance optimizations
-### Example optimizations
-The obvious optimization is to remove the intermediate step of creating
-the in-memory structures generated by the thrift crate, and instead parse
-the thrift binary directly into arrow's own in-memory representation of parquet metadata.
+## New Design: Custom Thrift Parser
-However, there are other optimizations that can now be applied such as: (TODO GET LIST)
+As is typical of code generated from another tool, opportunities for
+optimization in the code generated by the thrift compilers are typically
+limited. This is because
+1. The generated is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
+2. The generated code must be general purpose, and easy to embed, and typically has
+ generates structures with a one to one mapping of the thrift definitions,
+ which limits adding additional optimizations such as zero copy parsing, or
+ amortized memory allocation strategies.
+3. The thrift compilers are quite stable, which is important to enable embedding
+ generated code. For example, the [last release of the Rust `thrift` crate]
+ was almost three years ago.
-### Maintainability
-THe largest concern with this approach is that it is more difficult to maintain, as any changes to the parquet
-format must be manually reflected in the custom parser, and the thrift definitions
-do get updated (e.g. for the recent additions of [Geometry] and [Variant] tyoes)
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
-However, one of the arrow-rs contributors, Jorn Horstmann (todo link) prototyped a macro
-based approach, that generates the custom parser code using rust macros so that the
-rust structures look very similar to the original thrift definitions.
+Thus, we concluded that we needed a custom thrift parser that could be optimized
+for the specific subset of the Thrift format used by Parquet.
+So we instead wrote a custom parser that parses the thrift binary directly into the needed
+structures as shown in the figure below.
-For exmaple, here is the thrift definition of a parquet file metadata:
-(TOD)O
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
+own in-memory representation of parquet metadata.
+
+The custom parser is optimized for the specific subset of the Thrift format used
+by Parquet, and by using various performance optimizations, such as careful memory
+allocation and avoiding unnecessary copies.
-And the corresponding Rust structure that is created directly from the custom parser:
+The largest initial speedup came from removing the intermediate in-memory
+structures, and instead simply created the needed in-memory representation of
+parquet metadata. We also carefully hand optimized certain thrift decoding and
+memory allocation paths.
-(TODO example
-)
+### Maintainability
+
+THe largest concern with this approach is that it is more difficult to maintain, as any changes to the [`parquet.thrift`] file
+must be manually reflected in the custom parser, and the thrift definitions
+do get updated regularly (e.g. for the recent additions of [Geospatial] and [Variant] types)
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+However, [Jörn Horstmann] prototyped a [Rust macro
+based approach] that generates parsing code for annotated Rust structs
+that closely resemble the thrift definitions. Structs that need additional optimization
+can be manually implemented. This approach is similar to how the [serde] crate
+generates serialization and deserialization code for Rust structs.
+
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+<!-- https://x.com/jhorstmann23/status/1803426667748053448-->
+
+For example, here is the thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here is the corresponding Rust structure annotated with the custom thrift parsing macros:
+
+https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This organization makes it easy to see the correspondence between the thrift definition
+and the Rust structure, and makes it easy to update the Rust structure when the
+thrift definition changes.
Review Comment:
This is a great point -- I tried to incorporate it more
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
-The custom parser is optimized for the specific subset of the Thrift format used
-by Parquet, and by using various performance optimizations
-### Example optimizations
-The obvious optimization is to remove the intermediate step of creating
-the in-memory structures generated by the thrift crate, and instead parse
-the thrift binary directly into arrow's own in-memory representation of parquet metadata.
+## New Design: Custom Thrift Parser
-However, there are other optimizations that can now be applied such as: (TODO GET LIST)
+As is typical of code generated from another tool, opportunities for
+optimization in the code generated by the thrift compilers are typically
+limited. This is because
+1. The generated is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
+2. The generated code must be general purpose, and easy to embed, and typically has
+ generates structures with a one to one mapping of the thrift definitions,
+ which limits adding additional optimizations such as zero copy parsing, or
+ amortized memory allocation strategies.
+3. The thrift compilers are quite stable, which is important to enable embedding
+ generated code. For example, the [last release of the Rust `thrift` crate]
+ was almost three years ago.
-### Maintainability
-THe largest concern with this approach is that it is more difficult to maintain, as any changes to the parquet
-format must be manually reflected in the custom parser, and the thrift definitions
-do get updated (e.g. for the recent additions of [Geometry] and [Variant] tyoes)
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
-However, one of the arrow-rs contributors, Jorn Horstmann (todo link) prototyped a macro
-based approach, that generates the custom parser code using rust macros so that the
-rust structures look very similar to the original thrift definitions.
+Thus, we concluded that we needed a custom thrift parser that could be optimized
+for the specific subset of the Thrift format used by Parquet.
+So we instead wrote a custom parser that parses the thrift binary directly into the needed
+structures as shown in the figure below.
-For exmaple, here is the thrift definition of a parquet file metadata:
-(TOD)O
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
+own in-memory representation of parquet metadata.
+
+The custom parser is optimized for the specific subset of the Thrift format used
+by Parquet, and by using various performance optimizations, such as careful memory
+allocation and avoiding unnecessary copies.
-And the corresponding Rust structure that is created directly from the custom parser:
+The largest initial speedup came from removing the intermediate in-memory
+structures, and instead simply created the needed in-memory representation of
+parquet metadata. We also carefully hand optimized certain thrift decoding and
+memory allocation paths.
-(TODO example
-)
+### Maintainability
+
+THe largest concern with this approach is that it is more difficult to maintain, as any changes to the [`parquet.thrift`] file
+must be manually reflected in the custom parser, and the thrift definitions
+do get updated regularly (e.g. for the recent additions of [Geospatial] and [Variant] types)
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+However, [Jörn Horstmann] prototyped a [Rust macro
+based approach] that generates parsing code for annotated Rust structs
+that closely resemble the thrift definitions. Structs that need additional optimization
+can be manually implemented. This approach is similar to how the [serde] crate
+generates serialization and deserialization code for Rust structs.
+
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+<!-- https://x.com/jhorstmann23/status/1803426667748053448-->
+
+For example, here is the thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here is the corresponding Rust structure annotated with the custom thrift parsing macros:
+
+https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This organization makes it easy to see the correspondence between the thrift definition
+and the Rust structure, and makes it easy to update the Rust structure when the
+thrift definition changes.
Review Comment:
This is a great point -- I tried to incorporate it in the latest round of edits
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3391890059
I'm unable to access the "preview" link; the bot comment suggests that @alamb needs to enable some setting on his fork?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "jhorstmann (via GitHub)" <gi...@apache.org>.
jhorstmann commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2433918270
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "3x-8x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly three times as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 3× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+parsed than are necessary. As discussed above, given the
+variable encoding used for the metadata, all metadata bytes must still be
+fetched and scanned; however, CPUs are (very) fast at scanning data, and
+skipping *parsing* of unneeded fields speeds up overall metadata performance
+significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of generated code, opportunities for specializing
+the behavior of generated Thrift parsers is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is very stable (hard to change), which is important for easy maintenance when a large number
Review Comment:
It might be worth mentioning that arrow-rs already did some postprocessing on the generated code, and also included a custom implementation of the compact protocol api. That makes the step to a completely custom parser slightly smaller and less crazy :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2433391399
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
+variable encoding used for the metadata, all the metadata bytes must still be
+fetched and scanned; however, since CPUs are quite fast at scanning data, skipping
+parsing of unneeded fields can speed up overall metadata performance significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of automatically generated code, opportunities for specializing
+the behavior of Thrift compiler generated code is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is stable, which is important for easy maintenance when a large number
+ of projects are built using generated code from the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago.
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] came up with
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl] took the
+lead and rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Ed Seidl]: https://github.com/etseidl
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+For example, here is the original Thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here ([source]) is the corresponding Rust structure using the Thrift macros (before Ed wrote a custom version in [#8574]):
+
+[source]: https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This system makes it easy to see the correspondence between the Thrift
+definition and the Rust structure, making it straightforward to support newly added
+structures such as the recent `GeospatialStatistics`. The carefully hand-
+optimized parsers for the most performance-critical structures, such as
+`RowGroupMetaData` and `ColumnChunkMetaData`, are harder—though still
+straightforward—to update (see [this PR]). However, those structures are less
+likely to change frequently.
+
+### Future Improvements
+
+With the custom parser in place, we are working on additional improvements:
+
+* Implementing special "skip" indexes to skip directly to the parts of the metadata
+ that are needed for a particular query, such as the row group offsets.
+* Selectively decoding only the statistics for columns that are needed for a particular query.
+* Potentially contributing the macros back to the thrift crate.
+
+### Conclusion
+
+We believe metadata parsing in many open source Parquet
+readers is slow primarily because they use parsers automatically generated by Thrift
+compilers, which are not optimized for Parquet metadata parsing. By writing a
+custom parser, we significantly sped up metadata parsing in the
+[parquet] Rust crate, which is widely used in the [Apache Arrow] ecosystem.
+
+This is the first open source effort (to my knowledge) to write a custom Thrift
Review Comment:
Great call -- fixed in e86b3e7818b
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3361177086
Preview URL: https://alamb.github.io/arrow-site
If the preview URL doesn't work, you may forget to configure your fork repository for preview.
See https://github.com/apache/arrow-site/blob/main/README.md#forks how to configure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2430277326
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
Review Comment:
```suggestion
that are not used by the predicate is unnecessary. As discussed above, given the
```
I was thrown by the 10 column projection and thought `999` was wrong.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3403702194
@alamb Oh, sorry that those instructions didn't work... It seems that `*` doesn't match `XXX/YYY` branch names.
I'll update these instructions to the "No restriction" approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2432951974
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
Review Comment:
Thanks -- fixed in 3066161e695
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2437964960
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "3x-8x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly three times as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 3× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
Review Comment:
```suggestion
for `100`, `1000`, `10,000`, and `100,000` columns. The new parser is faster in all cases,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3402960314
Update: I changed my banch protection rule to "no restrictions"
<img width="948" height="841" alt="Screenshot 2025-10-14 at 1 05 37 PM" src="https://github.com/user-attachments/assets/9261cbc1-edd9-4a7d-a313-cd7c9d012c10" />
Probably not the best approach, but now the preview link does work: https://alamb.github.io/arrow-site/blog/2025/10/08/rust-parquet-metadata/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3406852720
> @alamb Oh, sorry that those instructions didn't work... It seems that `*` doesn't match `XXX/YYY` branch names.
>
> I'll update these instructions to the "No restriction" approach.
Thank you for making it easier to see the preview of the sites @kou 🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3393265581
The preview on fork is deployed on your fork's GitHub Actions not apache/arrow-site's GitHub Actions: https://github.com/alamb/arrow-site/actions/runs/18410524340
You need to the followings on https://github.com/alamb/arrow-site/settings/pages and https://github.com/alamb/arrow-site/settings/environments :
https://github.com/apache/arrow-site/blob/main/README.md#forks
> 1. Enable GitHub Pages on your fork:
> 1. Open [https://github.com/${YOUR_GITHUB_ACCOUNT}/arrow-site/settings/pages](https://github.com/$%7BYOUR_GITHUB_ACCOUNT%7D/arrow-site/settings/pages)
> 2. Select "GitHub Actions" as "Source"
> 2. Accept publishing GitHub Pages from all branches on your fork:
> 1. Open [https://github.com/${YOUR_GITHUB_ACCOUNT}/arrow-site/settings/environments](https://github.com/$%7BYOUR_GITHUB_ACCOUNT%7D/arrow-site/settings/environments)
> 2. Select the "github-pages" environment
> 1. Change the default "Deployment branches and tags" rule:
> 2. Press the "Edit" button
> 3. Change the "Name pattern" to * from main or gh-pages
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2433411806
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "2x-7x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+than needed. As discussed above, given the
+variable encoding used for the metadata, all metadata bytes must still be
+fetched and scanned; however, CPUs are (very) fast at scanning data, and
+skipping *parsing* of unneeded fields speeds up overall metadata performance
+significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of generated code, opportunities for specializing
+the behavior of generated Thrift parsers is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is very stable (hard to change), which is important for easy maintenance when a large number
+ of projects are built using the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago at
+ the time of this writing.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] developed
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl]
+rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
Review Comment:
FYI @jhorstmann you have a shout out in this blog -- please let me know if you would like any changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2434230986
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "2x-7x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+than needed. As discussed above, given the
+variable encoding used for the metadata, all metadata bytes must still be
+fetched and scanned; however, CPUs are (very) fast at scanning data, and
+skipping *parsing* of unneeded fields speeds up overall metadata performance
+significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of generated code, opportunities for specializing
+the behavior of generated Thrift parsers is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is very stable (hard to change), which is important for easy maintenance when a large number
+ of projects are built using the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago at
+ the time of this writing.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] developed
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl]
+rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
Review Comment:
Nice -- note that @etseidl also write up a readme here that is quite good:
https://github.com/apache/arrow-rs/blob/49d92fa163f61d677a971143c598ad9f020f8fec/parquet/THRIFT.md
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3437455572
BTW I re-ran the numbers with the final arrow 57 release
It is even better than before (thanks to @jhorstmann 's late arriving optimization 🚀
- https://github.com/apache/arrow-rs/pull/8636
<img width="1151" height="728" alt="results" src="https://github.com/user-attachments/assets/54f90cdb-d8e6-4f0d-b3f9-b8f6cb113073" />
I am going to read this blog once more and then publish it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3392157474
> > I'm unable to access the "preview" link; the bot comment suggests that @alamb needs to enable some setting on his fork?
>
> I tried to follow the directions, but it did not seem to work. I'll double check
For some reason the publish to fork workflow was skipped: https://github.com/apache/arrow-site/actions/runs/18410526447/job/52461618507?pr=711
The workflow file that github reports https://github.com/apache/arrow-site/actions/runs/18410526447/workflow?pr=711 seems to be ok, but I am not a github actions expert
```yaml
name: Deploy on fork
if: >-
github.event_name == 'push' &&
github.repository != 'apache/arrow-site'
needs: build
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2432836991
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
Review Comment:
Not sure if this was mentioned before, but Figure 6 has the old feather logo. Don't know if that should be updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3407814825
> > @etseidl I re-ran the numbers with the latest code from the arrow-rs main branch. Your optimization work is paying off -- we are now 3x faster than 56.2 😮 🤓
>
> I was just re-running your benchmark branch on my workstation and was composing a message the same effect 😁
I can't tell you how much I am currently grinning. You have basically achieved what @XingpengHao predicated 2 years ago (2x-4x speedup).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2417760586
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -1,8 +1,8 @@
---
layout: post
-title: "Reading Parquet Metadata in Rust got 2x faster"
+title: "Speeding up Parquet Metadata Parsing in Rust with a custom Thrift Parser"
date: "2025-10-08 00:00:00"
-author: "Andrew Lamb and Ed Seidl"
+author: "Andrew Lamb (InfluxData) and Ed Seidl (LLNL)"
Review Comment:
Thanks for the mention @alamb, but for bureaucratic reasons I'd prefer to not be listed as an author. Doing so leads to red tape and months of lead time to actually publish this. >.<
I'm still happy to help as I can.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2417761635
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -24,10 +24,10 @@ limitations under the License.
{% endcomment %}
-->
-
-*Editors Note: While the [Apache Arrow] and [Apache Parquet] are separate projects,
-the [arrow-rs] repository hosts the development of the [parquet] Rust crate, a widely used
-and high performance implementation.*
+*Editors Note: While the [Apache Arrow] and [Apache Parquet] are separate
Review Comment:
```suggestion
*Editors Note: While [Apache Arrow] and [Apache Parquet] are separate
```
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
Review Comment:
```suggestion
many small heap allocations, which are expensive.
```
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
-The custom parser is optimized for the specific subset of the Thrift format used
-by Parquet, and by using various performance optimizations
-### Example optimizations
-The obvious optimization is to remove the intermediate step of creating
-the in-memory structures generated by the thrift crate, and instead parse
-the thrift binary directly into arrow's own in-memory representation of parquet metadata.
+## New Design: Custom Thrift Parser
-However, there are other optimizations that can now be applied such as: (TODO GET LIST)
+As is typical of code generated from another tool, opportunities for
+optimization in the code generated by the thrift compilers are typically
+limited. This is because
+1. The generated is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
Review Comment:
```suggestion
1. The generated code is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
```
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
-The custom parser is optimized for the specific subset of the Thrift format used
-by Parquet, and by using various performance optimizations
-### Example optimizations
-The obvious optimization is to remove the intermediate step of creating
-the in-memory structures generated by the thrift crate, and instead parse
-the thrift binary directly into arrow's own in-memory representation of parquet metadata.
+## New Design: Custom Thrift Parser
-However, there are other optimizations that can now be applied such as: (TODO GET LIST)
+As is typical of code generated from another tool, opportunities for
+optimization in the code generated by the thrift compilers are typically
+limited. This is because
+1. The generated is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
+2. The generated code must be general purpose, and easy to embed, and typically has
+ generates structures with a one to one mapping of the thrift definitions,
+ which limits adding additional optimizations such as zero copy parsing, or
+ amortized memory allocation strategies.
+3. The thrift compilers are quite stable, which is important to enable embedding
+ generated code. For example, the [last release of the Rust `thrift` crate]
+ was almost three years ago.
-### Maintainability
-THe largest concern with this approach is that it is more difficult to maintain, as any changes to the parquet
-format must be manually reflected in the custom parser, and the thrift definitions
-do get updated (e.g. for the recent additions of [Geometry] and [Variant] tyoes)
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
-However, one of the arrow-rs contributors, Jorn Horstmann (todo link) prototyped a macro
-based approach, that generates the custom parser code using rust macros so that the
-rust structures look very similar to the original thrift definitions.
+Thus, we concluded that we needed a custom thrift parser that could be optimized
+for the specific subset of the Thrift format used by Parquet.
+So we instead wrote a custom parser that parses the thrift binary directly into the needed
+structures as shown in the figure below.
-For exmaple, here is the thrift definition of a parquet file metadata:
-(TOD)O
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
+own in-memory representation of parquet metadata.
+
+The custom parser is optimized for the specific subset of the Thrift format used
+by Parquet, and by using various performance optimizations, such as careful memory
+allocation and avoiding unnecessary copies.
-And the corresponding Rust structure that is created directly from the custom parser:
+The largest initial speedup came from removing the intermediate in-memory
+structures, and instead simply created the needed in-memory representation of
+parquet metadata. We also carefully hand optimized certain thrift decoding and
+memory allocation paths.
-(TODO example
-)
+### Maintainability
+
+THe largest concern with this approach is that it is more difficult to maintain, as any changes to the [`parquet.thrift`] file
+must be manually reflected in the custom parser, and the thrift definitions
+do get updated regularly (e.g. for the recent additions of [Geospatial] and [Variant] types)
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+However, [Jörn Horstmann] prototyped a [Rust macro
+based approach] that generates parsing code for annotated Rust structs
+that closely resemble the thrift definitions. Structs that need additional optimization
+can be manually implemented. This approach is similar to how the [serde] crate
+generates serialization and deserialization code for Rust structs.
+
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+<!-- https://x.com/jhorstmann23/status/1803426667748053448-->
+
+For example, here is the thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here is the corresponding Rust structure annotated with the custom thrift parsing macros:
+
+https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This organization makes it easy to see the correspondence between the thrift definition
+and the Rust structure, and makes it easy to update the Rust structure when the
+thrift definition changes.
Review Comment:
While true for objects we don't wish to customize, for the heavy hitting structures (FileMetaData, RowGroupMetaData, ColumnChunkMetaData) we actually skip using the macros and hand write those (but retain the ability to add new structures like the GeospatialStatistics with relative ease).
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -137,38 +137,62 @@ decoder implementation.
## Background: Apache Thrift
+
+[Apache Thrift] is a framework for defining network data types and service
+interfaces and includes a data definition language similar [Protocol Buffers].
Review Comment:
```suggestion
interfaces and includes a data definition language similar to [Protocol Buffers].
```
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -178,67 +202,155 @@ but this crate is not optimized for speed, and so we have been looking for alter
Figure 2: Two step process to read parquet metadata: use code generated by the thrift crate to parse
the thrift binary into in-memory structures, then convert the in-memory structures into arrow's
-## New Design: Custom Parser
-
-As is typical of code generated from another tool, oportunities for optimization
-are typically limited, both because the generated is not easy to modify.
-(TODO find exmaples of trying to help the thrift crate be faster)
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the thrift encoded bytes, copying data into in-memory, heap
+allocated structures such as a Rust [`Vec`], or C++ [`std::vector`], as
+shown in the figure below. This approach is simple and straightforward and a good
+choice given Thrift's design point of encoding network messages, which typically
+don't send extraneous information. However, reading all fields and allocating
+memory for them is not necessary in many cases when reading Parquet metadata.
-For example, the last release of the rust thrift compiler crate https://crates.io/crates/thrift/0.17.0
-was three years ago, and the last commit to the repository was over a year ago
-https://crates.io/crates/thrift
-We hope we can also help make the rust thrift crate to be better.
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[thrift compilers]: https://thrift.apache.org/lib/
-So we instead wrote a custom parser that parses the thrift binary directly into the needed
-structures.
+For some use cases, such as caching the parsed Parquet metadata, all the fields
+are needed and thus must be parsed. However, for many use cases, parsing the
+entire metadata into in memory structures is wasteful. For example, a query that
+reads only 10 columns from a file with 1000 columns with a single column predicate
+(e.g. `time > now() - '1 minute'`) only needs [`Statistics`] (or
+[`ColumnIndex`]) for the predicate column and the [`ColumnChunk`] for the 10 columns. Parsing (allocating and copying)
+statistics for remaining 999 columns which are not used in predicates is
+unnecessary work. While all the metadata bytes must still be fetched and scanned
+to find the relevant positions, CPUs are quite fast at scanning data, so skipping parsing
+unnecessary data can speed up overall metadata parsing significantly.
-The speedup was achieved by using a custom parser that is optimized for the specific
-subset of the Thrift format used by Parquet, and by using various performance optimizations.
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
- <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
</div>
-Figure 3: New one step process to read parquet metadata: use a custom parser to parse the thrift binary directly
-own in-memory representation of parquet metadata.
+*Figure XX*: Generated thrift parsers typically parse into heap allocated structures requiring
+in many small heap allocations, which are expensive.
-The custom parser is optimized for the specific subset of the Thrift format used
-by Parquet, and by using various performance optimizations
-### Example optimizations
-The obvious optimization is to remove the intermediate step of creating
-the in-memory structures generated by the thrift crate, and instead parse
-the thrift binary directly into arrow's own in-memory representation of parquet metadata.
+## New Design: Custom Thrift Parser
-However, there are other optimizations that can now be applied such as: (TODO GET LIST)
+As is typical of code generated from another tool, opportunities for
+optimization in the code generated by the thrift compilers are typically
+limited. This is because
+1. The generated is not easy to modify (it must be re-generated from from the thrift definitions when the definitions change)
+2. The generated code must be general purpose, and easy to embed, and typically has
+ generates structures with a one to one mapping of the thrift definitions,
Review Comment:
```suggestion
generated structures with a one to one mapping of the thrift definitions,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3392148223
> I'm unable to access the "preview" link; the bot comment suggests that @alamb needs to enable some setting on his fork?
I tried to follow the directions, but it did not seem to work. I'll double check
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3402738283
> The preview on fork is deployed on your fork's GitHub Actions not apache/arrow-site's GitHub Actions: https://github.com/alamb/arrow-site/actions/runs/18410524340
Thank you @kou
I had previously tried to follow those instructions and could not get it to work for some reason
Here is the content of
https://github.com/alamb/arrow-site/settings/pages
<img width="1187" height="862" alt="Screenshot 2025-10-14 at 12 31 14 PM" src="https://github.com/user-attachments/assets/92d8c752-c5fa-44bb-a7de-e136c8c8e4f2" />
https://github.com/alamb/arrow-site/settings/environments -->
https://github.com/alamb/arrow-site/settings/environments/9063572923/edit
<img width="1218" height="1130" alt="Screenshot 2025-10-14 at 12 32 50 PM" src="https://github.com/user-attachments/assets/aca27c07-3328-47fb-9b10-f21bb731affe" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3407755079
@etseidl I re-ran the numbers with the latest code from the arrow-rs main branch. Your optimization work is paying off -- we are now 3x faster than 56.2 😮 🤓
<img width="1158" height="735" alt="results" src="https://github.com/user-attachments/assets/38d34fd9-98f6-4d02-9517-3e601f2267be" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3407764271
> @etseidl I re-ran the numbers with the latest code from the arrow-rs main branch. Your optimization work is paying off -- we are now 3x faster than 56.2 😮 🤓
I was just re-running your benchmark branch on my workstation and was composing a message the same effect :grin:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2430277326
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
Review Comment:
```suggestion
that are not used by the predicate is unnecessary. As discussed above, given the
```
I was thrown by the 10 column projection and thought `990` was wrong.
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
+variable encoding used for the metadata, all the metadata bytes must still be
+fetched and scanned; however, since CPUs are quite fast at scanning data, skipping
+parsing of unneeded fields can speed up overall metadata performance significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of automatically generated code, opportunities for specializing
+the behavior of Thrift compiler generated code is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is stable, which is important for easy maintenance when a large number
+ of projects are built using generated code from the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago.
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] came up with
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl] took the
+lead and rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Ed Seidl]: https://github.com/etseidl
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+For example, here is the original Thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here ([source]) is the corresponding Rust structure using the Thrift macros (before Ed wrote a custom version in [#8574]):
+
+[source]: https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This system makes it easy to see the correspondence between the Thrift
+definition and the Rust structure, making it straightforward to support newly added
+structures such as the recent `GeospatialStatistics`. The carefully hand-
+optimized parsers for the most performance-critical structures, such as
Review Comment:
```suggestion
structures such as the recent `GeospatialStatistics`. The carefully hand-optimized
parsers for the most performance-critical structures, such as
```
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
+variable encoding used for the metadata, all the metadata bytes must still be
+fetched and scanned; however, since CPUs are quite fast at scanning data, skipping
+parsing of unneeded fields can speed up overall metadata performance significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of automatically generated code, opportunities for specializing
+the behavior of Thrift compiler generated code is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is stable, which is important for easy maintenance when a large number
+ of projects are built using generated code from the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago.
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] came up with
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl] took the
+lead and rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
+[Ed Seidl]: https://github.com/etseidl
+[Rust macro based approach]: https://github.com/jhorstmann/compact-thrift
+[serde]: https://serde.rs/
+
+For example, here is the original Thrift definition of the [`FileMetaData`] structure (comments omitted for brevity):
+
+[`FileMetaData`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1254C1-L1314C2
+
+```thrift
+struct FileMetaData {
+ 1: required i32 version
+ 2: required list<SchemaElement> schema;
+ 3: required i64 num_rows
+ 4: required list<RowGroup> row_groups
+ 5: optional list<KeyValue> key_value_metadata
+ 6: optional string created_by
+ 7: optional list<ColumnOrder> column_orders;
+ 8: optional EncryptionAlgorithm encryption_algorithm
+ 9: optional binary footer_signing_key_metadata
+}
+```
+
+And here ([source]) is the corresponding Rust structure using the Thrift macros (before Ed wrote a custom version in [#8574]):
+
+[source]: https://github.com/apache/arrow-rs/blob/02fa779a9cb122c5218293be3afb980832701683/parquet/src/file/metadata/thrift_gen.rs#L146-L158
+
+```rust
+thrift_struct!(
+struct FileMetaData<'a> {
+1: required i32 version
+2: required list<'a><SchemaElement> schema;
+3: required i64 num_rows
+4: required list<'a><RowGroup> row_groups
+5: optional list<KeyValue> key_value_metadata
+6: optional string<'a> created_by
+7: optional list<ColumnOrder> column_orders;
+8: optional EncryptionAlgorithm encryption_algorithm
+9: optional binary<'a> footer_signing_key_metadata
+}
+);
+```
+
+This system makes it easy to see the correspondence between the Thrift
+definition and the Rust structure, making it straightforward to support newly added
+structures such as the recent `GeospatialStatistics`. The carefully hand-
+optimized parsers for the most performance-critical structures, such as
+`RowGroupMetaData` and `ColumnChunkMetaData`, are harder—though still
+straightforward—to update (see [this PR]). However, those structures are less
+likely to change frequently.
+
+### Future Improvements
+
+With the custom parser in place, we are working on additional improvements:
+
+* Implementing special "skip" indexes to skip directly to the parts of the metadata
+ that are needed for a particular query, such as the row group offsets.
+* Selectively decoding only the statistics for columns that are needed for a particular query.
+* Potentially contributing the macros back to the thrift crate.
+
+### Conclusion
+
+We believe metadata parsing in many open source Parquet
+readers is slow primarily because they use parsers automatically generated by Thrift
+compilers, which are not optimized for Parquet metadata parsing. By writing a
+custom parser, we significantly sped up metadata parsing in the
+[parquet] Rust crate, which is widely used in the [Apache Arrow] ecosystem.
+
+This is the first open source effort (to my knowledge) to write a custom Thrift
Review Comment:
cudf beat us to the punch by several years 😅. They have a cool functor based parser. https://github.com/rapidsai/cudf/blob/branch-25.12/cpp/src/io/parquet/compact_protocol_reader.hpp
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2432993308
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
Review Comment:
Yeah, I agree this was confusing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "jhorstmann (via GitHub)" <gi...@apache.org>.
jhorstmann commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2433908003
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "2x-7x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+than needed. As discussed above, given the
+variable encoding used for the metadata, all metadata bytes must still be
+fetched and scanned; however, CPUs are (very) fast at scanning data, and
+skipping *parsing* of unneeded fields speeds up overall metadata performance
+significantly.
+
+[`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
+[`std::vector`]: https://en.cppreference.com/w/cpp/container/vector.html
+[Thrift compilers]: https://thrift.apache.org/lib/
+[`Statistics`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L912
+[`ColumnIndex`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L1163
+[`ColumnChunk`]: https://github.com/apache/parquet-format/blob/9fd57b59e0ce1a82a69237dcf8977d3e72a2965d/src/main/thrift/parquet.thrift#L958
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-parsing-allocations.png" width="100%" class="img-responsive" alt="Thrift Parsing Allocations" aria-hidden="true">
+</div>
+
+*Figure 7:* Generated Thrift parsers typically parse encoded bytes into
+structures requiring many small heap allocations, which are expensive.
+
+## New Design: Custom Thrift Parser
+
+As is typical of generated code, opportunities for specializing
+the behavior of generated Thrift parsers is limited:
+
+1. It is not easy to modify (it is re-generated from the
+ Thrift definitions when they change and carries the warning
+ `/* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING */`).
+2. It typically maps one-to-one with Thrift definitions, limiting
+ additional optimizations such as zero-copy parsing, field
+ skipping, and amortized memory allocation strategies.
+3. Its API is very stable (hard to change), which is important for easy maintenance when a large number
+ of projects are built using the [thrift crate]. For example, the
+ [last release of the Rust `thrift` crate] was almost three years ago at
+ the time of this writing.
+
+[last release of the Rust `thrift` crate]: https://crates.io/crates/thrift/0.17.0
+
+
+These limitations are a consequence of the design goals for producing code that
+is general purpose and easy to embed in a wide variety of projects, rather than
+any fundamental limitation of generated code.
+Given our goal of fast Parquet metadata parsing, we concluded we
+needed a custom parser that converts the Thrift binary directly into the needed
+structures and is easier to optimize (Figure 8).
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/new-pipeline.png" width="100%" class="img-responsive" alt="New Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 8:* One-step Parquet metadata parsing using a custom Thrift parser. The
+Thrift binary is parsed directly into the desired in-memory representation with
+highly optimized code.
+
+Our new custom parser is optimized for the specific subset of Thrift used by
+Parquet and contains various performance optimizations, such as careful
+memory allocation. The largest initial speedup came from removing
+intermediate in-memory structures and directly creating the needed in-memory representation.
+We also carefully hand-optimized several performance-critical code paths (see [#8574],
+[#8587], and [#8599]).
+
+[#8574]: https://github.com/apache/arrow-rs/pull/8574
+[#8587]: https://github.com/apache/arrow-rs/pull/8587
+[#8599]: https://github.com/apache/arrow-rs/pull/8599
+
+### Maintainability
+
+The largest concern with a custom parser is that it is more difficult
+to maintain than generated parsers because the custom parser must be updated to
+reflect any changes to [parquet.thrift]. This is a growing concern given the
+resurgent interest in Parquet and the recent addition of new features such as
+[Geospatial] and [Variant] types.
+
+[Geospatial]: https://github.com/apache/parquet-format/blob/master/Geospatial.md
+[Variant]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md
+
+Thankfully, after discussions with the community, [Jörn Horstmann] developed
+a [Rust macro based approach] for generating code with annotated Rust structs
+that closely resemble the Thrift definitions while permitting additional hand
+optimization where necessary. This approach is similar to the [serde] crate
+where generic implementations can be generated with `#[derive]` annotations and
+specialized serialization is written by hand where needed. [Ed Seidl]
+rewrote the metadata parsing code in the [parquet] crate using this
+approach. Please see the [final PR] for details of the level of effort involved.
+
+[final PR]: https://github.com/apache/arrow-rs/pull/8530
+[Jörn Horstmann]: https://github.com/jhorstmann
Review Comment:
Thanks, looks good! I actually plan to do a presentation on the macros at an internal Rust meetup and will then also update the readme of the `compact-thrift` repository with more details. The details how the macros work are probably out of scope for this blog post, but could be added to the `arrow-rs` code base later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2433415888
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,403 @@
+---
+layout: post
+title: "2x-7x Faster Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and enables further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often performance critical when reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed to know what data pages to read, placing it directly on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must still be parsed on cache miss.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful
+systems. Stateless engines read the footer on every query, and the time taken to
+parse the footer directly adds to query latency. Stateful systems cache some or
+all of the parsed footer in advance of queries. The performance of footer
+parsing is important for both types of systems, but especially for stateless.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability, interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs.
+As overall query times decrease, the proportion spent on footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of the metadata
+serialized at the end of each Parquet file in the [Thrift Compact
+protocol], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [FlatBuffers] provide
+random-access parsing and have been [proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[FlatBuffers]: https://google.github.io/flatbuffers/
+[proposed as alternatives]: https://lists.apache.org/thread/j9qv5vyg0r4jk6tbm6sqthltly4oztd3
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift Compact protocol].
+Each field is stored using a variable number of bytes that depends on its value.
+Primitive types use a variable-length encoding and strings and lists are
+prefixed with their lengths.
+
+[Thrift Compact protocol]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes. [Xiangpeng Hao]'s
+previous analysis theorized significant (2x–4x) potential performance
+improvements simply by optimizing the implementation of Parquet footer parsing.
+See the blog post [How Good is Parquet for Wide Tables (Machine Learning
+Workloads) Really?] for more details.
+
+## Processing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into API-level structures.
+For example, the [C/C++ Parquet implementation] includes a [two]-[step] process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. Parsing metadata involves:
+
+1. Invoke the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., [`struct FileMetaData`]), then
+2. Copy the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects.
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in Figure 7 below.
+
+Parsing all fields is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+Network messages typically don't contain extra information irrelevant for receivers;
+however, Parquet metadata often *does* contain information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful.
+
+For example, a query on a file with 1,000 columns that reads
+only 10 columns and has a single column predicate
+(e.g., `time > now() - '1 minute'`) only needs
+
+1. [`Statistics`] (or [`ColumnIndex`]) for the `time` column
+2. [`ColumnChunk`] information for the 10 selected columns
+
+The default strategy to parse (allocating and copying) all statistics and all
+`ColumnChunks` results in 999 more statistics and 990 more `ColumnChunks` being
+than needed. As discussed above, given the
Review Comment:
```suggestion
parsed than are necessary. As discussed above, given the
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "cannonpalms (via GitHub)" <gi...@apache.org>.
cannonpalms commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2417481826
##########
img/rust-parquet-metadata/original-pipeline.png:
##########
Review Comment:
In pink, is `Step 3: Gata` a typo for `Step 3: Data`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3422838218
My plan here is to wait for the arrow 57 release to be published (eta in about 2 days), and then rerun the benchmarks again with the final released version and then publish this blog
If anyone else would like more time to review, please just leave comments
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3361178131
FYI @etseidl I started writing a blog post about this work. Right now it is a brain dump and isn't ready for review but I wanted to get it out of my mind
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2417561291
##########
img/rust-parquet-metadata/original-pipeline.png:
##########
Review Comment:
thanks @cannonpalms -- I fixed it in the source and I will update the images before publishing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3438511028
Blog is live: https://arrow.apache.org/blog/2025/10/23/rust-parquet-metadata/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #711:
URL: https://github.com/apache/arrow-site/pull/711#discussion_r2432993308
##########
_posts/2025-10-30-rust-parquet-metadata.md:
##########
@@ -0,0 +1,392 @@
+---
+layout: post
+title: "Parsing Apache Parquet Footer Metadata Using a Custom Thrift Parser in Rust"
+date: "2025-10-08 00:00:00"
+author: "Andrew Lamb (InfluxData)"
+categories: [release]
+---
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+*Editor’s Note: While [Apache Arrow] and [Apache Parquet] are separate
+projects, this post is part of the Arrow site because the Arrow [arrow-rs]
+repository hosts the development of the [parquet] Rust crate, a widely used and
+high-performance implementation of the Parquet format.*
+
+## Summary
+
+Version `57.0.0` of the [parquet] Rust crate decodes metadata roughly twice as
+fast as previous versions thanks to a new custom [Apache Thrift] parser. The new
+parser is 2× faster in all cases and sets the stage for further performance improvements not
+possible with generated parsers, such as skipping unnecessary fields and selective parsing.
+
+<!-- AAL: TODO: update the benchmark and charts with results from 57.0.0 -->
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/results.png" width="100%" class="img-responsive" alt="" aria-hidden="true">
+</div>
+
+*Figure 1:* Performance comparison of [Apache Parquet] metadata parsing using a generated
+Thrift parser (versions `56.2.0` and earlier) and the new
+[custom Thrift decoder] in [arrow-rs] version [57.0.0]. No
+changes are needed to the Parquet format itself.
+See the [benchmark page] for more details.
+
+[parquet]: https://crates.io/crates/parquet
+[Apache Arrow]: https://arrow.apache.org/
+[Apache Parquet]: https://parquet.apache.org/
+[custom Thrift decoder]: https://github.com/apache/arrow-rs/issues/5854
+[arrow-rs]: https://github.com/apache/arrow-rs
+[57.0.0]: https://github.com/apache/arrow-rs/issues/7835
+
+[benchmark page]: https://github.com/alamb/parquet_footer_parsing
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/scaling.png" width="100%" class="img-responsive" alt="Scaling behavior of custom Thrift parser" aria-hidden="true">
+</div>
+
+*Figure 2:* Speedup of the [custom Thrift decoder] for string and floating-point data types,
+for `100`, `1000`, and `100,000` columns. The new parser is faster in all cases,
+and the speedup is similar regardless of the number of columns. See the [benchmark page] for more details.
+
+## Introduction: Parquet and the Importance of Metadata Parsing
+
+[Apache Parquet] is a popular columnar storage format for big data processing. It
+is designed to be efficient for both storage and query performance. Parquet
+files consist of a header, a series of data pages, and a footer, as shown in Figure 3. The footer
+contains metadata about the file, including schema, statistics, and other
+information needed to decode the data.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/parquet.png" width="100%" class="img-responsive" alt="Physical File Structure of Parquet" aria-hidden="true">
+</div>
+
+*Figure 3:* Structure of a Parquet file showing the header, data pages, and footer metadata.
+
+Getting information stored in the footer is typically the first step in reading
+a Parquet file, as it is required to interpret the data pages. *Parsing* the
+footer is often on the critical path for reading data:
+
+* When reading from fast local storage, such as modern NVMe SSDs, footer parsing
+ must be completed before data pages are read, placing it on the critical
+ I/O path.
+* Footer parsing scales linearly with the number of columns and row groups in a
+ Parquet file and thus can be a bottleneck for tables with many columns or files
+ with many row groups.
+* For systems that cache the parsed footer in memory, as explained in [Using
+ External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries
+ on Apache Parquet], the footer must be parsed when the cache is cold or the
+ hit rate is low.
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/flow.png" width="100%" class="img-responsive" alt="Typical Parquet processing flow" aria-hidden="true">
+</div>
+
+*Figure 4:* Typical processing flow for Parquet files for stateless and stateful systems.
+The performance of footer parsing is important for both types of systems, but especially
+for stateless systems that do not cache the parsed footer.
+
+[Using External Indexes, Metadata Stores, Catalogs and Caches to Accelerate Queries on Apache Parquet]: https://datafusion.apache.org/blog/2025/08/15/external-parquet-indexes/
+
+The speed of parsing metadata has grown even more important as Parquet spreads
+throughout the data ecosystem and is used for more latency-sensitive workloads such
+as observability (TODO find citations), interactive analytics, and single-point
+lookups for Retrieval-Augmented Generation (RAG) applications feeding LLMs (TODO
+find citations). As overall query times decrease, the relative
+importance of footer parsing increases.
+
+## Background: Apache Thrift
+
+Parquet stores metadata using [Apache Thrift], a framework for
+network data types and service interfaces. It includes a [data definition
+language] similar to [Protocol Buffers]. Thrift definition files describe data
+types in a language-neutral way, and systems use code generators to
+automatically create code for a specific programming language to read and write
+those data types.
+
+The [parquet.thrift] file defines the format of Parquet metadata that is
+serialized at the end of each Parquet file in the [Thrift compact binary
+encoding format], as shown below in Figure 5. The binary encoding is "variable-length",
+meaning that the length of each element depends on its content, not
+just its type. Smaller-valued primitive types are encoded in fewer bytes than
+larger values, and strings and lists are stored inline, prefixed with their
+length.
+
+This encoding is space-efficient but, due to being variable-length, does not
+support random access: it is not possible to locate a particular field without
+scanning all previous fields. Other formats such as [Flatbuffers] provide
+random-access parsing and have [been proposed as alternatives] given their
+theoretical performance advantages. However, changing the Parquet format is a
+significant undertaking, requires buy-in from the community and ecosystem,
+and would likely take years to be adopted.
+
+[How Good is Parquet for Wide Tables (Machine Learning Workloads) Really?]: https://www.influxdata.com/blog/how-good-parquet-wide-tables/
+[Apache Thrift]: https://thrift.apache.org/
+[Flatbuffers]: https://google.github.io/flatbuffers/
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/thrift-compact-encoding.png" width="100%" class="img-responsive" alt="Thrift Compact Encoding Illustration" aria-hidden="true">
+</div>
+
+*Figure 5:* Parquet metadata is serialized using the [Thrift compact binary
+encoding format]. Each field is stored using a variable number of bytes that
+depends on its value. Primitive types use a variable-length encoding and strings
+and lists are prefixed with their lengths.
+
+[Thrift compact binary encoding format]: https://github.com/apache/thrift/blob/master/doc/specs/thrift-compact-protocol.md
+[Protocol Buffers]: https://developers.google.com/protocol-buffers
+[data definition language]: https://thrift.apache.org/docs/idl
+[parquet.thrift]: https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift
+[gRPC]: https://grpc.io/
+[Xiangpeng Hao]: https://xiangpeng.systems/
+
+Despite Thrift's very real disadvantage due to lack of random access, software
+optimizations are much easier to deploy than format changes, and thus we decided
+to explore this approach first. [Xiangpeng Hao] previously measured significant
+(2x–4x) potential performance improvements simply by optimizing the
+implementation of Parquet footer parsing. See the blog post [How Good is
+Parquet for Wide Tables (Machine Learning Workloads) Really?] for more details.
+
+## Parsing Thrift Using Generated Parsers
+
+*Parsing* Parquet metadata is the process of decoding the Thrift-encoded bytes
+into in-memory structures that can be used for computation. Most Parquet
+implementations use one of the existing [Thrift compilers] to generate a parser
+that converts Thrift binary data into generated code structures, and then copy
+relevant portions of those generated structures into their API-level structures.
+For example, the [C/C++ Parquet implementation] includes a two-step process,
+as does [parquet-java]. [DuckDB] also contains a Thrift compiler–generated
+parser.
+
+In versions `56.2.0` and earlier, the Apache Arrow Rust implementation used the
+same pattern. The [format] module contains a parser generated by the [thrift
+crate] and the [parquet.thrift] definition. To parse metadata, it:
+
+1. Invokes the generated parser on the Thrift binary data, producing
+ generated in-memory structures (e.g., `struct FileMetaData`), then
+2. Copies the relevant fields into a more user-friendly representation,
+ [`ParquetMetadata`].
+
+[thrift crate]: https://crates.io/crates/thrift
+[format]: https://docs.rs/parquet/56.2.0/parquet/format/index.html
+[`ParquetMetadata`]: https://docs.rs/parquet/56.2.0/parquet/file/metadata/struct.ParquetMetaData.html
+[`struct FileMetaData`]: https://docs.rs/parquet/56.2.0/parquet/format/struct.FileMetaData.html
+
+[two]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/build-support/update-thrift.sh#L23
+[step process]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet/thrift_internal.h#L56
+[C/C++ Parquet implementation]: https://github.com/apache/arrow/blob/e1f727cbb447d2385949a54d8f4be2fdc6cefe29/cpp/src/parquet
+[parquet-java]: https://github.com/apache/parquet-java/blob/0fea3e1e22fffb0a25193e3efb9a5d090899458a/parquet-format-structures/pom.xml#L69-L88
+[DuckDB]: https://github.com/duckdb/duckdb/blob/8f512187537c65d36ce6d6f562b75a37e8d4ee54/third_party/parquet/parquet_types.h#L1-L6
+
+<!-- Image source: https://docs.google.com/presentation/d/1WjX4t7YVj2kY14SqCpenGqNl_swjdHvPg86UeBT3IcY -->
+<div style="display: flex; gap: 16px; justify-content: center; align-items: flex-start;">
+ <img src="{{ site.baseurl }}/img/rust-parquet-metadata/original-pipeline.png" width="100%" class="img-responsive" alt="Original Parquet Parsing Pipeline" aria-hidden="true">
+</div>
+
+*Figure 6:* Two-step process to read Parquet metadata: A parser created with the
+`thrift` crate and `parquet.thrift` parses the metadata bytes
+into generated in-memory structures. These structures are then converted into
+API objects such as [`ParquetMetadata`].
+
+The parsers generated by standard Thrift compilers typically parse *all* fields
+in a single pass over the Thrift-encoded bytes, copying data into in-memory,
+heap-allocated structures (e.g., Rust [`Vec`], or C++ [`std::vector`]) as shown
+in the figure below. This approach is straightforward and a good default
+choice given Thrift's original design goal of encoding network messages.
+
+Network messages typically don't contain extra information that can be skipped
+by some receivers; however, Parquet metadata often does contain extra information
+that is not needed for a particular query. In such cases, parsing the entire
+metadata into in-memory structures is wasteful. For example, a query that reads
+only 10 columns from a file with 1,000 columns with a single column predicate
+(e.g., `time > now() - '1 minute'`) needs [`Statistics`] (or
+[`ColumnIndex`]) only for the predicate column and the [`ColumnChunk`] for the 10
+columns. Parsing (allocating and copying) statistics for the remaining 999 columns
+that are not used is unnecessary. As discussed above, given the
Review Comment:
Yeah, I agree this was confusing. Thank you
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Website]: Blog post about new Rust Parquet Metadata parser [arrow-site]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #711:
URL: https://github.com/apache/arrow-site/pull/711#issuecomment-3402743560
For some reason the branch protection rule is preventing it: https://github.com/alamb/arrow-site/actions/runs/18410524340
<img width="1345" height="999" alt="Screenshot 2025-10-14 at 12 36 08 PM" src="https://github.com/user-attachments/assets/64de9799-19c6-4e48-8d77-23a40a7cc3f7" />
I will look more carefully
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org