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))