This is an automated email from the ASF dual-hosted git repository.
remziy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 928032faa Fail if field lengths are not same in INTERSECT and EXPECT
(#3674)
928032faa is described below
commit 928032faa06f1fc0f6f1add8106dc7ac1d976c3a
Author: askoa <[email protected]>
AuthorDate: Sat Oct 1 19:24:53 2022 -0400
Fail if field lengths are not same in INTERSECT and EXPECT (#3674)
* fail if field lengths are not same in INTERSECT and EXPECT
* incorporate PR comment
* move test per PR comment
Co-authored-by: askoa <askoa@local>
---
datafusion/expr/src/logical_plan/builder.rs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/datafusion/expr/src/logical_plan/builder.rs
b/datafusion/expr/src/logical_plan/builder.rs
index 3ceb0f5f8..6b396b0d6 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -781,6 +781,16 @@ impl LogicalPlanBuilder {
join_type: JoinType,
is_all: bool,
) -> Result<LogicalPlan> {
+ let left_len = left_plan.schema().fields().len();
+ let right_len = right_plan.schema().fields().len();
+
+ if left_len != right_len {
+ return Err(DataFusionError::Plan(format!(
+ "INTERSECT/EXCEPT query must have the same number of columns.
Left is {} and right is {}.",
+ left_len, right_len
+ )));
+ }
+
let join_keys = left_plan
.schema()
.fields()
@@ -1417,4 +1427,21 @@ mod tests {
]);
table_scan(Some(name), &schema, None)?.build()
}
+
+ #[test]
+ fn plan_builder_intersect_different_num_columns_error() -> Result<()> {
+ let plan1 = table_scan(None, &employee_schema(), Some(vec![3]))?;
+
+ let plan2 = table_scan(None, &employee_schema(), Some(vec![3, 4]))?;
+
+ let expected = "Error during planning: INTERSECT/EXCEPT query must
have the same number of columns. \
+ Left is 1 and right is 2.";
+ let err_msg1 =
+ LogicalPlanBuilder::intersect(plan1.build()?, plan2.build()?, true)
+ .unwrap_err();
+
+ assert_eq!(err_msg1.to_string(), expected);
+
+ Ok(())
+ }
}