[SPARK-36405][SQL][TESTS] Check that SQLSTATEs are valid
### What changes were proposed in this pull request? Adds validation that the SQLSTATEs in the error class JSON are a subset of those provided in the README. ### Why are the changes needed? Validation of error class JSON ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Unit test Closes #33627 from karenfeng/check-sqlstates. Authored-by: Karen Feng <karen.feng@databricks.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
This commit is contained in:
parent
5268904742
commit
7cc9667c88
|
@ -98,6 +98,7 @@ Spark only uses the standard-defined classes and subclasses, and does not use im
|
|||
|
||||
The following SQLSTATEs are from ISO/IEC CD 9075-2.
|
||||
|
||||
<!-- SQLSTATE table start -->
|
||||
|SQLSTATE|Class|Condition |Subclass|Subcondition |
|
||||
|--------|-----|------------------------------------------------------------|--------|---------------------------------------------------------------|
|
||||
|07000 |07 |dynamic SQL error |000 |(no subclass) |
|
||||
|
@ -253,3 +254,4 @@ The following SQLSTATEs are from ISO/IEC CD 9075-2.
|
|||
|42000 |42 |syntax error or access rule violation |000 |(no subclass) |
|
||||
|44000 |44 |with check option violation |000 |(no subclass) |
|
||||
|HZ000 |HZ |remote database access |000 |(no subclass) |
|
||||
<!-- SQLSTATE table stop -->
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.fasterxml.jackson.module.scala.DefaultScalaModule
|
|||
import org.apache.commons.io.IOUtils
|
||||
|
||||
import org.apache.spark.SparkThrowableHelper._
|
||||
import org.apache.spark.util.Utils
|
||||
|
||||
/**
|
||||
* Test suite for Spark Throwables.
|
||||
|
@ -73,7 +74,17 @@ class SparkThrowableSuite extends SparkFunSuite {
|
|||
|
||||
test("SQLSTATE invariants") {
|
||||
val sqlStates = errorClassToInfoMap.values.toSeq.flatMap(_.sqlState)
|
||||
checkCondition(sqlStates, s => s.length == 5)
|
||||
val errorClassReadMe = Utils.getSparkClassLoader.getResource("error/README.md")
|
||||
val errorClassReadMeContents = IOUtils.toString(errorClassReadMe.openStream())
|
||||
val sqlStateTableRegex =
|
||||
"(?s)<!-- SQLSTATE table start -->(.+)<!-- SQLSTATE table stop -->".r
|
||||
val sqlTable = sqlStateTableRegex.findFirstIn(errorClassReadMeContents).get
|
||||
val sqlTableRows = sqlTable.split("\n").filter(_.startsWith("|")).drop(2)
|
||||
val validSqlStates = sqlTableRows.map(_.slice(1, 6)).toSet
|
||||
// Sanity check
|
||||
assert(Set("07000", "42000", "HZ000").subsetOf(validSqlStates))
|
||||
assert(validSqlStates.forall(_.length == 5), validSqlStates)
|
||||
checkCondition(sqlStates, s => validSqlStates.contains(s))
|
||||
}
|
||||
|
||||
test("Message format invariants") {
|
||||
|
|
Loading…
Reference in a new issue