Skip to content

Commit

Permalink
[SPARK-39935][SQL][TESTS] Switch validateParsingError() onto `check…
Browse files Browse the repository at this point in the history
…Error()`

### What changes were proposed in this pull request?
1. Re-implemented `validateParsingError()` using `checkError()`.
2. Removed `checkParsingError()` and replaced by `checkError()`.

### Why are the changes needed?
1. To prepare test infra for testing of query contexts.
3. To check message parameters instead of entire text message. This PR is some kind of follow up of #36693 and #37322.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By running the modified test suites:
```
$ build/sbt -Phive -Phive-thriftserver "test:testOnly *TruncateTableParserSuite"
$ build/sbt -Phive-2.3 -Phive-thriftserver "test:testOnly *ShowPartitionsParserSuite"
$ build/sbt "sql/testOnly *QueryParsingErrorsSuite"
```

Closes #37363 from MaxGekk/checkParsingError-to-checkError.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
  • Loading branch information
MaxGekk committed Aug 2, 2022
1 parent b0c831d commit 99fc389
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.sql.errors

import org.apache.spark.{QueryContext, SparkThrowable}
import org.apache.spark.QueryContext
import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.test.SharedSparkSession

Expand All @@ -28,28 +28,13 @@ trait QueryErrorsSuiteBase extends SharedSparkSession {
errorClass: String,
errorSubClass: Option[String] = None,
sqlState: String,
message: String): Unit = {
val exception = intercept[ParseException] {
sql(sqlText)
}
checkParsingError(exception, errorClass, errorSubClass, sqlState, message)
}

def checkParsingError(
exception: Exception with SparkThrowable,
errorClass: String,
errorSubClass: Option[String] = None,
sqlState: String,
message: String): Unit = {
val fullErrorClass = if (errorSubClass.isDefined) {
errorClass + "." + errorSubClass.get
} else {
errorClass
}
assert(exception.getErrorClass === errorClass)
assert(exception.getErrorSubClass === errorSubClass.orNull)
assert(exception.getSqlState === sqlState)
assert(exception.getMessage === s"""\n[$fullErrorClass] """ + message)
parameters: Map[String, String] = Map.empty): Unit = {
checkError(
exception = intercept[ParseException](sql(sqlText)),
errorClass = errorClass,
errorSubClass = errorSubClass,
sqlState = Some(sqlState),
parameters = parameters)
}

case class ExpectedContext(
Expand Down

0 comments on commit 99fc389

Please sign in to comment.