File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
datafusion/expr/src/logical_plan Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -781,6 +781,16 @@ impl LogicalPlanBuilder {
781
781
join_type : JoinType ,
782
782
is_all : bool ,
783
783
) -> Result < LogicalPlan > {
784
+ let left_len = left_plan. schema ( ) . fields ( ) . len ( ) ;
785
+ let right_len = right_plan. schema ( ) . fields ( ) . len ( ) ;
786
+
787
+ if left_len != right_len {
788
+ return Err ( DataFusionError :: Plan ( format ! (
789
+ "INTERSECT/EXCEPT query must have the same number of columns. Left is {} and right is {}." ,
790
+ left_len, right_len
791
+ ) ) ) ;
792
+ }
793
+
784
794
let join_keys = left_plan
785
795
. schema ( )
786
796
. fields ( )
@@ -1417,4 +1427,21 @@ mod tests {
1417
1427
] ) ;
1418
1428
table_scan ( Some ( name) , & schema, None ) ?. build ( )
1419
1429
}
1430
+
1431
+ #[ test]
1432
+ fn plan_builder_intersect_different_num_columns_error ( ) -> Result < ( ) > {
1433
+ let plan1 = table_scan ( None , & employee_schema ( ) , Some ( vec ! [ 3 ] ) ) ?;
1434
+
1435
+ let plan2 = table_scan ( None , & employee_schema ( ) , Some ( vec ! [ 3 , 4 ] ) ) ?;
1436
+
1437
+ let expected = "Error during planning: INTERSECT/EXCEPT query must have the same number of columns. \
1438
+ Left is 1 and right is 2.";
1439
+ let err_msg1 =
1440
+ LogicalPlanBuilder :: intersect ( plan1. build ( ) ?, plan2. build ( ) ?, true )
1441
+ . unwrap_err ( ) ;
1442
+
1443
+ assert_eq ! ( err_msg1. to_string( ) , expected) ;
1444
+
1445
+ Ok ( ( ) )
1446
+ }
1420
1447
}
You can’t perform that action at this time.
0 commit comments