Skip to content

[SPARK-56638][SQL] Replace legacy parser error for ParserUtils validation failures - #55782

Closed
XdithyX wants to merge 4 commits into
apache:masterfrom
XdithyX:SPARK-56638
Closed

XdithyX wants to merge 4 commits into
apache:masterfrom
XdithyX:SPARK-56638

Conversation

@XdithyX

@XdithyX XdithyX commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR removes the remaining use of _LEGACY_ERROR_TEMP_0064 from parser validation paths that depended on ParserUtils.validate(...) (SPARK-56638).

Specifically, this PR:

  • Adds named parser error conditions for the affected validation failures
  • Adds corresponding QueryParsingErrors helpers
  • Replaces ParserUtils.validate(...) call sites with specific parser errors
  • Removes ParserUtils.validate(...)
  • Updates parser tests and SQL golden files to assert the new error classes

This includes the TABLESAMPLE fraction validation path, covering both existing TABLESAMPLE syntax and TABLESAMPLE SYSTEM from #54972.

Why are the changes needed?

ParserUtils.validate(...) always threw _LEGACY_ERROR_TEMP_0064, which made different parser validation failures share the same generic legacy error class.

Using named error classes makes each parser failure explicit and removes this legacy temporary error from the affected parser paths.

INVALID_TABLESAMPLE_FRACTION uses SQLSTATE 22023 because the statement is syntactically valid, but the supplied sampling fraction is invalid/out of range. The other parser syntax validation errors are added under INVALID_SQL_SYNTAX, which uses SQLSTATE 42000.

Does this PR introduce any user-facing change?

Yes. The error class changes from _LEGACY_ERROR_TEMP_0064 to named error classes for the affected parser validation failures.

For invalid TABLESAMPLE fractions, the new error class is INVALID_TABLESAMPLE_FRACTION.

How was this patch tested?

build/sbt 'catalyst / Test / testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite -- -z "sampled relations"'
build/sbt 'catalyst / Test / testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite -- -z "TABLESAMPLE SYSTEM - fraction out of range"'

SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "tablesample-negative.sql"'
SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "pipe-operators.sql"'
build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "tablesample-negative.sql"' 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "pipe-operators.sql"'

Was this patch authored or co-authored using generative AI tooling?

Yes. Generated-by: OpenAI GPT-5.5 Codex

@XdithyX

XdithyX commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @cloud-fan and @sarutak, could you please take a look? Thanks.
Tagging @HeartSaVioR as well.

@stanyao

stanyao commented May 11, 2026

Copy link
Copy Markdown
Contributor

@XdithyX , thank you for fixing this issue. Please fix this issue after #54972 merges, because this issue was found during this PR. To keep this already big PR focused and fix it everywhere (including the code that is not part of #54972) I opened this Jira item (SPARK-56638) to track a follow up fix.

@XdithyX

XdithyX commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@stanyao Thanks. I rebased this PR after #54972 merged and updated the new TABLESAMPLE SYSTEM out-of-range test to expect INVALID_TABLESAMPLE_FRACTION.
No other changes were required, I also regenerated and verified the affected SQL golden files.

Can you please have a look when you get a chance?

@XdithyX

XdithyX commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

CI has now passed. Please let me know if anything else is required.
cc: @stanyao

@stanyao

stanyao commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

The goal of this JIRA item is to deprecate the usage of "_LEGACY_ERROR_TEMP_0064" in TABLESAMPLE code path and likely other code paths that depend on ParserUtils.scala. For example, in test("SPARK-55978: TABLESAMPLE SYSTEM - fraction out of range") in PlanParserSuite.scala. Starting from that call site, there is a call chain of -> AnalysisTest.scala -> AbstractSqlParser.scala -> AstBuilder.scala -> validate() function in ParserUtils.scala that is shared by both the existing Bernoulli sampling and the new System sampling. Fixing this will need code changes to 10+ call sites and 20+ test cases. That is a super set of TABLESAMPLE code path. Fixing them all at once is the best approach. I don't think your PR currently covers the full fix.

@XdithyX

XdithyX commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@stanyao Thanks for clarifying. I originally scoped this PR to the TABLESAMPLE fraction validation path only, but I understand now that the expected fix is to eliminate _LEGACY_ERROR_TEMP_0064 from all current ParserUtils.validate(...) call sites, including TABLESAMPLE SYSTEM/Bernoulli and the other parser validations that share the helper.

I’ll update the PR to cover the full set of validate() call sites and their tests/golden files.

@XdithyX
XdithyX force-pushed the SPARK-56638 branch 2 times, most recently from 99181d7 to 7b22383 Compare May 17, 2026 11:04
@XdithyX XdithyX changed the title [SPARK-56638][SQL] Eliminate legacy error class for TABLESAMPLE fraction validation [SPARK-56638][SQL] Replace legacy parser error for ParserUtils validation failures May 17, 2026
@XdithyX

XdithyX commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Hi @stanyao I've updated the PR, can you please have a look when you get a chance?
Thank you

ctx)
}

def invalidTableFunctionTableArgumentWithSinglePartitionError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to have test coverage in PlanParserSuite.scala for the newly introduced error classes here.

@XdithyX XdithyX May 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanyao Thanks for pointing this out. I added PlanParserSuite coverage for the reachable table function parser error path, including the ORDER BY variant.

I also removed the two newly added table-function error classes that were not reachable from SQL parsing because the grammar rejects those forms earlier with PARSE_SYNTAX_ERROR.

@XdithyX
XdithyX requested a review from stanyao May 19, 2026 15:33
@stanyao

stanyao commented May 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for removing the entire ParserUtils.validate() and making progress of deprecating _LEGACY_ERROR_TEMP_0064! This PR touches the error framework (error-conditions.json, QueryParsingErrors), parser infrastructure (ParserUtils.validate removal, AstBuilder), and a bunch of golden files. Please get feedback from @cloud-fan and @MaxGekk.

@XdithyX

XdithyX commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

@stanyao Thanks for the review. @cloud-fan @MaxGekk Could you please have a look when you get a chance?
Thank you!

@stanyao stanyao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I looped in 2 committers who are experts in this area for more feedback.

@XdithyX

XdithyX commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @cloud-fan @MaxGekk Gentle follow up on this PR.

@cloud-fan

Copy link
Copy Markdown
Contributor

cc @srielau

@cloud-fan

Copy link
Copy Markdown
Contributor

BTW PR needs a rebase, ChangelogInfo has been renamed.

@XdithyX

XdithyX commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @cloud-fan. Rebased the PR on latest master to pick up the ChangelogInfo rename.

Also re-ran the parser coverage after rebase:

build/sbt 'catalyst / Test / testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite -- -z "Support PARTITION BY and ORDER BY clause for TVF TABLE arguments"'

@XdithyX

XdithyX commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Gentle follow-up @srielau @cloud-fan . Please let me know if anything else is needed from my side. Thanks!

@srielau srielau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@XdithyX

XdithyX commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @srielau for the review. @cloud-fan Can we check this in, if there are no other issues?

@cloud-fan

Copy link
Copy Markdown
Contributor

thanks, merging to master/4.x!

@cloud-fan cloud-fan closed this in 447d3b4 Jun 1, 2026
cloud-fan pushed a commit that referenced this pull request Jun 1, 2026
…tion failures

### What changes were proposed in this pull request?

This PR removes the remaining use of `_LEGACY_ERROR_TEMP_0064` from parser validation paths that depended on `ParserUtils.validate(...)` ([SPARK-56638](https://issues.apache.org/jira/browse/SPARK-56638)).

Specifically, this PR:
- Adds named parser error conditions for the affected validation failures
- Adds corresponding `QueryParsingErrors` helpers
- Replaces `ParserUtils.validate(...)` call sites with specific parser errors
- Removes `ParserUtils.validate(...)`
- Updates parser tests and SQL golden files to assert the new error classes

This includes the `TABLESAMPLE` fraction validation path, covering both existing `TABLESAMPLE` syntax and `TABLESAMPLE SYSTEM` from [#54972](#54972).

### Why are the changes needed?

`ParserUtils.validate(...)` always threw `_LEGACY_ERROR_TEMP_0064`, which made different parser validation failures share the same generic legacy error class.

Using named error classes makes each parser failure explicit and removes this legacy temporary error from the affected parser paths.

`INVALID_TABLESAMPLE_FRACTION` uses SQLSTATE `22023` because the statement is syntactically valid, but the supplied sampling fraction is invalid/out of range. The other parser syntax validation errors are added under `INVALID_SQL_SYNTAX`, which uses SQLSTATE `42000`.

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

Yes. The error class changes from `_LEGACY_ERROR_TEMP_0064` to named error classes for the affected parser validation failures.

For invalid `TABLESAMPLE` fractions, the new error class is `INVALID_TABLESAMPLE_FRACTION`.

### How was this patch tested?

```bash
build/sbt 'catalyst / Test / testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite -- -z "sampled relations"'
build/sbt 'catalyst / Test / testOnly org.apache.spark.sql.catalyst.parser.PlanParserSuite -- -z "TABLESAMPLE SYSTEM - fraction out of range"'

SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "tablesample-negative.sql"'
SPARK_GENERATE_GOLDEN_FILES=1 build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "pipe-operators.sql"'
build/sbt 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "tablesample-negative.sql"' 'sql / Test / testOnly org.apache.spark.sql.SQLQueryTestSuite -- -z "pipe-operators.sql"'
```

### Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: OpenAI GPT-5.5 Codex

Closes #55782 from XdithyX/SPARK-56638.

Authored-by: Adithya Ajith <4adhi007@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 447d3b4)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@XdithyX

XdithyX commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @cloud-fan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants