From 884512c4a352e2ea9b6d11a18ce570347f690a29 Mon Sep 17 00:00:00 2001 From: Raja sudhan Date: Mon, 4 Nov 2024 20:41:00 +0530 Subject: [PATCH 1/4] fix: round function planning for (float64,int64) --- datafusion/expr/src/function.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datafusion/expr/src/function.rs b/datafusion/expr/src/function.rs index e6cdfa428f7b..701fff111503 100644 --- a/datafusion/expr/src/function.rs +++ b/datafusion/expr/src/function.rs @@ -567,6 +567,8 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature { TypeSignature::Exact(vec![DataType::Float64]), TypeSignature::Exact(vec![DataType::Float32]), // NOTE: stub, won't execute + TypeSignature::Exact(vec![DataType::Float64, DataType::Int64]), + TypeSignature::Exact(vec![DataType::Decimal(38, 10), DataType::Int64]), TypeSignature::Exact(vec![DataType::Decimal(38, 10), DataType::Int32]), ], fun.volatility(), From 3a3ce89250330096bb4fd5c1b5b1b03cff168799 Mon Sep 17 00:00:00 2001 From: Raja sudhan Date: Mon, 4 Nov 2024 20:56:20 +0530 Subject: [PATCH 2/4] fix: add integer signatures for log function --- datafusion/expr/src/function.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datafusion/expr/src/function.rs b/datafusion/expr/src/function.rs index 701fff111503..a3dad8f70dfc 100644 --- a/datafusion/expr/src/function.rs +++ b/datafusion/expr/src/function.rs @@ -559,6 +559,8 @@ pub fn signature(fun: &BuiltinScalarFunction) -> Signature { DataType::Decimal(38, 10), DataType::Decimal(38, 10), ]), + TypeSignature::Exact(vec![DataType::Decimal(38, 10), DataType::Int64]), + TypeSignature::Exact(vec![DataType::Float64, DataType::Int64]), ], fun.volatility(), ), From 3485f24f7895673c6f632e130ac4b762bfafd18b Mon Sep 17 00:00:00 2001 From: Raja sudhan Date: Thu, 14 Nov 2024 23:55:40 +0530 Subject: [PATCH 3/4] test: add tests for log and round function planning with two args --- datafusion/core/tests/sql/functions.rs | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index 517e7f1863c7..ce7c3bc68f84 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -610,3 +610,66 @@ async fn pi_function() -> Result<()> { assert_batches_eq!(expected, &actual); Ok(()) } + +macro_rules! assert_logical_plan { + ($ctx:expr, $udf_call:expr, $expected:expr) => { + { + let sql = format!("SELECT {}", $udf_call); + let logical_plan = $ctx.create_logical_plan(&sql)?; + let formatted = format!("{:?}", logical_plan); + assert_eq!($expected, formatted.split("\n").collect::>()); + } + }; +} + +#[tokio::test] +async fn test_log_round_logical_plan() -> Result<()> { + let ctx = SessionContext::new(); + + assert_logical_plan!( + ctx, + "log(2.0, 2)", + vec![ + "Projection: log(Float64(2), Int64(2))", + " EmptyRelation", + ] + ); + + assert_logical_plan!( + ctx, + "log(2::Decimal(38,10), 2::Decimal(38,10))", + vec![ + "Projection: log(CAST(Int64(2) AS Decimal(38, 10)), CAST(Int64(2) AS Decimal(38, 10)))", + " EmptyRelation", + ] + ); + + assert_logical_plan!( + ctx, + "log(2::Decimal(38,10), 2)", + vec![ + "Projection: log(CAST(Int64(2) AS Decimal(38, 10)), Int64(2))", + " EmptyRelation", + ] + ); + + assert_logical_plan!( + ctx, + "round(5.7, 2)", + vec![ + "Projection: round(Float64(5.7), Int64(2))", + " EmptyRelation", + ] + ); + + assert_logical_plan!( + ctx, + "round(5.7::Decimal(38,10), 2)", + vec![ + "Projection: round(CAST(Float64(5.7) AS Decimal(38, 10)), Int64(2))", + " EmptyRelation", + ] + ); + + Ok(()) +} From 3671fc19034a5b701e16928bb79f1bf9ae4db2b7 Mon Sep 17 00:00:00 2001 From: droidraja Date: Wed, 20 Nov 2024 13:57:21 +0530 Subject: [PATCH 4/4] reformat: run cargo fmt --- datafusion/core/tests/sql/functions.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs index ce7c3bc68f84..de2b04ba34d3 100644 --- a/datafusion/core/tests/sql/functions.rs +++ b/datafusion/core/tests/sql/functions.rs @@ -612,14 +612,12 @@ async fn pi_function() -> Result<()> { } macro_rules! assert_logical_plan { - ($ctx:expr, $udf_call:expr, $expected:expr) => { - { - let sql = format!("SELECT {}", $udf_call); - let logical_plan = $ctx.create_logical_plan(&sql)?; - let formatted = format!("{:?}", logical_plan); - assert_eq!($expected, formatted.split("\n").collect::>()); - } - }; + ($ctx:expr, $udf_call:expr, $expected:expr) => {{ + let sql = format!("SELECT {}", $udf_call); + let logical_plan = $ctx.create_logical_plan(&sql)?; + let formatted = format!("{:?}", logical_plan); + assert_eq!($expected, formatted.split("\n").collect::>()); + }}; } #[tokio::test] @@ -629,10 +627,7 @@ async fn test_log_round_logical_plan() -> Result<()> { assert_logical_plan!( ctx, "log(2.0, 2)", - vec![ - "Projection: log(Float64(2), Int64(2))", - " EmptyRelation", - ] + vec!["Projection: log(Float64(2), Int64(2))", " EmptyRelation",] ); assert_logical_plan!(