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 2020/12/01 19:16:08 UTC
[GitHub] [spark] dongjoon-hyun commented on a change in pull request #30504: [SPARK-33544][SQL] Optimizer should not insert filter when explode with CreateArray/CreateMap
dongjoon-hyun commented on a change in pull request #30504:
URL: https://github.com/apache/spark/pull/30504#discussion_r533659242
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -41,13 +41,26 @@ import org.apache.spark.sql.types._
* equivalent [[Literal]] values.
*/
object ConstantFolding extends Rule[LogicalPlan] {
+
+ private def hasNoSideEffect(e: Expression): Boolean = e match {
+ case _: Attribute => true
+ case _: Literal => true
+ case _: NoSideEffect => e.children.forall(hasNoSideEffect)
+ case _ => false
+ }
+
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case q: LogicalPlan => q transformExpressionsDown {
// Skip redundant folding of literals. This rule is technically not necessary. Placing this
// here avoids running the next rule for Literal values, which would create a new Literal
// object and running eval unnecessarily.
case l: Literal => l
+ case Size(c: CreateArray, _) if c.children.forall(hasNoSideEffect) =>
+ Literal(c.children.length)
+ case Size(c: CreateMap, _) if c.children.forall(hasNoSideEffect) =>
+ Literal(c.children.length / 2)
Review comment:
Since the PR content seems to be finalized, could you revise the PR title to focus on this a little more? Of course, this PR is originated to fix the described problem.
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org