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

Jefffrey 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 fc16607ccf parquet plain dict bench (#10591)
fc16607ccf is described below

commit fc16607ccfdb298557ed6630742941761ac18ce3
Author: RIchard Baah <[email protected]>
AuthorDate: Tue Aug 11 02:59:11 2026 -0400

    parquet plain dict bench (#10591)
    
    # Which issue does this PR close?
    
    <!--
    We generally require a GitHub issue to be filed for all bug fixes and
    enhancements and this helps us generate change logs for our releases.
    You can link an issue to this PR using the GitHub syntax.
    -->
    
    - works towards #10590
    - works towards https://github.com/apache/datafusion/issues/24111
    
    # Rationale for this change
     see #10590
    <!--
    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?
    introduces benchmarks for reading string values into dictionary arrays
    <!--
    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?
    n/a
    <!--
    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)?
    
    If this PR claims a performance improvement, please include evidence
    such as benchmark results.
    -->
    
    # Are there any user-facing changes?
    no
    <!--
    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/arrow_reader.rs | 83 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/parquet/benches/arrow_reader.rs b/parquet/benches/arrow_reader.rs
index 2fad9d5c9e..b86306ab8f 100644
--- a/parquet/benches/arrow_reader.rs
+++ b/parquet/benches/arrow_reader.rs
@@ -15,21 +15,27 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use arrow::array::Array;
-use arrow::datatypes::DataType;
+use arrow::array::{Array, StringArray};
+use arrow::datatypes::{DataType, Schema, SchemaRef};
+use arrow::record_batch::RecordBatch;
 use arrow_schema::Field;
+use bytes::Bytes;
 use criterion::measurement::WallTime;
 use criterion::{BenchmarkGroup, Criterion, criterion_group, criterion_main};
 use half::f16;
 use num_bigint::BigInt;
 use num_traits::FromPrimitive;
+use parquet::arrow::ArrowWriter;
 use parquet::arrow::array_reader::{
     ListArrayReader, make_byte_array_reader, make_byte_view_array_reader,
     make_fixed_len_byte_array_reader,
 };
-use parquet::arrow::arrow_reader::DEFAULT_BATCH_SIZE;
-use parquet::basic::Type;
+use parquet::arrow::arrow_reader::{
+    ArrowReaderOptions, DEFAULT_BATCH_SIZE, ParquetRecordBatchReaderBuilder,
+};
+use parquet::basic::{Compression, Type};
 use parquet::data_type::{ByteArray, FixedLenByteArrayType};
+use parquet::file::properties::WriterProperties;
 use parquet::util::{DataPageBuilder, DataPageBuilderImpl, 
InMemoryPageIterator};
 use parquet::{
     arrow::array_reader::ArrayReader,
@@ -2614,5 +2620,72 @@ fn add_benches(c: &mut Criterion) {
     group.finish();
 }
 
-criterion_group!(benches, add_benches, decimal_benches, float16_benches,);
+fn bench_plain_string_to_dict(c: &mut Criterion) {
+    fn make_parquet(num_rows: usize, cardinality: usize) -> Bytes {
+        let schema = Arc::new(Schema::new(vec![Field::new("s", DataType::Utf8, 
false)]));
+        let values: StringArray = (0..num_rows)
+            .map(|i| Some(format!("{:032}", i % cardinality)))
+            .collect();
+        let batch = RecordBatch::try_new(Arc::clone(&schema), 
vec![Arc::new(values) as _]).unwrap();
+        let props = WriterProperties::builder()
+            .set_compression(Compression::UNCOMPRESSED)
+            .set_dictionary_enabled(false)
+            .set_encoding(Encoding::PLAIN)
+            .build();
+        let mut buf = Vec::new();
+        let mut writer = ArrowWriter::try_new(&mut buf, schema, 
Some(props)).unwrap();
+        writer.write(&batch).unwrap();
+        writer.close().unwrap();
+        Bytes::from(buf)
+    }
+
+    let num_rows = 8192 * 8;
+    let dict_schema: SchemaRef = Arc::new(Schema::new(vec![Field::new(
+        "s",
+        DataType::Dictionary(Box::new(DataType::Int32), 
Box::new(DataType::Utf8)),
+        false,
+    )]));
+
+    let high_card = make_parquet(num_rows, num_rows); // every value unique
+    let med_card_1 = make_parquet(num_rows, 1_000); // 1 000 distinct values
+    let med_card_2 = make_parquet(num_rows, 100); //  100 distinct values
+    let low_card = make_parquet(num_rows, 10); // 10 distinct values
+
+    let mut group = 
c.benchmark_group("arrow_array_reader/PlainStringToDictionary");
+
+    for (name, data) in [
+        ("high cardinality", high_card),
+        ("medium cardinality 1", med_card_1),
+        ("medium cardinality 2", med_card_2),
+        ("low cardinality", low_card),
+    ] {
+        let schema = Arc::clone(&dict_schema);
+        group.bench_function(name, |b| {
+            b.iter(|| {
+                let opts = 
ArrowReaderOptions::new().with_schema(Arc::clone(&schema));
+                let reader =
+                    
ParquetRecordBatchReaderBuilder::try_new_with_options(data.clone(), opts)
+                        .unwrap()
+                        .build()
+                        .unwrap();
+                let mut count = 0usize;
+
+                for batch in reader {
+                    count += batch.unwrap().num_rows();
+                }
+                assert_eq!(count, num_rows);
+            });
+        });
+    }
+
+    group.finish();
+}
+
+criterion_group!(
+    benches,
+    add_benches,
+    decimal_benches,
+    float16_benches,
+    bench_plain_string_to_dict,
+);
 criterion_main!(benches);

Reply via email to