neilconway opened a new issue, #10860:
URL: https://github.com/apache/arrow-rs/issues/10860

   ### 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
   
   ```rust
   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_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to