This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 7cc9667 [SPARK-36405][SQL][TESTS] Check that SQLSTATEs are valid
7cc9667 is described below
commit 7cc9667c88b0f17d8f58a37789f4838312cf7382
Author: Karen Feng <[email protected]>
AuthorDate: Thu Sep 23 14:24:59 2021 +0900
[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 <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
---
core/src/main/resources/error/README.md | 2 ++
.../test/scala/org/apache/spark/SparkThrowableSuite.scala | 13 ++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/core/src/main/resources/error/README.md
b/core/src/main/resources/error/README.md
index dbe180b..c4ab6bb 100644
--- a/core/src/main/resources/error/README.md
+++ b/core/src/main/resources/error/README.md
@@ -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 -->
diff --git a/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
b/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
index 473ecc6..750b2ee 100644
--- a/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
+++ b/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
@@ -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") {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]