Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions parquet/benches/arrow_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use arrow::datatypes::*;
use arrow::util::bench_util::{create_f16_array, create_f32_array, create_f64_array};
use arrow::{record_batch::RecordBatch, util::data_gen::*};
use arrow_array::RecordBatchOptions;
use arrow_array::builder::StringDictionaryBuilder;
use parquet::arrow::ArrowSchemaConverter;
use parquet::errors::Result;
use parquet::file::properties::{WriterProperties, WriterVersion};
Expand Down Expand Up @@ -139,6 +140,43 @@ fn create_string_dictionary_bench_batch(
)?)
}

/// Creates a DictionaryArray with low cardinality (~15 unique values across
/// `size` rows). This simulates realistic categorical columns like status
/// codes, country codes, or ship modes where dictionary encoding excels.
fn create_string_dictionary_low_cardinality_bench_batch(size: usize) -> Result<RecordBatch> {
let categories = [
"DELIVERED",
"SHIPPED",
"PENDING",
"CANCELLED",
"RETURNED",
"PROCESSING",
"ON_HOLD",
"REFUNDED",
"BACKORDERED",
"IN_TRANSIT",
"CONFIRMED",
"DISPATCHED",
"FAILED",
"COMPLETED",
"UNKNOWN",
];
let mut builder = StringDictionaryBuilder::<Int32Type>::new();
for i in 0..size {
builder.append_value(categories[i % categories.len()]);
}
let dict = builder.finish();
let schema = Schema::new(vec![Field::new(
"_1",
DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8)),
false,
)]);
Ok(RecordBatch::try_new(
Arc::new(schema),
vec![Arc::new(dict)],
)?)
}

fn create_string_bench_batch_non_null(
size: usize,
null_density: f32,
Expand Down Expand Up @@ -399,6 +437,9 @@ fn create_batches() -> Vec<(&'static str, RecordBatch)> {
let batch = create_string_dictionary_bench_batch(BATCH_SIZE, 0.25, 0.75).unwrap();
batches.push(("string_dictionary", batch));

let batch = create_string_dictionary_low_cardinality_bench_batch(BATCH_SIZE).unwrap();
batches.push(("string_dictionary_low_cardinality", batch));

let batch = create_string_bench_batch_non_null(BATCH_SIZE, 0.25, 0.75).unwrap();
batches.push(("string_non_null", batch));

Expand Down
Loading
Loading