You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/06 10:28:08 UTC
[GitHub] [arrow-datafusion] alamb commented on a change in pull request #513: Implement constant folding for CAST
alamb commented on a change in pull request #513:
URL: https://github.com/apache/arrow-datafusion/pull/513#discussion_r646110743
##########
File path: datafusion/src/optimizer/constant_folding.rs
##########
@@ -724,6 +744,44 @@ mod tests {
assert_eq!(expected, actual);
}
+ #[test]
+ fn cast_expr() {
+ let table_scan = test_table_scan().unwrap();
+ let proj = vec![Expr::Cast {
+ expr: Box::new(Expr::Literal(ScalarValue::Utf8(Some("0".to_string())))),
+ data_type: DataType::Int32,
+ }];
+ let plan = LogicalPlanBuilder::from(&table_scan)
+ .project(proj)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ let expected = "Projection: Int32(0)\
+ \n TableScan: test projection=None";
+ let actual = get_optimized_plan_formatted(&plan, &chrono::Utc::now());
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn cast_expr_wrong_arg() {
+ let table_scan = test_table_scan().unwrap();
+ let proj = vec![Expr::Cast {
+ expr: Box::new(Expr::Literal(ScalarValue::Utf8(Some("".to_string())))),
+ data_type: DataType::Int32,
+ }];
+ let plan = LogicalPlanBuilder::from(&table_scan)
+ .project(proj)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ let expected = "Projection: Int32(NULL)\
Review comment:
👍
##########
File path: datafusion/src/optimizer/constant_folding.rs
##########
@@ -724,6 +744,44 @@ mod tests {
assert_eq!(expected, actual);
}
+ #[test]
+ fn cast_expr() {
+ let table_scan = test_table_scan().unwrap();
+ let proj = vec![Expr::Cast {
+ expr: Box::new(Expr::Literal(ScalarValue::Utf8(Some("0".to_string())))),
+ data_type: DataType::Int32,
+ }];
+ let plan = LogicalPlanBuilder::from(&table_scan)
+ .project(proj)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ let expected = "Projection: Int32(0)\
Review comment:
this is beautiful ❤️ -- thank you @msathis
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org