You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by et...@apache.org on 2025/10/14 14:02:50 UTC

(arrow-rs) branch main updated: [Parquet] Remove use of `parquet::format` in metadata bench code (#8598)

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

etseidl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new a02be635a0 [Parquet] Remove use of `parquet::format` in metadata bench code (#8598)
a02be635a0 is described below

commit a02be635a0ec514ba12ae45562c724ebe546c595
Author: lichuang <li...@gmail.com>
AuthorDate: Tue Oct 14 22:02:44 2025 +0800

    [Parquet] Remove use of `parquet::format` in metadata bench code (#8598)
    
    # Which issue does this PR close?
    
    Remove unused parquet::format crate in `metadata.rs` bench code, but the
    file `format.rs` has not been removed, because it is used in
    `parquet-layout.rs`
    
    - Part of #8572.
    
    # Rationale for this change
    
    Why are you proposing this change? If this is already explained clearly
    in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand
    your changes and offer better suggestions for fixes.
    
    # What changes are included in this PR?
    
    There is no need to duplicate the description in the issue here but it
    is sometimes worth providing a summary of the individual changes in this
    PR.
    
    # Are these changes tested?
    
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they covered by existing tests)?
    
    # Are there any user-facing changes?
    
    If there are user-facing changes then we may require documentation to be
    updated before approving the PR.
    
    If there are any breaking changes to public APIs, please call them out.
---
 parquet/benches/metadata.rs | 168 +++++++++++++++++++-------------------------
 1 file changed, 72 insertions(+), 96 deletions(-)

diff --git a/parquet/benches/metadata.rs b/parquet/benches/metadata.rs
index b05d6c33a9..1d61c4d7ac 100644
--- a/parquet/benches/metadata.rs
+++ b/parquet/benches/metadata.rs
@@ -15,20 +15,26 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use parquet::file::metadata::ParquetMetaDataReader;
+use std::sync::Arc;
+
+use parquet::basic::{Encoding, PageType, Type as PhysicalType};
+use parquet::file::metadata::{
+    ColumnChunkMetaData, FileMetaData, PageEncodingStats, ParquetMetaData, ParquetMetaDataReader,
+    ParquetMetaDataWriter, RowGroupMetaData,
+};
+use parquet::file::statistics::Statistics;
+use parquet::file::writer::TrackedWrite;
+use parquet::schema::parser::parse_message_type;
+use parquet::schema::types::{
+    ColumnDescPtr, ColumnDescriptor, ColumnPath, SchemaDescriptor, Type as SchemaType,
+};
 use rand::Rng;
-use thrift::protocol::TCompactOutputProtocol;
 
 use arrow::util::test_util::seedable_rng;
 use bytes::Bytes;
 use criterion::*;
 use parquet::file::reader::SerializedFileReader;
 use parquet::file::serialized_reader::ReadOptionsBuilder;
-use parquet::format::{
-    ColumnChunk, ColumnMetaData, CompressionCodec, Encoding, FieldRepetitionType, FileMetaData,
-    PageEncodingStats, PageType, RowGroup, SchemaElement, Type,
-};
-use parquet::thrift::TSerializable;
 
 const NUM_COLUMNS: usize = 10_000;
 const NUM_ROW_GROUPS: usize = 10;
@@ -36,65 +42,42 @@ const NUM_ROW_GROUPS: usize = 10;
 fn encoded_meta() -> Vec<u8> {
     let mut rng = seedable_rng();
 
-    let mut schema = Vec::with_capacity(NUM_COLUMNS + 1);
-    schema.push(SchemaElement {
-        type_: None,
-        type_length: None,
-        repetition_type: None,
-        name: Default::default(),
-        num_children: Some(NUM_COLUMNS as _),
-        converted_type: None,
-        scale: None,
-        precision: None,
-        field_id: None,
-        logical_type: None,
-    });
+    let mut column_desc_ptrs: Vec<ColumnDescPtr> = Vec::with_capacity(NUM_COLUMNS);
+    let mut message_type = "message test_schema {".to_string();
     for i in 0..NUM_COLUMNS {
-        schema.push(SchemaElement {
-            type_: Some(Type::FLOAT),
-            type_length: None,
-            repetition_type: Some(FieldRepetitionType::REQUIRED),
-            name: i.to_string(),
-            num_children: None,
-            converted_type: None,
-            scale: None,
-            precision: None,
-            field_id: None,
-            logical_type: None,
-        })
+        message_type.push_str(&format!("REQUIRED FLOAT {};", i));
+        column_desc_ptrs.push(ColumnDescPtr::new(ColumnDescriptor::new(
+            Arc::new(
+                SchemaType::primitive_type_builder(&i.to_string(), PhysicalType::FLOAT)
+                    .build()
+                    .unwrap(),
+            ),
+            0,
+            0,
+            ColumnPath::new(vec![]),
+        )));
     }
+    message_type.push('}');
 
-    let stats = parquet::format::Statistics {
-        min: None,
-        max: None,
-        null_count: Some(0),
-        distinct_count: None,
-        max_value: Some(vec![rng.random(); 8]),
-        min_value: Some(vec![rng.random(); 8]),
-        is_max_value_exact: Some(true),
-        is_min_value_exact: Some(true),
-    };
+    let schema_descr = parse_message_type(&message_type)
+        .map(|t| Arc::new(SchemaDescriptor::new(Arc::new(t))))
+        .unwrap();
+
+    let stats = Statistics::float(Some(rng.random()), Some(rng.random()), None, Some(0), false);
 
     let row_groups = (0..NUM_ROW_GROUPS)
         .map(|i| {
             let columns = (0..NUM_COLUMNS)
-                .map(|_| ColumnChunk {
-                    file_path: None,
-                    file_offset: 0,
-                    meta_data: Some(ColumnMetaData {
-                        type_: Type::FLOAT,
-                        encodings: vec![Encoding::PLAIN, Encoding::RLE_DICTIONARY],
-                        path_in_schema: vec![],
-                        codec: CompressionCodec::UNCOMPRESSED,
-                        num_values: rng.random_range(1..1000000),
-                        total_uncompressed_size: rng.random_range(100000..100000000),
-                        total_compressed_size: rng.random_range(50000..5000000),
-                        key_value_metadata: None,
-                        data_page_offset: rng.random_range(4..2000000000),
-                        index_page_offset: None,
-                        dictionary_page_offset: Some(rng.random_range(4..2000000000)),
-                        statistics: Some(stats.clone()),
-                        encoding_stats: Some(vec![
+                .map(|j| {
+                    ColumnChunkMetaData::builder(column_desc_ptrs[j].clone())
+                        .set_encodings(vec![Encoding::PLAIN, Encoding::RLE_DICTIONARY])
+                        .set_compression(parquet::basic::Compression::UNCOMPRESSED)
+                        .set_num_values(rng.random_range(1..1000000))
+                        .set_total_compressed_size(rng.random_range(50000..5000000))
+                        .set_data_page_offset(rng.random_range(4..2000000000))
+                        .set_dictionary_page_offset(Some(rng.random_range(4..2000000000)))
+                        .set_statistics(stats.clone())
+                        .set_page_encoding_stats(vec![
                             PageEncodingStats {
                                 page_type: PageType::DICTIONARY_PAGE,
                                 encoding: Encoding::PLAIN,
@@ -105,51 +88,44 @@ fn encoded_meta() -> Vec<u8> {
                                 encoding: Encoding::RLE_DICTIONARY,
                                 count: 10,
                             },
-                        ]),
-                        bloom_filter_offset: None,
-                        bloom_filter_length: None,
-                        size_statistics: None,
-                        geospatial_statistics: None,
-                    }),
-                    offset_index_offset: Some(rng.random_range(0..2000000000)),
-                    offset_index_length: Some(rng.random_range(1..100000)),
-                    column_index_offset: Some(rng.random_range(0..2000000000)),
-                    column_index_length: Some(rng.random_range(1..100000)),
-                    crypto_metadata: None,
-                    encrypted_column_metadata: None,
+                        ])
+                        .set_offset_index_offset(Some(rng.random_range(0..2000000000)))
+                        .set_offset_index_length(Some(rng.random_range(1..100000)))
+                        .set_column_index_offset(Some(rng.random_range(0..2000000000)))
+                        .set_column_index_length(Some(rng.random_range(1..100000)))
+                        .build()
+                        .unwrap()
                 })
                 .collect();
 
-            RowGroup {
-                columns,
-                total_byte_size: rng.random_range(1..2000000000),
-                num_rows: rng.random_range(1..10000000000),
-                sorting_columns: None,
-                file_offset: None,
-                total_compressed_size: Some(rng.random_range(1..1000000000)),
-                ordinal: Some(i as _),
-            }
+            RowGroupMetaData::builder(schema_descr.clone())
+                .set_column_metadata(columns)
+                .set_total_byte_size(rng.random_range(1..2000000000))
+                .set_num_rows(rng.random_range(1..10000000000))
+                .set_ordinal(i as i16)
+                .build()
+                .unwrap()
         })
         .collect();
 
-    let file = FileMetaData {
-        schema,
-        row_groups,
-        version: 1,
-        num_rows: rng.random_range(1..2000000000),
-        key_value_metadata: None,
-        created_by: Some("parquet-rs".into()),
-        column_orders: None,
-        encryption_algorithm: None,
-        footer_signing_key_metadata: None,
-    };
-
-    let mut buf = Vec::with_capacity(1024);
+    let file_metadata = FileMetaData::new(
+        1,
+        rng.random_range(1..2000000000),
+        Some("parquet-rs".into()),
+        None,
+        schema_descr,
+        None,
+    );
+
+    let metadata = ParquetMetaData::new(file_metadata, row_groups);
+    let mut buffer = Vec::with_capacity(1024);
     {
-        let mut out = TCompactOutputProtocol::new(&mut buf);
-        file.write_to_out_protocol(&mut out).unwrap();
+        let buf = TrackedWrite::new(&mut buffer);
+        let writer = ParquetMetaDataWriter::new_with_tracked(buf, &metadata);
+        writer.finish().unwrap();
     }
-    buf
+
+    buffer
 }
 
 fn get_footer_bytes(data: Bytes) -> Bytes {