viirya commented on a change in pull request #25215: [SPARK-28445][SQL][Python]
Fix error when PythonUDF is used in both group by and aggregate expression
URL: https://github.com/apache/spark/pull/25215#discussion_r305660113
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2189,4 +2189,46 @@ class DataFrameSuite extends QueryTest with
SharedSQLContext {
|*(1) Range (0, 10, step=1, splits=2)""".stripMargin))
}
}
+
+ test("SPARK-28445: PythonUDF in grouping key and aggregate expressions") {
+ import IntegratedUDFTestUtils._
+
+ val scalaTestUDF = TestScalaUDF(name = "scalaUDF")
+ registerTestUDF(scalaTestUDF, spark)
+
+ val pythonTestUDF = TestPythonUDF(name = "pyUDF")
+ registerTestUDF(pythonTestUDF, spark)
+
+ withTempView("testData") {
+ sql(
+ """CREATE OR REPLACE TEMPORARY VIEW testData AS
+ |SELECT * FROM VALUES
+ |(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3,
null), (null, null)
+ |AS testData(a, b)""".stripMargin)
+
+ val df = sql("SELECT scalaUDF(a + 1), scalaUDF(COUNT(b)) FROM testData "
+
Review comment:
Rewrote them by Scala DSL.
For creating temp view,
```
sql(
"""CREATE OR REPLACE TEMPORARY VIEW testData AS
|SELECT * FROM VALUES
|(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2), (null, 1), (3, null),
(null, null)
|AS testData(a, b)""".stripMargin)
```
It includes null, seems using Scala DSL is troublesome, so keeping it as is.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]