LuciferYang commented on code in PR #38507:
URL: https://github.com/apache/spark/pull/38507#discussion_r1014786778
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala:
##########
@@ -1603,25 +1681,35 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSparkSession {
Seq(Row(1L))
)
- val e1 = intercept[AnalysisException] {
- Seq(("a string element", "a")).toDF().selectExpr("array_position(_1,
_2)")
- }
- val errorMsg1 =
- s"""
- |Input to function array_position should have been array followed by a
- |value with same element type, but it's [string, string].
- """.stripMargin.replace("\n", " ").trim()
- assert(e1.message.contains(errorMsg1))
-
- val e2 = intercept[AnalysisException] {
- OneRowRelation().selectExpr("array_position(array(1), '1')")
- }
- val errorMsg2 =
- s"""
- |Input to function array_position should have been array followed by a
- |value with same element type, but it's [array<int>, string].
- """.stripMargin.replace("\n", " ").trim()
- assert(e2.message.contains(errorMsg2))
+ checkError(
+ exception = intercept[AnalysisException] {
+ Seq(("a string element", "a")).toDF().selectExpr("array_position(_1,
_2)")
+ },
+ errorClass = "DATATYPE_MISMATCH.ARRAY_FUNCTION_DIFF_TYPES",
+ parameters = Map(
+ "sqlExpr" -> "\"array_position(_1, _2)\"",
+ "functionName" -> "`array_position`",
+ "dataType" -> "\"ARRAY\"",
+ "leftType" -> "\"STRING\"",
+ "rightType" -> "\"STRING\""
+ ),
Review Comment:
@MaxGekk For this case, do you think this error does not match?
When `leftType` is not an `Array`, is it more appropriate to use
`UNEXPECTED_INPUT_TYPE` to indicate that the first parameter is not an `Array`?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]