File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
common/utils/src/main/resources/error
catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
core/src/test/scala/org/apache/spark/sql/execution/python Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 2425
2425
"message" : [
2426
2426
" A higher order function expects <expectedNumArgs> arguments, but got <actualNumArgs>."
2427
2427
]
2428
+ },
2429
+ "UNEVALUABLE" : {
2430
+ "message" : [
2431
+ " Evaluable expressions should be used for a lambda function in a higher order function. However, <funcName> was unevaluable."
2432
+ ]
2428
2433
}
2429
2434
},
2430
2435
"sqlState" : " 42K0D"
Original file line number Diff line number Diff line change @@ -254,6 +254,14 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
254
254
hof.invalidFormat(checkRes)
255
255
}
256
256
257
+ case hof : HigherOrderFunction
258
+ if hof.argumentsResolved && hof.functions
259
+ .exists(_.exists(_.isInstanceOf [Unevaluable ])) =>
260
+ val u = hof.functions.flatMap(_.find(_.isInstanceOf [Unevaluable ])).head
261
+ hof.failAnalysis(
262
+ errorClass = " INVALID_LAMBDA_FUNCTION_CALL.UNEVALUABLE" ,
263
+ messageParameters = Map (" funcName" -> toSQLExpr(u)))
264
+
257
265
// If an attribute can't be resolved as a map key of string type, either the key should be
258
266
// surrounded with single quotes, or there is a typo in the attribute name.
259
267
case GetMapValue (map, key : Attribute ) if isMapWithStringKey(map) && ! key.resolved =>
Original file line number Diff line number Diff line change 17
17
18
18
package org .apache .spark .sql .execution .python
19
19
20
- import org .apache .spark .sql .{IntegratedUDFTestUtils , QueryTest }
21
- import org .apache .spark .sql .functions .count
20
+ import org .apache .spark .sql .{AnalysisException , IntegratedUDFTestUtils , QueryTest }
21
+ import org .apache .spark .sql .functions .{ array , count , transform }
22
22
import org .apache .spark .sql .test .SharedSparkSession
23
23
import org .apache .spark .sql .types .LongType
24
24
@@ -112,4 +112,16 @@ class PythonUDFSuite extends QueryTest with SharedSparkSession {
112
112
val pandasTestUDF = TestGroupedAggPandasUDF (name = udfName)
113
113
assert(df.agg(pandasTestUDF(df(" id" ))).schema.fieldNames.exists(_.startsWith(udfName)))
114
114
}
115
+
116
+ test(" SPARK-48706: Negative test case for Python UDF in higher order functions" ) {
117
+ assume(shouldTestPythonUDFs)
118
+ checkError(
119
+ exception = intercept[AnalysisException ] {
120
+ spark.range(1 ).select(transform(array(" id" ), x => pythonTestUDF(x))).collect()
121
+ },
122
+ errorClass = " INVALID_LAMBDA_FUNCTION_CALL.UNEVALUABLE" ,
123
+ parameters = Map (" funcName" -> " \" pyUDF(namedlambdavariable())\" " ),
124
+ context = ExpectedContext (
125
+ " transform" , s " .* ${this .getClass.getSimpleName}.* " ))
126
+ }
115
127
}
You can’t perform that action at this time.
0 commit comments