Github user maropu commented on a diff in the pull request: https://github.com/apache/spark/pull/16605#discussion_r96549098 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala --- @@ -1428,6 +1428,134 @@ class DataFrameSuite extends QueryTest with SharedSQLContext { checkAnswer(df.select(primitiveUDF($"age")), Row(44) :: Row(null) :: Nil) } + test("SPARK-18884 correctly handle array inputs in functions.udf") { + Seq("true", "false").foreach { codegenEnabled => + withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> codegenEnabled) { + // scalastyle:off line.size.limit + Seq(( + udf { (ar1: Array[Int]) => ar1.sum }, + udf { (ar1: Array[Int], ar2: Array[Int]) => (ar1 ++ ar2).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int]) => (ar1 ++ ar2 ++ ar3).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int], ar6: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int], ar6: Array[Int], ar7: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int], ar6: Array[Int], ar7: Array[Int], ar8: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int], ar6: Array[Int], ar7: Array[Int], ar8: Array[Int], ar9: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8 ++ ar9).sum }, + udf { (ar1: Array[Int], ar2: Array[Int], ar3: Array[Int], ar4: Array[Int], ar5: Array[Int], ar6: Array[Int], ar7: Array[Int], ar8: Array[Int], ar9: Array[Int], ar10: Array[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8 ++ ar9 ++ ar10).sum } + ), ( + udf { (ar1: Seq[Int]) => ar1.sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int]) => (ar1 ++ ar2).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int]) => (ar1 ++ ar2 ++ ar3).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int], ar6: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int], ar6: Seq[Int], ar7: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int], ar6: Seq[Int], ar7: Seq[Int], ar8: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int], ar6: Seq[Int], ar7: Seq[Int], ar8: Seq[Int], ar9: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8 ++ ar9).sum }, + udf { (ar1: Seq[Int], ar2: Seq[Int], ar3: Seq[Int], ar4: Seq[Int], ar5: Seq[Int], ar6: Seq[Int], ar7: Seq[Int], ar8: Seq[Int], ar9: Seq[Int], ar10: Seq[Int]) => (ar1 ++ ar2 ++ ar3 ++ ar4 ++ ar5 ++ ar6 ++ ar7 ++ ar8 ++ ar9 ++ ar10).sum } + ) + ).map { case (udf1, udf2, udf3, udf4, udf5, udf6, udf7, udf8, udf9, udf10) => + val arVal = functions.array(lit(1), lit(1)) --- End diff -- you mean this kind of this?: ``` val testUdf = udf { (ar: Array[Long]) => ar.sum } val df = spark.range(10).select(array('id, 'id).as("arVal")) checkAnswer(df.select(udf1(arVal)), Row(2) :: Nil) ```
--- 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