Skip to content

Parquet writer produces wrong min/max statistics for BYTE_ARRAY DECIMAL columns #10860

Closed

Description

@neilconway

Describe the bug

When a BYTE_ARRAY DECIMAL column contains values whose encodings have different byte lengths, the written row-group/page statistics can be wrong; see repro for example (min/max swapped).

To Reproduce

use parquet::basic::{ConvertedType, Repetition, Type as PhysicalType};
use parquet::data_type::{ByteArray, ByteArrayType};
use parquet::file::properties::WriterProperties;
use parquet::file::reader::FileReader;
use parquet::file::serialized_reader::SerializedFileReader;
use parquet::file::writer::SerializedFileWriter;
use parquet::schema::types::Type;
use std::fs::File;
use std::sync::Arc;

let field = Type::primitive_type_builder("c", PhysicalType::BYTE_ARRAY)
    .with_repetition(Repetition::REQUIRED)
    .with_converted_type(ConvertedType::DECIMAL)
    .with_precision(8)
    .with_scale(0)
    .build()
    .unwrap();
let schema = Arc::new(
    Type::group_type_builder("schema")
        .with_fields(vec![Arc::new(field)])
        .build()
        .unwrap(),
);

let file = File::create("/tmp/repro.parquet").unwrap();
let mut writer =
    SerializedFileWriter::new(file, schema, Arc::new(WriterProperties::builder().build())).unwrap();
let mut rg = writer.next_row_group().unwrap();
let mut col = rg.next_column().unwrap().unwrap();
// minimal big-endian two's-complement: 255 and 32768
let values = vec![
    ByteArray::from(vec![0x00u8, 0xFF]),       // 255
    ByteArray::from(vec![0x00u8, 0x80, 0x00]), // 32768
];
col.typed::<ByteArrayType>().write_batch(&values, None, None).unwrap();
col.close().unwrap();
rg.close().unwrap();
writer.close().unwrap();

let reader = SerializedFileReader::new(File::open("/tmp/repro.parquet").unwrap()).unwrap();
let stats = reader.metadata().row_group(0).column(0).statistics().unwrap();
println!("{stats:?}");
// min: Some(b"\0\x80\0") (= 32768), max: Some(b"\0\xff") (= 255),
// max_value_exact: true, min_value_exact: true
// expected: min = 255, max = 32768

Expected behavior

No response

Additional context

No response

Activity

  1. added theissue type on Aug 26, 2026
  2. added
    bug
    on Aug 26, 2026
  3. neilconway commented on Aug 26, 2026

    @neilconway
    ContributorAuthor

    take

  4. added a commit that references this issue on Aug 27, 2026
    4cc296b
  5. added a commit that references this issue on Sep 2, 2026
    c40bf04
  6. added 3 commits that reference this issue on Sep 18, 2026
    0d7a11c
    fa16312
    7758af4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions