srielau opened a new pull request, #59875:
URL: https://github.com/apache/spark/pull/59875
### What changes were proposed in this pull request?
`parse_sql` describes the inside of a SQL script (`BEGIN ... END`).
- A script object gets a `statements` array with one object per nested
statement and control-flow condition, ordered by `start`. Each object has the
same shape as a top-level statement. Spans are batch-relative, and nested error
indexes are relative to the nested statement.
- In `ANALYZE` mode:
- Each nested statement sees the script locals in scope, following the
interpreter's rules. Locals are typed from the DECLARE type or the DEFAULT
expression and can be resolved by block label or FOR variable. Handler bodies
are analyzed in scope.
- Each nested statement also sees the tables and views that earlier
statements create.
- Conditions must be a single BOOLEAN column
(`INVALID_BOOLEAN_STATEMENT`). A simple CASE is checked as `operand = value`
per WHEN.
- The script's `analyze_success` is true only when every nested statement
analyzed. Its references are the union of the nested references.
- Locals are supplied to the analyzer through a thread-local
`SuppliedLocalScopeRegistry`, read by `VariableResolution` and
`ResolveCatalogs`. No `SqlScriptingContextManager` is installed.
This is part 4 of the stack that splits
[#59844](https://github.com/apache/spark/pull/59844) (SPARK-60593). It is
stacked on [#59874](https://github.com/apache/spark/pull/59874) (SPARK-60622);
only the last commit is new here.
### Why are the changes needed?
A script is one statement at the top level, so without this the caller
learns nothing about the queries inside it, which is where the lineage and
types are.
### Does this PR introduce _any_ user-facing change?
Yes, for the unreleased `parse_sql` function, which is behind
`spark.sql.function.parseSql.enabled` (default `false`). Script objects gain a
`statements` array, in `PARSE` and `ANALYZE` mode.
### How was this patch tested?
- New `ParseSqlAnalyzeSuite` tests for local typing, scope and label
resolution, FOR loops, conditions, handlers, simple CASE, created tables and
views, the interpreter's variable rules, BOOLEAN conditions and per-statement
error indexes.
- A `ParseSqlResultSuite` test for the PARSE `statements` array.
- A new golden script case.
- Ran the parse_sql suites, `SQLQueryTestSuite -z parse-sql` and the
analysis suites.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Grok 4.6
--
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]