Skip to content

Commit 41c4f91

Browse files
lvshaokangMaxGekk
authored andcommitted
[SPARK-38732][SQL][TESTS] Test the error class: INCOMPARABLE_PIVOT_COLUMN
### What changes were proposed in this pull request? I add a test case for the error class INCOMPARABLE_PIVOT_COLUMN in the QueryExecutionErrorsSuite. ### Why are the changes needed? To improve test coverage, and record expected error messages in tests. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By existing tests. Closes #36323 from lvshaokang/SPARK-38732. Authored-by: lvshaokang <[email protected]> Signed-off-by: Max Gekk <[email protected]>
1 parent 5e494d3 commit 41c4f91

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util.Locale
2222
import test.org.apache.spark.sql.connector.JavaSimpleWritableDataSource
2323

2424
import org.apache.spark.{SparkArithmeticException, SparkException, SparkIllegalStateException, SparkRuntimeException, SparkUnsupportedOperationException, SparkUpgradeException}
25-
import org.apache.spark.sql.{DataFrame, QueryTest}
25+
import org.apache.spark.sql.{AnalysisException, DataFrame, QueryTest}
2626
import org.apache.spark.sql.catalyst.util.BadRecordException
2727
import org.apache.spark.sql.connector.SimpleWritableDataSource
2828
import org.apache.spark.sql.execution.QueryExecutionException
@@ -398,4 +398,30 @@ class QueryExecutionErrorsSuite
398398
"\\(QueryExecutionErrorsSuite\\$\\$Lambda\\$\\d+/\\w+: \\(string, int\\) => string\\)",
399399
matchMsg = true)
400400
}
401+
402+
test("INCOMPARABLE_PIVOT_COLUMN: an incomparable column of the map type") {
403+
val e = intercept[AnalysisException] {
404+
trainingSales
405+
sql(
406+
"""
407+
| select * from (
408+
| select *,map(sales.course, sales.year) as map
409+
| from trainingSales
410+
| )
411+
| pivot (
412+
| sum(sales.earnings) as sum
413+
| for map in (
414+
| map("dotNET", 2012), map("JAVA", 2012),
415+
| map("dotNet", 2013), map("Java", 2013)
416+
| ))
417+
|""".stripMargin).collect()
418+
}
419+
checkErrorClass(
420+
exception = e,
421+
errorClass = "INCOMPARABLE_PIVOT_COLUMN",
422+
msg = "Invalid pivot column 'map.*\\'. Pivot columns must be comparable.",
423+
sqlState = Some("42000"),
424+
matchMsg = true
425+
)
426+
}
401427
}

0 commit comments

Comments
 (0)