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

    https://github.com/apache/spark/pull/16193#discussion_r91244760
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/python/BatchEvalPythonExecSuite.scala
 ---
    @@ -0,0 +1,99 @@
    +/*
    + * 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.execution.python
    +
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable.ArrayBuffer
    +
    +import org.apache.spark.api.python.PythonFunction
    +import org.apache.spark.sql.catalyst.expressions.{And, AttributeReference, 
In}
    +import org.apache.spark.sql.execution.{FilterExec, SparkPlanTest}
    +import org.apache.spark.sql.test.SharedSQLContext
    +import org.apache.spark.sql.types.BooleanType
    +
    +class BatchEvalPythonExecSuite extends SparkPlanTest with SharedSQLContext 
{
    +    import testImplicits.newProductEncoder
    +    import testImplicits.localSeqToDatasetHolder
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +    spark.udf.registerPython("dummyPythonUDF", new MyDummyPythonUDF)
    +  }
    +
    +  override def afterAll(): Unit = {
    +    spark.sessionState.functionRegistry.dropFunction("dummyPythonUDF")
    +    super.afterAll()
    +  }
    +
    +  test("Python UDF: push down deterministic FilterExec predicates") {
    +    val df = Seq(("Hello", 4)).toDF("a", "b")
    +      .where("dummyPythonUDF(b) and dummyPythonUDF(a) and a in (3, 4)")
    +    val qualifiedPlanNodes = df.queryExecution.executedPlan.collect {
    +      case f @ FilterExec(And(_: AttributeReference, _: 
AttributeReference), _) => f
    +      case b: BatchEvalPythonExec => b
    +      case f @ FilterExec(_: In, _) => f
    +    }
    +    assert(qualifiedPlanNodes.size == 3)
    +  }
    +
    +  test("Nested Python UDF: push down deterministic FilterExec predicates") 
{
    +    val df = Seq(("Hello", 4)).toDF("a", "b")
    +      .where("dummyPythonUDF(a, dummyPythonUDF(a, b)) and a in (3, 4)")
    +    val qualifiedPlanNodes = df.queryExecution.executedPlan.collect {
    +      case f @ FilterExec(_: AttributeReference, _) => f
    +      case b: BatchEvalPythonExec => b
    +      case f @ FilterExec(_: In, _) => f
    +    }
    +    assert(qualifiedPlanNodes.size == 4)
    +  }
    +
    +  test("Python UDF: no push down on non-deterministic FilterExec 
predicates") {
    +    val df = Seq(("Hello", 4)).toDF("a", "b")
    +      .where("dummyPythonUDF(a) and rand() > 3")
    +    val qualifiedPlanNodes = df.queryExecution.executedPlan.collect {
    +      case f: FilterExec => f
    +      case b: BatchEvalPythonExec => b
    +    }
    +    assert(qualifiedPlanNodes.size == 2)
    +  }
    +
    +  test("Python UDF refers to the attributes from more than one child") {
    --- End diff --
    
    This test case is not directly related to this PR. In the future, we need 
to add more unit test cases in Scala side for verifying `BatchEvalPythonExec` 
for improving the test case coverage.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to