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



##########
File path: datafusion/src/sql/planner.rs
##########
@@ -226,25 +226,25 @@ 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) => {

Review comment:
       that certainly looks nicer

##########
File path: datafusion/src/logical_plan/builder.rs
##########
@@ -715,6 +715,65 @@ impl LogicalPlanBuilder {
         }
     }
 
+    /// Process intersect set operator
+    pub(crate) fn intersect(
+        left_plan: LogicalPlan,
+        right_plan: LogicalPlan,
+        is_all: bool,
+    ) -> Result<LogicalPlan> {
+        LogicalPlanBuilder::intersect_or_except(
+            left_plan,
+            right_plan,
+            JoinType::Semi,
+            is_all,
+        )
+    }
+
+    /// Process except set operator
+    pub(crate) fn except(
+        left_plan: LogicalPlan,
+        right_plan: LogicalPlan,
+        is_all: bool,
+    ) -> Result<LogicalPlan> {
+        LogicalPlanBuilder::intersect_or_except(
+            left_plan,
+            right_plan,
+            JoinType::Anti,
+            is_all,
+        )
+    }
+
+    /// Process intersect or except
+    fn intersect_or_except(

Review comment:
       this is nice




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