Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17993#discussion_r118852747
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/ConstantPropagationSuite.scala
 ---
    @@ -0,0 +1,167 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.catalyst.optimizer
    +
    +import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
    +import org.apache.spark.sql.catalyst.dsl.expressions._
    +import org.apache.spark.sql.catalyst.dsl.plans._
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.plans.PlanTest
    +import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, 
LogicalPlan}
    +import org.apache.spark.sql.catalyst.rules.RuleExecutor
    +
    +/**
    + * Unit tests for constant propagation in expressions.
    + */
    +class ConstantPropagationSuite extends PlanTest {
    +
    +  object Optimize extends RuleExecutor[LogicalPlan] {
    +    val batches =
    +      Batch("AnalysisNodes", Once,
    +        EliminateSubqueryAliases) ::
    +        Batch("ConstantPropagation", Once,
    +          ColumnPruning,
    +          ConstantPropagation,
    +          ConstantFolding,
    +          BooleanSimplification) :: Nil
    +  }
    +
    +  val testRelation = LocalRelation('a.int, 'b.int, 'c.int)
    +
    +  private val columnA = 'a.int
    +  private val columnB = 'b.int
    +  private val columnC = 'c.int
    +
    +  test("basic test") {
    +    val query = testRelation
    +      .select(columnA)
    +      .where(columnA === Add(columnB, Literal(1)) && columnB === 
Literal(10))
    +
    +    val correctAnswer =
    +      testRelation
    +        .select(columnA)
    +        .where(columnA === Literal(11) && columnB === Literal(10)).analyze
    +
    +    comparePlans(Optimize.execute(query.analyze), correctAnswer)
    +  }
    +
    +  test("with combination of AND and OR predicates") {
    +    val query = testRelation
    +      .select(columnA)
    +      .where(
    +        columnA === Add(columnB, Literal(1)) &&
    +          columnB === Literal(10) &&
    +          (columnA === Add(columnC, Literal(3)) || columnB === columnC))
    +      .analyze
    +
    +    val correctAnswer =
    +      testRelation
    +        .select(columnA)
    +        .where(
    +          columnA === Literal(11) &&
    +            columnB === Literal(10) &&
    +            (columnA === Add(columnC, Literal(3)) || Literal(10) === 
columnC))
    --- End diff --
    
    Hmmm... that means the optimizer is not converging to a fixed point. Could 
you try to increase the number of iterations? You can also check if the 
optimizer reaches 100 iterations during regular execution; it should log a 
warning. If it does something is wrong with the rule, and it might cause the 
optimizer to run prohibitively long...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to