From 9e5bc8c942556393c54006e49bf12091cd7f6f72 Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Wed, 12 Mar 2025 19:49:09 +0400 Subject: [PATCH] fix: Function expr names without arguments are plain function names Signed-off-by: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> --- datafusion/core/src/optimizer/simplify_expressions.rs | 4 ++-- datafusion/core/tests/sql/functions.rs | 2 +- datafusion/expr/src/expr.rs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/datafusion/core/src/optimizer/simplify_expressions.rs b/datafusion/core/src/optimizer/simplify_expressions.rs index 97012932b6fa..6bacc9133ddb 100644 --- a/datafusion/core/src/optimizer/simplify_expressions.rs +++ b/datafusion/core/src/optimizer/simplify_expressions.rs @@ -1860,7 +1860,7 @@ mod tests { // expect the same timestamp appears in both exprs let actual = get_optimized_plan_formatted(&plan, &time); let expected = format!( - "Projection: TimestampNanosecond({}, Some(\"UTC\")) AS now(), TimestampNanosecond({}, Some(\"UTC\")) AS t2\ + "Projection: TimestampNanosecond({}, Some(\"UTC\")) AS now, TimestampNanosecond({}, Some(\"UTC\")) AS t2\ \n TableScan: test projection=None", time.timestamp_nanos(), time.timestamp_nanos() @@ -1910,7 +1910,7 @@ mod tests { // Note that constant folder runs and folds the entire // expression down to a single constant (true) - let expected = "Filter: Boolean(true) AS CAST(now() AS Int64) < CAST(totimestamp(Utf8(\"2020-09-08T12:05:00+00:00\")) AS Int64) + Int32(50000)\ + let expected = "Filter: Boolean(true) AS CAST(now AS Int64) < CAST(totimestamp(Utf8(\"2020-09-08T12:05:00+00:00\")) AS Int64) + Int32(50000)\ \n TableScan: test projection=None"; let actual = get_optimized_plan_formatted(&plan, &time); diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index 517e7f1863c7..cfb16169da7b 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -602,7 +602,7 @@ async fn pi_function() -> Result<()> { let actual = execute_to_batches(&ctx, sql).await; let expected = vec![ "+-------------------+--------------------+--------------------+", - "| pi() | pi() / Int64(2) | pi() / Int64(3) |", + "| pi | pi / Int64(2) | pi / Int64(3) |", "+-------------------+--------------------+--------------------+", "| 3.141592653589793 | 1.5707963267948966 | 1.0471975511965976 |", "+-------------------+--------------------+--------------------+", diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index d380d9360a8d..19eb17711e9c 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -772,6 +772,9 @@ fn create_function_name( args: &[Expr], input_schema: &DFSchema, ) -> Result { + if !distinct && args.is_empty() { + return Ok(fun.to_ascii_lowercase()); + } let names: Vec = args .iter() .map(|e| create_name(e, input_schema))