Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Incorrect statistics read for i8 i16 columns in parquet #10629

Merged
merged 4 commits into from
May 23, 2024
Merged
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
28 changes: 22 additions & 6 deletions datafusion/core/src/datasource/physical_plan/parquet/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ macro_rules! get_statistic {
*scale,
))
}
Some(DataType::Int8) => {
Some(ScalarValue::Int8(Some((*s.$func()).try_into().unwrap())))
}
Some(DataType::Int16) => {
Some(ScalarValue::Int16(Some((*s.$func()).try_into().unwrap())))
}
_ => Some(ScalarValue::Int32(Some(*s.$func()))),
}
}
Expand Down Expand Up @@ -365,8 +371,8 @@ mod test {
use super::*;
use arrow_array::{
new_null_array, Array, BinaryArray, BooleanArray, Decimal128Array, Float32Array,
Float64Array, Int32Array, Int64Array, RecordBatch, StringArray, StructArray,
TimestampNanosecondArray,
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, RecordBatch,
StringArray, StructArray, TimestampNanosecondArray,
};
use arrow_schema::{Field, SchemaRef};
use bytes::Bytes;
Expand Down Expand Up @@ -786,13 +792,13 @@ mod test {
})
.with_column(ExpectedColumn {
name: "tinyint_col",
expected_min: i32_array([Some(0)]),
expected_max: i32_array([Some(9)]),
expected_min: i8_array([Some(0)]),
expected_max: i8_array([Some(9)]),
})
.with_column(ExpectedColumn {
name: "smallint_col",
expected_min: i32_array([Some(0)]),
expected_max: i32_array([Some(9)]),
expected_min: i16_array([Some(0)]),
expected_max: i16_array([Some(9)]),
})
.with_column(ExpectedColumn {
name: "int_col",
Expand Down Expand Up @@ -1018,6 +1024,16 @@ mod test {
Arc::new(array)
}

fn i8_array(input: impl IntoIterator<Item = Option<i8>>) -> ArrayRef {
let array: Int8Array = input.into_iter().collect();
Arc::new(array)
}

fn i16_array(input: impl IntoIterator<Item = Option<i16>>) -> ArrayRef {
let array: Int16Array = input.into_iter().collect();
Arc::new(array)
}

fn i32_array(input: impl IntoIterator<Item = Option<i32>>) -> ArrayRef {
let array: Int32Array = input.into_iter().collect();
Arc::new(array)
Expand Down
2 changes: 0 additions & 2 deletions datafusion/core/tests/parquet/arrow_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ async fn test_int_32() {
// Note that the file has 4 columns named "i8", "i16", "i32", "i64".
// - The tests on column i32 and i64 passed.
// - The tests on column i8 and i16 failed.
#[ignore]
#[tokio::test]
async fn test_int_16() {
// This creates a parquet files of 4 columns named "i8", "i16", "i32", "i64"
Expand Down Expand Up @@ -419,7 +418,6 @@ async fn test_int_16() {

// BUG (same as above): ignore this test for now
// https://github.com/apache/datafusion/issues/10585
#[ignore]
#[tokio::test]
async fn test_int_8() {
// This creates a parquet files of 4 columns named "i8", "i16", "i32", "i64"
Expand Down