dongjoon-hyun commented on code in PR #60710:
URL: https://github.com/apache/spark/pull/60710#discussion_r4633938770
##########
sql/core/src/test/scala/org/apache/spark/sql/RuntimeNullChecksV2Writes.scala:
##########
@@ -400,11 +391,11 @@ class RuntimeNullChecksV2Writes extends
SharedSparkSession {
""".stripMargin)
}
}
- assertNotNullException(e2, Seq("m", "value", "x"))
}
}
- private def assertNotNullException(e: SparkRuntimeException, colPath:
Seq[String]): Unit = {
+ protected def assertNotNullException(colPath: Seq[String])(f: => Any): Unit
= {
+ val e = intercept[SparkRuntimeException](f)
e.getCause match {
Review Comment:
**[1] The top-level test lost the actual condition in its failure message.**
Before this PR, `checkNotNullTopLevelFields` had its own
`assert(e.getCondition == "NOT_NULL_ASSERT_VIOLATION")`. If the write threw a
`SparkRuntimeException` with another condition, the failure showed both values,
for example `"CAST_INVALID_INPUT" did not equal "NOT_NULL_ASSERT_VIOLATION"`.
That test now goes through this helper, which matches on `e.getCause` and
checks the condition only in a guard. The same failure now reports `Unexpected
exception cause: null` (or the cause, if there is one), and the condition that
was wrong is not shown.
The match on `getCause` does nothing else, so a plain assertion keeps the
old message for every call site:
```scala
val e = intercept[SparkRuntimeException](f)
assert(e.getCondition == "NOT_NULL_ASSERT_VIOLATION")
```
##########
sql/core/src/test/scala/org/apache/spark/sql/RuntimeNullChecksV2Writes.scala:
##########
@@ -400,11 +391,11 @@ class RuntimeNullChecksV2Writes extends
SharedSparkSession {
""".stripMargin)
}
}
- assertNotNullException(e2, Seq("m", "value", "x"))
}
}
- private def assertNotNullException(e: SparkRuntimeException, colPath:
Seq[String]): Unit = {
+ protected def assertNotNullException(colPath: Seq[String])(f: => Any): Unit
= {
+ val e = intercept[SparkRuntimeException](f)
Review Comment:
**[2] `checkError` already does this check.**
`checkError` from `CheckErrorHelper`, which `SparkFunSuite` mixes in,
compares the condition and the message parameters and lists every mismatch, so
this helper does not need a hand-written condition check. Since it compares all
message parameters, the call also passes `walkedTypePath`. `AssertNotNull` sets
it to `walkedTypePath.mkString("\n", "\n", "\n")`, built from the column path
that `TableOutputResolver` gives it, so something like this:
```scala
checkError(
exception = intercept[SparkRuntimeException](f),
condition = "NOT_NULL_ASSERT_VIOLATION",
parameters = Map("walkedTypePath" -> colPath.mkString("\n", "\n",
"\n")))
```
--
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]