You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/02/17 07:35:16 UTC

[GitHub] HyukjinKwon commented on a change in pull request #23810: [SPARK-26901][SQL][R] Avoid to prune columns for vectorized gapply()

HyukjinKwon commented on a change in pull request #23810: [SPARK-26901][SQL][R] Avoid to prune columns for vectorized gapply()
URL: https://github.com/apache/spark/pull/23810#discussion_r257491764
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ##########
 @@ -651,6 +651,10 @@ object ColumnPruning extends Rule[LogicalPlan] {
     // Can't prune the columns on LeafNode
     case p @ Project(_, _: LeafNode) => p
 
+    // Vectorized gapply in R should not prune columns because all referred fields
+    // can be used within given R native function.
+    case p @ Project(_, _: FlatMapGroupsInRWithArrow) => p
 
 Review comment:
   There might be some more grouping columns. For example, 
   ```r
   df <- createDataFrame(mtcars)
   explain(count(groupBy(gapply(df,
                                c("gear", "hp"),
                                function(key, group) {
                                  data.frame(gear = key[[1]], disp = mean(group$disp))
                                },
                                structType("gear double, disp double")))), TRUE)
   ```
   
   Before:
   
   ```
   == Optimized Logical Plan ==
   Aggregate [count(1) AS count#42L]
   +- Project
      +- FlatMapGroupsInRWithArrow [StructField(mpg,DoubleType,true), StructField(cyl,DoubleType,true), StructField(disp,DoubleType,true), StructField(hp,DoubleType,true), StructField(drat,DoubleType,true), StructField(wt,DoubleType,true), StructField(qsec,DoubleType,true), StructField(vs,DoubleType,true), StructField(am,DoubleType,true), StructField(gear,DoubleType,true), StructField(carb,DoubleType,true)], [StructField(gear,DoubleType,true), StructField(disp,DoubleType,true)], createexternalrow(gear#9, hp#3, StructField(gear,DoubleType,true), StructField(hp,DoubleType,true)), [gear#9, hp#3]
         +- Project [hp#3, gear#9]
            +- LogicalRDD [mpg#0, cyl#1, disp#2, hp#3, drat#4, wt#5, qsec#6, vs#7, am#8, gear#9, carb#10], false
   
   == Physical Plan ==
   *(4) HashAggregate(keys=[], functions=[count(1)], output=[count#42L])
   +- Exchange SinglePartition
      +- *(3) HashAggregate(keys=[], functions=[partial_count(1)], output=[count#45L])
         +- *(3) Project
            +- FlatMapGroupsInRWithArrow [...], [StructField(mpg,DoubleType,true), StructField(cyl,DoubleType,true), StructField(disp,DoubleType,true), StructField(hp,DoubleType,true), StructField(drat,DoubleType,true), StructField(wt,DoubleType,true), StructField(qsec,DoubleType,true), StructField(vs,DoubleType,true), StructField(am,DoubleType,true), StructField(gear,DoubleType,true), StructField(carb,DoubleType,true)], [gear#35, disp#36], createexternalrow(gear#9, hp#3, StructField(gear,DoubleType,true), StructField(hp,DoubleType,true)), [gear#9, hp#3]
               +- *(2) Sort [gear#9 ASC NULLS FIRST, hp#3 ASC NULLS FIRST], false, 0
                  +- Exchange hashpartitioning(gear#9, hp#3, 200)
                     +- *(1) Project [hp#3, gear#9]
                        +- *(1) Scan ExistingRDD arrow[mpg#0,cyl#1,disp#2,hp#3,drat#4,wt#5,qsec#6,vs#7,am#8,gear#9,carb#10]
   ```
   
   After:
   
   ```
   == Optimized Logical Plan ==
   Aggregate [count(1) AS count#42L]
   +- Project
      +- FlatMapGroupsInRWithArrow [StructField(mpg,DoubleType,true), StructField(cyl,DoubleType,true), StructField(disp,DoubleType,true), StructField(hp,DoubleType,true), StructField(drat,DoubleType,true), StructField(wt,DoubleType,true), StructField(qsec,DoubleType,true), StructField(vs,DoubleType,true), StructField(am,DoubleType,true), StructField(gear,DoubleType,true), StructField(carb,DoubleType,true)], [StructField(gear,DoubleType,true), StructField(disp,DoubleType,true)], createexternalrow(gear#9, hp#3, StructField(gear,DoubleType,true), StructField(hp,DoubleType,true)), [gear#9, hp#3]
         +- LogicalRDD [mpg#0, cyl#1, disp#2, hp#3, drat#4, wt#5, qsec#6, vs#7, am#8, gear#9, carb#10], false
   
   == Physical Plan ==
   *(4) HashAggregate(keys=[], functions=[count(1)], output=[count#42L])
   +- Exchange SinglePartition
      +- *(3) HashAggregate(keys=[], functions=[partial_count(1)], output=[count#45L])
         +- *(3) Project
            +- FlatMapGroupsInRWithArrow [...], [StructField(mpg,DoubleType,true), StructField(cyl,DoubleType,true), StructField(disp,DoubleType,true), StructField(hp,DoubleType,true), StructField(drat,DoubleType,true), StructField(wt,DoubleType,true), StructField(qsec,DoubleType,true), StructField(vs,DoubleType,true), StructField(am,DoubleType,true), StructField(gear,DoubleType,true), StructField(carb,DoubleType,true)], [gear#35, disp#36], createexternalrow(gear#9, hp#3, StructField(gear,DoubleType,true), StructField(hp,DoubleType,true)), [gear#9, hp#3]
               +- *(2) Sort [gear#9 ASC NULLS FIRST, hp#3 ASC NULLS FIRST], false, 0
                  +- Exchange hashpartitioning(gear#9, hp#3, 200)
                     +- *(1) Scan ExistingRDD arrow[mpg#0,cyl#1,disp#2,hp#3,drat#4,wt#5,qsec#6,vs#7,am#8,gear#9,carb#10]
   ```
   
   and .. this crestes new output attributes from the given output schema (this is similar with Pandas groupped map UDF).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org