houqp commented on a change in pull request #1259:
URL: https://github.com/apache/arrow-datafusion/pull/1259#discussion_r744398111



##########
File path: datafusion/src/sql/planner.rs
##########
@@ -226,25 +226,45 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 let left_plan = self.set_expr_to_plan(left.as_ref(), None, 
ctes)?;
                 let right_plan = self.set_expr_to_plan(right.as_ref(), None, 
ctes)?;
                 match (op, all) {
-                (SetOperator::Union, true) => {
-                    union_with_alias(left_plan, right_plan, alias)
-                }
-                (SetOperator::Union, false) => {
-                    let union_plan = union_with_alias(left_plan, right_plan, 
alias)?;
-                    LogicalPlanBuilder::from(union_plan).distinct()?.build()
-                }
-                (SetOperator::Intersect, true) => {
-                    let join_keys = 
left_plan.schema().fields().iter().zip(right_plan.schema().fields().iter()).map(|(left_field,
 right_field)| ((Column::from_name(left_field.name())), 
(Column::from_name(right_field.name())))).unzip();
-                    
LogicalPlanBuilder::from(left_plan).join_detailed(&right_plan, JoinType::Semi, 
join_keys, true)?.build()
-                }
-                (SetOperator::Intersect, false) => {
-                    let join_keys = 
left_plan.schema().fields().iter().zip(right_plan.schema().fields().iter()).map(|(left_field,
 right_field)| ((Column::from_name(left_field.name())), 
(Column::from_name(right_field.name())))).unzip();
-                    
LogicalPlanBuilder::from(left_plan).distinct()?.join_detailed(&right_plan, 
JoinType::Semi, join_keys, true)?.build()
-                }
-                _ => Err(DataFusionError::NotImplemented(format!(
-                    "Only UNION ALL and UNION [DISTINCT] and INTERSECT and 
INTERSECT [DISTINCT] are supported, found {}",
-                    op
-                ))),
+                    (SetOperator::Union, true) => {
+                        union_with_alias(left_plan, right_plan, alias)
+                    }
+                    (SetOperator::Union, false) => {
+                        let union_plan = union_with_alias(left_plan, 
right_plan, alias)?;
+                        
LogicalPlanBuilder::from(union_plan).distinct()?.build()
+                    }
+                    (SetOperator::Intersect, true) => {
+                        LogicalPlanBuilder::intersect_or_except(
+                            left_plan,
+                            right_plan,
+                            JoinType::Semi,
+                            true,
+                        )
+                    }
+                    (SetOperator::Intersect, false) => {
+                        LogicalPlanBuilder::intersect_or_except(
+                            left_plan,
+                            right_plan,
+                            JoinType::Semi,
+                            false,
+                        )

Review comment:
       i think it would be cleaner to turn this and except into a simple public 
wrapper method in logical plan builder so users won't need to worry about which 
join type to pass in.




-- 
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]


Reply via email to