srielau opened a new pull request, #57962:
URL: https://github.com/apache/spark/pull/57962
### What changes were proposed in this pull request?
Add a built-in scalar SQL function `parse_command(sqlStmt)` that parse-only
analyzes a SQL statement string and returns a compact JSON description:
- `parse_success` and, on failure, a nested STANDARD-format error object
(`errorClass`, `messageTemplate`, `sqlState`, `messageParameters`) so batch
evaluation never fails a query on bad SQL
- Statement classification from ISO/IEC 9075-2:2023 Table 39
(`statement_identifier`, `statement_code`, `statement_type`,
`statement_class`); Spark-only statements use product-specific identifiers with
negative implementation-defined codes
- Multipart `table_references` and `function_references` (identifier part
sequences)
- `select_list` entries with name parts and expression text
- `parameter_markers` (`named` and `unnamed_count`)
- `as_subquery` for `CREATE TABLE ... AS SELECT` (still Table 39 `CREATE
TABLE` / code 77)
### Why are the changes needed?
Dialect-migration and SQL analysis tooling need an efficient, batchable way
to verify that translated SQL parses and to extract statement kind / references
without requiring catalog objects to exist.
### Does this PR introduce _any_ user-facing change?
Yes. New SQL function:
```sql
SELECT parse_command('SELECT a FROM t');
--
{"parse_success":true,"statement_identifier":"SELECT","statement_code":21,...}
SELECT parse_command('SELEC');
-- {"parse_success":false,"error":{"errorClass":"PARSE_SYNTAX_ERROR",...}}
```
### How was this patch tested?
Added `ParseCommandResultSuite` and `ParseCommandSuite` (catalyst). Ran:
```
build/sbt 'catalyst/testOnly
org.apache.spark.sql.catalyst.parser.ParseCommandResultSuite
org.apache.spark.sql.catalyst.expressions.ParseCommandSuite'
```
All 13 tests passed.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Grok 4.5
--
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]