srielau opened a new pull request, #59876:
URL: https://github.com/apache/spark/pull/59876

   ### What changes were proposed in this pull request?
   
   `parse_sql` handles cursors inside a SQL script.
   
   - `DECLARE CURSOR` is recorded in its lexical scope. `OPEN`, `FETCH` and 
`CLOSE` resolve the cursor the same way the interpreter does. An unknown cursor 
is reported as `CURSOR_NOT_FOUND`.
   - The cursor query is analyzed at `DECLARE`. If it has parameter markers, it 
is analyzed at `OPEN` instead, using the types of the `USING` arguments.
   - A cursor query error reported on `OPEN` has a `CURSOR` query context whose 
indexes are relative to the cursor query.
   - In `PARSE` mode, `DECLARE CURSOR` lists the tables its query reads.
   - `ResolveCursors` and `SuppliedLocalScopeRegistry` look up cursors supplied 
this way.
   
   This is part 5 of the stack that splits 
[#59844](https://github.com/apache/spark/pull/59844) (SPARK-60593). It is 
stacked on [#59875](https://github.com/apache/spark/pull/59875) (SPARK-60623); 
only the last commit is new here.
   
   ### Why are the changes needed?
   
   Cursor queries are a common place for a script's real lineage. Without this, 
`FETCH` and `CLOSE` fail analysis and the cursor query is not described.
   
   ### 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`).
   
   ### How was this patch tested?
   
   - New `ParseSqlAnalyzeSuite` tests: DECLARE/OPEN/FETCH/CLOSE resolution, 
tables listed in PARSE mode, `CURSOR_NOT_FOUND`, and a parameterized cursor 
typed at OPEN.
   - 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]

Reply via email to