alamb commented on code in PR #10611:
URL: https://github.com/apache/datafusion/pull/10611#discussion_r1611465815
##########
datafusion/physical-expr/src/aggregate/median.rs:
##########
@@ -295,387 +295,3 @@ fn calculate_median<T: ArrowNumericType>(
Some(*median)
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::expressions::col;
- use crate::expressions::tests::aggregate;
- use crate::generic_test_distinct_op;
- use arrow::{array::*, datatypes::*};
-
- #[test]
- fn median_decimal() -> Result<()> {
- // test median
- let array: ArrayRef = Arc::new(
- (1..7)
- .map(Some)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
-
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(Some(3), 10, 4)
- )
- }
-
- #[test]
- fn median_decimal_with_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- (1..6)
- .map(|i| if i == 2 { None } else { Some(i) })
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(Some(3), 10, 4)
- )
- }
-
- #[test]
- fn median_decimal_all_nulls() -> Result<()> {
- // test median
- let array: ArrayRef = Arc::new(
- std::iter::repeat::<Option<i128>>(None)
- .take(6)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(None, 10, 4)
- )
- }
-
- #[test]
- fn median_i32_odd() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3_i32)
- )
- }
-
- #[test]
- fn median_i32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3_i32)
- )
- }
-
- #[test]
- fn median_i32_with_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![
- Some(1),
- None,
- Some(3),
- Some(4),
- Some(5),
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3i32)
- )
- }
-
- #[test]
- fn median_i32_all_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::Int32(None)
- )
- }
-
- #[test]
- fn median_u32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(UInt32Array::from(vec![1_u32, 2_u32, 3_u32, 4_u32,
5_u32]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- false,
- ScalarValue::from(3u32)
- )
- }
-
- #[test]
- fn median_u32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(UInt32Array::from(vec![
- 1_u32, 2_u32, 3_u32, 4_u32, 5_u32, 6_u32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- false,
- ScalarValue::from(3u32)
- )
- }
-
- #[test]
- fn median_f32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float32Array::from(vec![1_f32, 2_f32, 3_f32, 4_f32,
5_f32]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- false,
- ScalarValue::from(3_f32)
- )
- }
-
- #[test]
- fn median_f32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Float32Array::from(vec![
- 1_f32, 2_f32, 3_f32, 4_f32, 5_f32, 6_f32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- false,
- ScalarValue::from(3.5_f32)
- )
- }
-
- #[test]
- fn median_f64_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64, 4_f64,
5_f64]));
- generic_test_distinct_op!(
- a,
- DataType::Float64,
- Median,
- false,
- ScalarValue::from(3_f64)
- )
- }
-
- #[test]
- fn median_f64_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Float64Array::from(vec![
- 1_f64, 2_f64, 3_f64, 4_f64, 5_f64, 6_f64,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Float64,
- Median,
- false,
- ScalarValue::from(3.5_f64)
- )
- }
-
- #[test]
- fn distinct_median_decimal() -> Result<()> {
- let array: ArrayRef = Arc::new(
- vec![1, 1, 1, 1, 2, 3, 1, 1, 3]
- .into_iter()
- .map(Some)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
-
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(Some(2), 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_decimal_with_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- vec![Some(3), Some(1), None, Some(3), Some(2), Some(3), Some(3)]
- .into_iter()
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(Some(2), 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_decimal_all_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- std::iter::repeat::<Option<i128>>(None)
- .take(6)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(None, 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_i32_odd() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![2, 1, 1, 2, 1, 3]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2_i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 1, 3, 1, 1]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2_i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_with_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![
- Some(1),
- None,
- Some(1),
- Some(1),
- Some(3),
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_all_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::Int32(None)
- )
- }
-
- #[test]
- fn distinct_median_u32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(UInt32Array::from(vec![1_u32, 1_u32, 2_u32, 1_u32,
3_u32]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- true,
- ScalarValue::from(2u32)
- )
- }
-
- #[test]
- fn distinct_median_u32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(UInt32Array::from(vec![
- 1_u32, 1_u32, 1_u32, 1_u32, 3_u32, 3_u32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- true,
- ScalarValue::from(2u32)
- )
- }
-
- #[test]
- fn distinct_median_f32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float32Array::from(vec![3_f32, 2_f32, 1_f32, 1_f32,
1_f32]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- true,
- ScalarValue::from(2_f32)
- )
- }
-
- #[test]
- fn distinct_median_f32_even() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float32Array::from(vec![1_f32, 1_f32, 1_f32, 1_f32,
2_f32]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- true,
- ScalarValue::from(1.5_f32)
- )
- }
-
- #[test]
- fn distinct_median_f64_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float64Array::from(vec![1_f64, 1_f64, 1_f64, 2_f64,
3_f64]));
- generic_test_distinct_op!(
- a,
- DataType::Float64,
- Median,
- true,
- ScalarValue::from(2_f64)
- )
- }
-
- #[test]
- fn distinct_median_f64_even() -> Result<()> {
Review Comment:
I couldn't find a corresponding test for this in slt -- I woud expect to see
(1)(1)(1)(1)(2) and a median result of 1.5 but I didn't see any 🤔
##########
datafusion/physical-expr/src/aggregate/median.rs:
##########
@@ -295,387 +295,3 @@ fn calculate_median<T: ArrowNumericType>(
Some(*median)
}
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use crate::expressions::col;
- use crate::expressions::tests::aggregate;
- use crate::generic_test_distinct_op;
- use arrow::{array::*, datatypes::*};
-
- #[test]
- fn median_decimal() -> Result<()> {
- // test median
- let array: ArrayRef = Arc::new(
- (1..7)
- .map(Some)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
-
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(Some(3), 10, 4)
- )
- }
-
- #[test]
- fn median_decimal_with_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- (1..6)
- .map(|i| if i == 2 { None } else { Some(i) })
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(Some(3), 10, 4)
- )
- }
-
- #[test]
- fn median_decimal_all_nulls() -> Result<()> {
- // test median
- let array: ArrayRef = Arc::new(
- std::iter::repeat::<Option<i128>>(None)
- .take(6)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- false,
- ScalarValue::Decimal128(None, 10, 4)
- )
- }
-
- #[test]
- fn median_i32_odd() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3_i32)
- )
- }
-
- #[test]
- fn median_i32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5, 6]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3_i32)
- )
- }
-
- #[test]
- fn median_i32_with_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![
- Some(1),
- None,
- Some(3),
- Some(4),
- Some(5),
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::from(3i32)
- )
- }
-
- #[test]
- fn median_i32_all_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- false,
- ScalarValue::Int32(None)
- )
- }
-
- #[test]
- fn median_u32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(UInt32Array::from(vec![1_u32, 2_u32, 3_u32, 4_u32,
5_u32]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- false,
- ScalarValue::from(3u32)
- )
- }
-
- #[test]
- fn median_u32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(UInt32Array::from(vec![
- 1_u32, 2_u32, 3_u32, 4_u32, 5_u32, 6_u32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- false,
- ScalarValue::from(3u32)
- )
- }
-
- #[test]
- fn median_f32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float32Array::from(vec![1_f32, 2_f32, 3_f32, 4_f32,
5_f32]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- false,
- ScalarValue::from(3_f32)
- )
- }
-
- #[test]
- fn median_f32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Float32Array::from(vec![
- 1_f32, 2_f32, 3_f32, 4_f32, 5_f32, 6_f32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Float32,
- Median,
- false,
- ScalarValue::from(3.5_f32)
- )
- }
-
- #[test]
- fn median_f64_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64, 4_f64,
5_f64]));
- generic_test_distinct_op!(
- a,
- DataType::Float64,
- Median,
- false,
- ScalarValue::from(3_f64)
- )
- }
-
- #[test]
- fn median_f64_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Float64Array::from(vec![
- 1_f64, 2_f64, 3_f64, 4_f64, 5_f64, 6_f64,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Float64,
- Median,
- false,
- ScalarValue::from(3.5_f64)
- )
- }
-
- #[test]
- fn distinct_median_decimal() -> Result<()> {
- let array: ArrayRef = Arc::new(
- vec![1, 1, 1, 1, 2, 3, 1, 1, 3]
- .into_iter()
- .map(Some)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
-
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(Some(2), 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_decimal_with_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- vec![Some(3), Some(1), None, Some(3), Some(2), Some(3), Some(3)]
- .into_iter()
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(Some(2), 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_decimal_all_nulls() -> Result<()> {
- let array: ArrayRef = Arc::new(
- std::iter::repeat::<Option<i128>>(None)
- .take(6)
- .collect::<Decimal128Array>()
- .with_precision_and_scale(10, 4)?,
- );
- generic_test_distinct_op!(
- array,
- DataType::Decimal128(10, 4),
- Median,
- true,
- ScalarValue::Decimal128(None, 10, 4)
- )
- }
-
- #[test]
- fn distinct_median_i32_odd() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![2, 1, 1, 2, 1, 3]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2_i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 1, 3, 1, 1]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2_i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_with_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![
- Some(1),
- None,
- Some(1),
- Some(1),
- Some(3),
- ]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::from(2i32)
- )
- }
-
- #[test]
- fn distinct_median_i32_all_nulls() -> Result<()> {
- let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
- generic_test_distinct_op!(
- a,
- DataType::Int32,
- Median,
- true,
- ScalarValue::Int32(None)
- )
- }
-
- #[test]
- fn distinct_median_u32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(UInt32Array::from(vec![1_u32, 1_u32, 2_u32, 1_u32,
3_u32]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- true,
- ScalarValue::from(2u32)
- )
- }
-
- #[test]
- fn distinct_median_u32_even() -> Result<()> {
- let a: ArrayRef = Arc::new(UInt32Array::from(vec![
- 1_u32, 1_u32, 1_u32, 1_u32, 3_u32, 3_u32,
- ]));
- generic_test_distinct_op!(
- a,
- DataType::UInt32,
- Median,
- true,
- ScalarValue::from(2u32)
- )
- }
-
- #[test]
- fn distinct_median_f32_odd() -> Result<()> {
- let a: ArrayRef =
- Arc::new(Float32Array::from(vec![3_f32, 2_f32, 1_f32, 1_f32,
1_f32]));
Review Comment:
I don't see this pattern (3,2,1,1,1) reflected in the new tests either 🤔
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]