spark-test commented on code in PR #60099:
URL: https://github.com/apache/spark/pull/60099#discussion_r4475125749
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala:
##########
@@ -53,6 +53,58 @@ import org.apache.spark.sql.util.CaseInsensitiveStringMap
class AnalysisSuite extends AnalysisTest with Matchers {
import org.apache.spark.sql.catalyst.analysis.TestRelations._
+ test("resolve a table specification without changing option evaluation or
other fields") {
+ val specification = UnresolvedTableSpec(
+ properties = Map("property" -> "value"),
+ provider = Some("parquet"),
+ optionExpression = OptionList(Seq(
+ "answer" -> Literal(1),
+ "answer" -> Add(Literal(40), Literal(2)),
+ "nullable" -> Literal(null))),
+ location = Some("/table"),
+ comment = Some("table comment"),
+ collation = Some("UTF8_BINARY"),
+ serde = None,
+ external = true,
+ constraints = Nil)
+
+ val expected = TableSpec(
+ properties = specification.properties,
+ provider = specification.provider,
+ options = Map("answer" -> "42", "nullable" -> null),
+ location = specification.location,
+ comment = specification.comment,
+ collation = specification.collation,
+ serde = specification.serde,
+ external = specification.external,
+ constraints = Nil)
+ assert(ResolveTableSpec.resolveTableSpec(specification) == expected)
+ assert(ResolveTableSpec.resolveTableSpec(expected) eq expected)
+ val unresolved = specification.copy(
+ optionExpression = OptionList(Seq("answer" ->
UnresolvedAttribute("missing"))))
+ assert(ResolveTableSpec.resolveTableSpec(unresolved) eq unresolved)
+ }
+
+ test("table specification rejects a root subquery option before evaluating
it") {
+ val specification = UnresolvedTableSpec(
+ properties = Map.empty,
+ provider = Some("parquet"),
+ optionExpression = OptionList(Seq("answer" ->
ScalarSubquery(OneRowRelation()))),
Review Comment:
**Nit (P3):** This fixture is already resolved:
`ScalarSubquery(OneRowRelation())` has no outer references and its plan is
resolved, so the spec's children count as resolved. If the
`SubqueryExpression.hasSubquery` precheck in
`ResolveTableSpec.resolveTableSpec` were removed, or moved after the
`childrenResolved` case, this option would still be rejected by the evaluation
branch: `value.dataType` throws for the subquery's empty output, and the
`catch` rethrows `optionMustBeConstant(key, Some(e))` with the same condition
and parameters. `checkError` does not compare the cause, so the test passes
either way and does not verify the "before evaluating it" ordering in its name.
The test also never uses a subquery that cannot resolve. That is the usual
case: `ResolveSubquery` skips these commands, so a subquery written in their
OPTIONS never resolves. Without the precheck, a direct call would return such a
spec unchanged with no error. Production behavior is unchanged, and the SQL
path is still covered by the SPARK-60780 test in
`TableOptionsConstantFoldingSuite`, so the gap is in the direct-call coverage
this PR adds for reuse.
**Verification:**
- **Regression:** With the subquery precheck removed from the
table-specification resolver, the direct subquery coverage fails on both cases:
the never-resolving subquery option comes back unchanged, and the
already-resolved one is rejected through option evaluation with a cause
attached. With the precheck instead moved after the branch that evaluates
resolved option values, the coverage still fails, because the already-resolved
option is then rejected with a cause attached.
- **Behavior:** With the precheck in place, resolving a table specification
whose option holds either a never-resolving subquery or an already-resolved one
raises INVALID_SQL_SYNTAX.OPTION_IS_INVALID for that option key, with supported
set to constant expressions and no cause attached.
--
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]