This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 91d2886d74 fix(substrait): disallow union with a single input (#13023)
91d2886d74 is described below

commit 91d2886d7494c1966c5a05876b26f09f47a5e1c2
Author: Tornike Gurgenidze <[email protected]>
AuthorDate: Tue Oct 22 19:07:57 2024 +0400

    fix(substrait): disallow union with a single input (#13023)
    
    * fix(substrait): disallow union with a single input
    
    * flip if condition
---
 datafusion/substrait/src/logical_plan/consumer.rs | 98 ++++++++---------------
 1 file changed, 34 insertions(+), 64 deletions(-)

diff --git a/datafusion/substrait/src/logical_plan/consumer.rs 
b/datafusion/substrait/src/logical_plan/consumer.rs
index 5f1824bc4b..8a8d195507 100644
--- a/datafusion/substrait/src/logical_plan/consumer.rs
+++ b/datafusion/substrait/src/logical_plan/consumer.rs
@@ -937,72 +937,42 @@ pub async fn from_substrait_rel(
             }
         }
         Some(RelType::Set(set)) => match set_rel::SetOp::try_from(set.op) {
-            Ok(set_op) => match set_op {
-                set_rel::SetOp::UnionAll => {
-                    if !set.inputs.is_empty() {
-                        union_rels(&set.inputs, ctx, extensions, true).await
-                    } else {
-                        not_impl_err!("Union relation requires at least one 
input")
-                    }
-                }
-                set_rel::SetOp::UnionDistinct => {
-                    if !set.inputs.is_empty() {
-                        union_rels(&set.inputs, ctx, extensions, false).await
-                    } else {
-                        not_impl_err!("Union relation requires at least one 
input")
-                    }
-                }
-                set_rel::SetOp::IntersectionPrimary => {
-                    if set.inputs.len() >= 2 {
-                        LogicalPlanBuilder::intersect(
-                            from_substrait_rel(ctx, &set.inputs[0], 
extensions).await?,
-                            union_rels(&set.inputs[1..], ctx, extensions, 
true).await?,
-                            false,
-                        )
-                    } else {
-                        not_impl_err!(
-                            "Primary Intersect relation requires at least two 
inputs"
-                        )
-                    }
-                }
-                set_rel::SetOp::IntersectionMultiset => {
-                    if set.inputs.len() >= 2 {
-                        intersect_rels(&set.inputs, ctx, extensions, 
false).await
-                    } else {
-                        not_impl_err!(
-                            "Multiset Intersect relation requires at least two 
inputs"
-                        )
-                    }
-                }
-                set_rel::SetOp::IntersectionMultisetAll => {
-                    if set.inputs.len() >= 2 {
-                        intersect_rels(&set.inputs, ctx, extensions, 
true).await
-                    } else {
-                        not_impl_err!(
-                            "MultisetAll Intersect relation requires at least 
two inputs"
-                        )
-                    }
-                }
-                set_rel::SetOp::MinusPrimary => {
-                    if set.inputs.len() >= 2 {
-                        except_rels(&set.inputs, ctx, extensions, false).await
-                    } else {
-                        not_impl_err!(
-                            "Primary Minus relation requires at least two 
inputs"
-                        )
-                    }
-                }
-                set_rel::SetOp::MinusPrimaryAll => {
-                    if set.inputs.len() >= 2 {
-                        except_rels(&set.inputs, ctx, extensions, true).await
-                    } else {
-                        not_impl_err!(
-                            "PrimaryAll Minus relation requires at least two 
inputs"
-                        )
+            Ok(set_op) => {
+                if set.inputs.len() < 2 {
+                    substrait_err!("Set operation requires at least two 
inputs")
+                } else {
+                    match set_op {
+                        set_rel::SetOp::UnionAll => {
+                            union_rels(&set.inputs, ctx, extensions, 
true).await
+                        }
+                        set_rel::SetOp::UnionDistinct => {
+                            union_rels(&set.inputs, ctx, extensions, 
false).await
+                        }
+                        set_rel::SetOp::IntersectionPrimary => {
+                            LogicalPlanBuilder::intersect(
+                                from_substrait_rel(ctx, &set.inputs[0], 
extensions)
+                                    .await?,
+                                union_rels(&set.inputs[1..], ctx, extensions, 
true)
+                                    .await?,
+                                false,
+                            )
+                        }
+                        set_rel::SetOp::IntersectionMultiset => {
+                            intersect_rels(&set.inputs, ctx, extensions, 
false).await
+                        }
+                        set_rel::SetOp::IntersectionMultisetAll => {
+                            intersect_rels(&set.inputs, ctx, extensions, 
true).await
+                        }
+                        set_rel::SetOp::MinusPrimary => {
+                            except_rels(&set.inputs, ctx, extensions, 
false).await
+                        }
+                        set_rel::SetOp::MinusPrimaryAll => {
+                            except_rels(&set.inputs, ctx, extensions, 
true).await
+                        }
+                        _ => not_impl_err!("Unsupported set operator: 
{set_op:?}"),
                     }
                 }
-                _ => not_impl_err!("Unsupported set operator: {set_op:?}"),
-            },
+            }
             Err(e) => not_impl_err!("Invalid set operation type {}: {e}", 
set.op),
         },
         Some(RelType::ExtensionLeaf(extension)) => {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to