This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 56be714eca Support NULL literal in Min/Max (#11812)
56be714eca is described below
commit 56be714ecaf0b0271d1c8a64cbc41d1dbc972228
Author: Xin Li <[email protected]>
AuthorDate: Thu Aug 8 13:40:06 2024 -0700
Support NULL literal in Min/Max (#11812)
* Support NULL literal in Min/Max
* Fix ut
* fix fmt
---------
Co-authored-by: Andrew Lamb <[email protected]>
---
datafusion/core/src/dataframe/mod.rs | 5 ++++-
datafusion/core/tests/dataframe/describe.rs | 4 ++--
datafusion/functions-aggregate/src/min_max.rs | 2 ++
datafusion/sqllogictest/test_files/aggregate.slt | 6 ++++++
4 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/datafusion/core/src/dataframe/mod.rs
b/datafusion/core/src/dataframe/mod.rs
index cc1a63cc05..5fa65cb0da 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 e446d71473..9321481efb 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 18028e358b..f19d6d767b 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 8a52221433..c68a6c345c 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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]