Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log and round function planning with second argument as int64 #173

Open
wants to merge 4 commits into
base: cubesql-3-04-2022
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions datafusion/core/tests/sql/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,61 @@ 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::<Vec<&str>>());
}};
}

#[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(())
}
4 changes: 4 additions & 0 deletions datafusion/expr/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
Expand All @@ -567,6 +569,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(),
Expand Down
Loading