diff --git a/datafusion/core/src/dataframe/mod.rs b/datafusion/core/src/dataframe/mod.rs index cc1a63cc05f7..5fa65cb0da42 100644 --- a/datafusion/core/src/dataframe/mod.rs +++ b/datafusion/core/src/dataframe/mod.rs @@ -717,7 +717,10 @@ impl DataFrame { { let column = batchs[0].column_by_name(field.name()).unwrap(); - if field.data_type().is_numeric() { + + if column.data_type().is_null() { + Arc::new(StringArray::from(vec!["null"])) + } else if field.data_type().is_numeric() { cast(column, &DataType::Float64)? } else { cast(column, &DataType::Utf8)? diff --git a/datafusion/core/tests/dataframe/describe.rs b/datafusion/core/tests/dataframe/describe.rs index e446d71473be..9321481efbd2 100644 --- a/datafusion/core/tests/dataframe/describe.rs +++ b/datafusion/core/tests/dataframe/describe.rs @@ -102,8 +102,8 @@ async fn describe_null() -> Result<()> { "| null_count | 0 | 1 |", "| mean | null | null |", "| std | null | null |", - "| min | null | null |", - "| max | null | null |", + "| min | a | null |", + "| max | a | null |", "| median | null | null |", "+------------+------+------+" ]; diff --git a/datafusion/functions-aggregate/src/min_max.rs b/datafusion/functions-aggregate/src/min_max.rs index 18028e358b21..f19d6d767ba1 100644 --- a/datafusion/functions-aggregate/src/min_max.rs +++ b/datafusion/functions-aggregate/src/min_max.rs @@ -304,6 +304,7 @@ macro_rules! typed_min_max_batch { macro_rules! min_max_batch { ($VALUES:expr, $OP:ident) => {{ match $VALUES.data_type() { + DataType::Null => ScalarValue::Null, DataType::Decimal128(precision, scale) => { typed_min_max_batch!( $VALUES, @@ -579,6 +580,7 @@ macro_rules! interval_min_max { macro_rules! min_max { ($VALUE:expr, $DELTA:expr, $OP:ident) => {{ Ok(match ($VALUE, $DELTA) { + (ScalarValue::Null, ScalarValue::Null) => ScalarValue::Null, ( lhs @ ScalarValue::Decimal128(lhsv, lhsp, lhss), rhs @ ScalarValue::Decimal128(rhsv, rhsp, rhss) diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 8a5222143356..c68a6c345caa 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -5548,3 +5548,9 @@ set datafusion.explain.logical_plan_only = false; statement ok drop table employee_csv; + +# test null literal handling in supported aggregate functions +query I??III?T +select count(null), min(null), max(null), bit_and(NULL), bit_or(NULL), bit_xor(NULL), nth_value(NULL, 1), string_agg(NULL, ','); +---- +0 NULL NULL NULL NULL NULL NULL NULL \ No newline at end of file