@@ -24,6 +24,7 @@ use crate::execution::dql::join::joins_nullable;
2424use crate :: expression:: agg:: AggKind ;
2525use crate :: expression:: { AliasType , BinaryOperator } ;
2626use crate :: planner:: operator:: aggregate:: AggregateOperator ;
27+ use crate :: planner:: operator:: except:: ExceptOperator ;
2728use crate :: planner:: operator:: function_scan:: FunctionScanOperator ;
2829use crate :: planner:: operator:: insert:: InsertOperator ;
2930use crate :: planner:: operator:: join:: JoinCondition ;
@@ -181,56 +182,83 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
181182 }
182183 true
183184 } ;
184- match ( op, is_all) {
185- ( SetOperator :: Union , true ) => {
186- let left_schema = left_plan. output_schema ( ) ;
187- let right_schema = right_plan. output_schema ( ) ;
188-
189- if !fn_eq ( left_schema, right_schema) {
190- return Err ( DatabaseError :: MisMatch (
191- "the output types on the left" ,
192- "the output types on the right" ,
193- ) ) ;
185+
186+ let left_schema = left_plan. output_schema ( ) ;
187+ let right_schema = right_plan. output_schema ( ) ;
188+
189+ if !fn_eq ( left_schema, right_schema) {
190+ return Err ( DatabaseError :: MisMatch (
191+ "the output types on the left" ,
192+ "the output types on the right" ,
193+ ) ) ;
194+ }
195+
196+ match op {
197+ SetOperator :: Union => {
198+ if is_all {
199+ Ok ( UnionOperator :: build (
200+ left_schema. clone ( ) ,
201+ right_schema. clone ( ) ,
202+ left_plan,
203+ right_plan,
204+ ) )
205+ } else {
206+ let distinct_exprs = left_schema
207+ . iter ( )
208+ . cloned ( )
209+ . map ( ScalarExpression :: ColumnRef )
210+ . collect_vec ( ) ;
211+
212+ let union_op = Operator :: Union ( UnionOperator {
213+ left_schema_ref : left_schema. clone ( ) ,
214+ _right_schema_ref : right_schema. clone ( ) ,
215+ } ) ;
216+
217+ Ok ( self . bind_distinct (
218+ LogicalPlan :: new (
219+ union_op,
220+ Childrens :: Twins {
221+ left : left_plan,
222+ right : right_plan,
223+ } ,
224+ ) ,
225+ distinct_exprs,
226+ ) )
194227 }
195- Ok ( UnionOperator :: build (
196- left_schema. clone ( ) ,
197- right_schema. clone ( ) ,
198- left_plan,
199- right_plan,
200- ) )
201228 }
202- ( SetOperator :: Union , false ) => {
203- let left_schema = left_plan. output_schema ( ) ;
204- let right_schema = right_plan. output_schema ( ) ;
205-
206- if !fn_eq ( left_schema, right_schema) {
207- return Err ( DatabaseError :: MisMatch (
208- "the output types on the left" ,
209- "the output types on the right" ,
210- ) ) ;
229+ SetOperator :: Except => {
230+ if is_all {
231+ Ok ( ExceptOperator :: build (
232+ left_schema. clone ( ) ,
233+ right_schema. clone ( ) ,
234+ left_plan,
235+ right_plan,
236+ ) )
237+ } else {
238+ let distinct_exprs = left_schema
239+ . iter ( )
240+ . cloned ( )
241+ . map ( ScalarExpression :: ColumnRef )
242+ . collect_vec ( ) ;
243+
244+ let except_op = Operator :: Except ( ExceptOperator {
245+ left_schema_ref : left_schema. clone ( ) ,
246+ _right_schema_ref : right_schema. clone ( ) ,
247+ } ) ;
248+
249+ Ok ( self . bind_distinct (
250+ LogicalPlan :: new (
251+ except_op,
252+ Childrens :: Twins {
253+ left : left_plan,
254+ right : right_plan,
255+ } ,
256+ ) ,
257+ distinct_exprs,
258+ ) )
211259 }
212- let union_op = Operator :: Union ( UnionOperator {
213- left_schema_ref : left_schema. clone ( ) ,
214- _right_schema_ref : right_schema. clone ( ) ,
215- } ) ;
216- let distinct_exprs = left_schema
217- . iter ( )
218- . cloned ( )
219- . map ( ScalarExpression :: ColumnRef )
220- . collect_vec ( ) ;
221-
222- Ok ( self . bind_distinct (
223- LogicalPlan :: new (
224- union_op,
225- Childrens :: Twins {
226- left : left_plan,
227- right : right_plan,
228- } ,
229- ) ,
230- distinct_exprs,
231- ) )
232260 }
233- ( set_operator, _ ) => Err ( DatabaseError :: UnsupportedStmt ( format ! (
261+ set_operator => Err ( DatabaseError :: UnsupportedStmt ( format ! (
234262 "set operator: {:?}" ,
235263 set_operator
236264 ) ) ) ,
0 commit comments