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

    https://github.com/apache/spark/pull/9393#discussion_r43657874
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala ---
    @@ -191,4 +193,86 @@ class UDFSuite extends QueryTest with SharedSQLContext 
{
         // pass a decimal to intExpected.
         assert(sql("SELECT intExpected(1.0)").head().getInt(0) === 1)
       }
    +
    +  private def checkNumUDFs(df: DataFrame, expectedNumUDFs: Int): Unit = {
    +    val udfs = df.queryExecution.optimizedPlan.collect {
    +      case p: logical.Project => p.projectList.flatMap {
    +        case e => e.collect {
    +          case udf: ScalaUDF => udf
    +        }
    +      }
    +    }.flatMap(functions => functions)
    +    assert(udfs.length === expectedNumUDFs)
    +  }
    +
    +  test("nondeterministic udf: using UDFRegistration") {
    +    import org.apache.spark.sql.functions._
    +
    +    val deterministicUDF = sqlContext.udf.register("plusOne1", (x: Int) => 
x + 1)
    +    val nondeterministicUDF = deterministicUDF.nonDeterministic
    +    sqlContext.udf.register("plusOne2", nondeterministicUDF)
    +
    +    {
    +      val df = sql("SELECT 1 as a")
    +        .select(col("a"), deterministicUDF(col("a")).as("b"))
    +        .select(col("a"), col("b"), deterministicUDF(col("b")).as("c"))
    +      checkNumUDFs(df, 3)
    --- End diff --
    
    The default value of `foldable` is false, which is why we see three 
expressions at here.


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