Skip to content

Commit 3485f24

Browse files
committed
test: add tests for log and round function planning with two args
1 parent 3a3ce89 commit 3485f24

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

datafusion/core/tests/sql/functions.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,66 @@ async fn pi_function() -> Result<()> {
610610
assert_batches_eq!(expected, &actual);
611611
Ok(())
612612
}
613+
614+
macro_rules! assert_logical_plan {
615+
($ctx:expr, $udf_call:expr, $expected:expr) => {
616+
{
617+
let sql = format!("SELECT {}", $udf_call);
618+
let logical_plan = $ctx.create_logical_plan(&sql)?;
619+
let formatted = format!("{:?}", logical_plan);
620+
assert_eq!($expected, formatted.split("\n").collect::<Vec<&str>>());
621+
}
622+
};
623+
}
624+
625+
#[tokio::test]
626+
async fn test_log_round_logical_plan() -> Result<()> {
627+
let ctx = SessionContext::new();
628+
629+
assert_logical_plan!(
630+
ctx,
631+
"log(2.0, 2)",
632+
vec![
633+
"Projection: log(Float64(2), Int64(2))",
634+
" EmptyRelation",
635+
]
636+
);
637+
638+
assert_logical_plan!(
639+
ctx,
640+
"log(2::Decimal(38,10), 2::Decimal(38,10))",
641+
vec![
642+
"Projection: log(CAST(Int64(2) AS Decimal(38, 10)), CAST(Int64(2) AS Decimal(38, 10)))",
643+
" EmptyRelation",
644+
]
645+
);
646+
647+
assert_logical_plan!(
648+
ctx,
649+
"log(2::Decimal(38,10), 2)",
650+
vec![
651+
"Projection: log(CAST(Int64(2) AS Decimal(38, 10)), Int64(2))",
652+
" EmptyRelation",
653+
]
654+
);
655+
656+
assert_logical_plan!(
657+
ctx,
658+
"round(5.7, 2)",
659+
vec![
660+
"Projection: round(Float64(5.7), Int64(2))",
661+
" EmptyRelation",
662+
]
663+
);
664+
665+
assert_logical_plan!(
666+
ctx,
667+
"round(5.7::Decimal(38,10), 2)",
668+
vec![
669+
"Projection: round(CAST(Float64(5.7) AS Decimal(38, 10)), Int64(2))",
670+
" EmptyRelation",
671+
]
672+
);
673+
674+
Ok(())
675+
}

0 commit comments

Comments
 (0)