jayzhan211 commented on code in PR #25074:
URL: https://github.com/apache/datafusion/pull/25074#discussion_r3999102348
##########
datafusion/optimizer/src/unions_to_filter.rs:
##########
@@ -406,12 +457,238 @@ mod tests {
ScalarUDF::new_from_impl(VolatileTestUdf).call(vec![])
}
+ #[test]
+ fn set_comparison_is_detected_as_subquery() {
+ let subquery =
LogicalPlanBuilder::from(test_table_scan_with_name("t2").unwrap())
+ .project(vec![col("b")])
+ .unwrap()
+ .build()
+ .unwrap();
+ let expr = Expr::SetComparison(SetComparison::new(
+ Box::new(col("a")),
+ Subquery {
+ subquery: Arc::new(subquery),
+ outer_ref_columns: vec![],
+ spans: Spans::new(),
+ },
+ Operator::Gt,
+ SetQuantifier::Any,
+ ));
+
+ assert!(expr_contains_subquery(&expr));
+ }
+
+ fn assert_not_rewritten(plan: LogicalPlan) {
+ let mut options = datafusion_common::config::ConfigOptions::default();
+ options.optimizer.enable_unions_to_filter = true;
+ let optimizer_ctx =
OptimizerContext::new_with_config_options(Arc::new(options));
+ let result = UnionsToFilter::new()
+ .rewrite(plan.clone(), &optimizer_ctx)
+ .unwrap();
+ assert!(!result.transformed);
+ assert_eq!(result.data, plan);
+ }
+
+ #[test]
+ fn rewrite_union_distinct_preserves_alias_below_filter() -> Result<()> {
+ let scan = test_table_scan_with_name("t").unwrap();
+ let left_source = LogicalPlanBuilder::from(scan.clone())
+ .alias("x")
+ .unwrap()
+ .build()
+ .unwrap();
+ let right_source = LogicalPlanBuilder::from(scan)
+ .alias("x")
+ .unwrap()
+ .build()
+ .unwrap();
+ let left = LogicalPlanBuilder::from(left_source)
+ .filter(col("x.a").eq(lit(1)))
+ .unwrap()
+ .project(vec![col("x.a")])
+ .unwrap()
+ .build()
+ .unwrap();
+ let right = LogicalPlanBuilder::from(right_source)
+ .filter(col("x.a").eq(lit(2)))
+ .unwrap()
+ .project(vec![col("x.a")])
+ .unwrap()
+ .build()
+ .unwrap();
+ let plan = LogicalPlanBuilder::from(left)
+ .union_distinct(right)
+ .unwrap()
+ .build()
+ .unwrap();
+
+ assert_optimized_plan_equal!(plan, @r"
+ Distinct:
+ Projection: x.a
+ Projection: x.a
+ Filter: x.a = Int32(1) OR x.a = Int32(2)
+ SubqueryAlias: x
+ TableScan: t
+ ")
+ .unwrap();
+ Ok(())
+ }
+
+ #[test]
+ fn rewrite_union_distinct_matching_computed_projection_below_filter() ->
Result<()> {
+ let scan = test_table_scan_with_name("prices").unwrap();
+ let left_source = LogicalPlanBuilder::from(scan.clone())
+ .project(vec![col("a").add(lit(100)).alias("amount")])
Review Comment:
`col("a") + lit(100)` without std::ops::Add
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]