jacobBaumbach commented on a change in pull request #9806:
URL: https://github.com/apache/arrow/pull/9806#discussion_r610329683



##########
File path: rust/datafusion/src/physical_plan/union.rs
##########
@@ -60,15 +60,31 @@ impl ExecutionPlan for UnionExec {
 
     /// Output of the union is the combination of all output partitions of the 
inputs
     fn output_partitioning(&self) -> Partitioning {
-        // Sums all the output partitions
-        let num_partitions = self
-            .inputs
+        let intial: Option<Partitioning> = None;
+        self.inputs
             .iter()
-            .map(|plan| plan.output_partitioning().partition_count())
-            .sum();
-        // TODO: this loses partitioning info in case of same partitioning 
scheme (for example `Partitioning::Hash`)
-        // https://issues.apache.org/jira/browse/ARROW-11991
-        Partitioning::UnknownPartitioning(num_partitions)
+            .fold(intial, |acc, input| {
+                match (acc, input.output_partitioning()) {
+                    (None, partition) => Some(partition),
+                    (
+                        Some(Partitioning::Hash(mut vector_acc, size_acc)),
+                        Partitioning::Hash(vector, size),
+                    ) => {
+                        vector_acc.append(&mut vector.clone());

Review comment:
       So I added `PartialEq` and ensured all structs that impl `PhysicalExpr` 
also `impl PartialEq`.  For every occurrence of `Arc<dyn PhysicalExpr>` I get 
the following error, 132 times:
   
   ```bash
   error[E0038]: the trait `PhysicalExpr` cannot be made into an object
      --> datafusion/src/physical_plan/udf.rs:95:17
       |
   95  |     args: &[Arc<dyn PhysicalExpr>],
       |                 ^^^^^^^^^^^^^^^^ `PhysicalExpr` cannot be made into an 
object
       |
   note: for a trait to be "object safe" it needs to allow building a vtable to 
allow the call to be resolvable dynamically; for more information visit 
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>
      --> datafusion/src/physical_plan/mod.rs:188:57
       |
   188 | pub trait PhysicalExpr: Send + Sync + Display + Debug + PartialEq {
       |           ------------                                  ^^^^^^^^^ 
...because it uses `Self` as a type parameter
       |           |
       |           this trait cannot be made into an object...
   
   ```
   
   It appears that the inclusion of PartialEq makes it so `PhysicalExpr` 
doesn't play nicely with dynamic dispatch.  Due to PartialEq taking a type arg 
of `Self`, which can't be determined under dynamic dispatch.  I am not sure how 
to work around this.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to