This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-12304-bef1132ae8dd220acfe8487b5d2e8f9e9500a08c
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit dc308c5e7be9da4cdcc086cb0acc2b00ad249fb9
Author: Arthur Carcano <[email protected]>
AuthorDate: Mon Nov 23 19:42:12 2026 +0000

    Small fixes in parquet_derive (#12304)
    
    # Which issue does this PR close?
    
    None, these are small cleanups in `parquet_derive`.
    
    # Rationale for this change
    
    A handful of small fixes noticed while reading the `parquet_derive`
    code.
    
    # What changes are included in this PR?
    
    - Fix a typo in `ParquetRecordReader`'s doc ("writing code" → "reading
    code").
    - Wrap the example structs in the `*_snippet` docs in `ignore` code
    blocks so they render with syntax highlighting, and drop the stray
    backticks around `Option<bool>`.
    - Build `name_to_index` in the derived reader with `collect` instead of
    a manual insert loop (slightly more optimal, directly allocates to the
    right size).
    - Reserve space for `num_records` in the derived reader before pushing
    records.
    
    # Are these changes tested?
    
    Covered by the existing `parquet_derive` and `parquet_derive_test`
    tests; no behavior change besides the up-front allocations.
    
    # Are there any significant user-facing changes?
    
    No.
    
    # AI usage disclosure
    
    This PR description was drafted with Claude Code. The changes were
    manual.
---
 parquet_derive/src/lib.rs           | 23 +++++++++++++----------
 parquet_derive/src/parquet_field.rs | 10 +++++++++-
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/parquet_derive/src/lib.rs b/parquet_derive/src/lib.rs
index ac5f8a40e1..3f4c9ab221 100644
--- a/parquet_derive/src/lib.rs
+++ b/parquet_derive/src/lib.rs
@@ -181,7 +181,7 @@ pub fn parquet_record_writer(input: 
proc_macro::TokenStream) -> proc_macro::Toke
 /// Derive flat, simple RecordReader implementations.
 ///
 /// Works by parsing a struct tagged with `#[derive(ParquetRecordReader)]` and 
emitting
-/// the correct writing code for each field of the struct. Column readers
+/// the correct reading code for each field of the struct. Column readers
 /// are generated by matching names in the schema to the names in the struct.
 ///
 /// It is up to the programmer to ensure the names in the struct
@@ -254,18 +254,21 @@ pub fn parquet_record_reader(input: 
proc_macro::TokenStream) -> proc_macro::Toke
         let mut row_group_reader = row_group_reader;
 
         // key: parquet file column name, value: column index
-        let mut name_to_index = std::collections::HashMap::new();
-        for (idx, col) in 
row_group_reader.metadata().schema_descr().columns().iter().enumerate() {
-            name_to_index.insert(col.name().to_string(), idx);
-        }
-
-        for _ in 0..num_records {
-          self.push(#derived_for {
+        let name_to_index : std::collections::HashMap<_,_> = row_group_reader
+            .metadata()
+            .schema_descr()
+            .columns()
+            .iter()
+            .enumerate()
+            .map(|(idx,col)| (col.name().to_string(),idx))
+            .collect();
+        self.extend(std::iter::repeat_with(|| {
+          #derived_for {
             #(
               #field_names: Default::default()
             ),*
-          })
-        }
+          }
+        }).take(num_records));
 
         let records = self; // Used by all the reader snippets to be more clear
 
diff --git a/parquet_derive/src/parquet_field.rs 
b/parquet_derive/src/parquet_field.rs
index e329344363..c9ed6c6077 100644
--- a/parquet_derive/src/parquet_field.rs
+++ b/parquet_derive/src/parquet_field.rs
@@ -68,17 +68,21 @@ impl Field {
     ///
     /// Can only generate writers for basic structs, for example:
     ///
+    /// ```ignore
     /// struct Record {
     ///   a_bool: bool,
-    ///   maybe_a_bool: `Option<bool>`
+    ///   maybe_a_bool: Option<bool>
     /// }
+    /// ```
     ///
     /// but not
     ///
+    /// ```ignore
     /// struct UnsupportedNestedRecord {
     ///   a_property: bool,
     ///   nested_record: Record
     /// }
+    /// ```
     ///
     /// because this parsing logic is not sophisticated enough for definition
     /// levels beyond 2.
@@ -227,16 +231,20 @@ impl Field {
     ///
     /// Can only generate writers for basic structs, for example:
     ///
+    /// ```ignore
     /// struct Record {
     ///   a_bool: bool
     /// }
+    /// ```
     ///
     /// but not
     ///
+    /// ```ignore
     /// struct UnsupportedNestedRecord {
     ///   a_property: bool,
     ///   nested_record: Record
     /// }
+    /// ```
     ///
     /// because this parsing logic is not sophisticated enough for definition
     /// levels beyond 2.

Reply via email to