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

   ### What changes were proposed in this pull request?
   
   This PR assigns proper names and SQLSTATEs to 21 of the parser's legacy 
error conditions (`_LEGACY_ERROR_TEMP_0001` to `_LEGACY_ERROR_TEMP_0056`). It 
is the first batch of SPARK-61835, which renames the remaining 
`_LEGACY_ERROR_TEMP_*` conditions in groups of related ones.
   
   | Legacy condition | New condition | SQLSTATE |
   |---|---|---|
   | `_LEGACY_ERROR_TEMP_0014` | `INVALID_SQL_SYNTAX.EMPTY_TABLESAMPLE` | 42000 
|
   | `_LEGACY_ERROR_TEMP_0015` | `UNSUPPORTED_FEATURE.TABLESAMPLE_METHOD` | 
0A000 |
   | `_LEGACY_ERROR_TEMP_0016` | 
`INVALID_SQL_SYNTAX.INVALID_TABLESAMPLE_METHOD` | 42000 |
   | `_LEGACY_ERROR_TEMP_0024` | 
`INVALID_SQL_SYNTAX.MULTIPLE_FROM_TO_INTERVAL_UNITS` | 42000 |
   | `_LEGACY_ERROR_TEMP_0026` | 
`INVALID_INTERVAL_FORMAT.NON_NUMERIC_MULTI_UNIT_VALUE` | 22006 |
   | `_LEGACY_ERROR_TEMP_0027` | 
`INVALID_INTERVAL_FORMAT.FROM_TO_VALUE_NOT_STRING` | 22006 |
   | `_LEGACY_ERROR_TEMP_0029` | 
`INVALID_INTERVAL_FORMAT.MIXED_YEAR_MONTH_AND_DAY_TIME_FIELDS` | 22006 |
   | `_LEGACY_ERROR_TEMP_0032` | `DUPLICATE_TABLE_PATH` (new) | 42613 |
   | `_LEGACY_ERROR_TEMP_0034` | `UNSUPPORTED_CHANGE_COLUMN.{RENAME, NOT_NULL}` 
and `UNSUPPORTED_REPLACE_COLUMNS.{NESTED_COLUMN, NOT_NULL, COLUMN_POSITION}` 
(new) | 0A000 |
   | `_LEGACY_ERROR_TEMP_0037` | reuses `INVALID_SQL_SYNTAX.MULTI_PART_NAME` | 
42000 |
   | `_LEGACY_ERROR_TEMP_0045` | 
`INVALID_SQL_SYNTAX.SET_TIME_ZONE_INVALID_VALUE` | 42000 |
   | `_LEGACY_ERROR_TEMP_0046` | 
`INVALID_SQL_SYNTAX.CREATE_TEMP_TABLE_WITHOUT_PROVIDER` | 42000 |
   | `_LEGACY_ERROR_TEMP_0047` | 
`INVALID_SQL_SYNTAX.ROW_FORMAT_SERDE_WITHOUT_STORED_AS` | 42000 |
   | `_LEGACY_ERROR_TEMP_0048` | 
`UNSUPPORTED_FEATURE.TRANSFORM_RECORD_READER_WRITER` | 0A000 |
   | `_LEGACY_ERROR_TEMP_0049` | 
`INSERT_OVERWRITE_DIRECTORY_PATH.{BOTH_SPECIFIED, MISSING}` (new) | 42601 |
   | `_LEGACY_ERROR_TEMP_0051` | 
`UNSUPPORTED_FEATURE.EMPTY_GROUPING_SET_IN_CUBE_OR_ROLLUP` | 0A000 |
   | `_LEGACY_ERROR_TEMP_0053` | 
`INVALID_SQL_SYNTAX.CREATE_TEMP_VIEW_WITH_IF_NOT_EXISTS` | 42000 |
   | `_LEGACY_ERROR_TEMP_0056` | 
`INVALID_TIME_TRAVEL_TIMESTAMP_EXPR.COLUMN_REFERENCE` | 42K0E |
   | `_LEGACY_ERROR_TEMP_0001`, `_0004`, `_0018` | 
`SparkException.internalError` | XX000 |
   
   Notes on specific cases:
   
   - `_LEGACY_ERROR_TEMP_0001` (unknown INSERT form), `_0004` (MERGE without a 
source) and `_0018` (unknown TRIM option) are unreachable: the grammar only 
produces the forms the parser handles. They become internal errors, as was done 
for `_LEGACY_ERROR_TEMP_1058` in SPARK-58228.
   - `_LEGACY_ERROR_TEMP_0034` passed English hints in a `msg` parameter (for 
example `", please run RENAME COLUMN instead"`). Each of its five call sites 
now has its own subcondition, and the hint is part of the message.
   - `_LEGACY_ERROR_TEMP_0049` fired both when the path was given twice and 
when it was missing, but its message only described the first case. The two 
cases now raise separate subconditions.
   - `_LEGACY_ERROR_TEMP_0015` received the grammar rule name 
`byteLengthLiteral` as its parameter. It now receives `BYTES`, as 
`UNSUPPORTED_FEATURE.TABLESAMPLE_SYSTEM_SAMPLE_METHOD` does.
   - `_LEGACY_ERROR_TEMP_0056` received a fixed English reason. It now names 
the offending expression, like the other `INVALID_TIME_TRAVEL_TIMESTAMP_EXPR` 
subconditions.
   
   Not in this batch: `_LEGACY_ERROR_TEMP_0031` and `_0035` are covered by 
other open PRs, and `_LEGACY_ERROR_TEMP_0060`, `_0062` and `_0063` forward Java 
exception messages and need a separate redesign.
   
   ### Why are the changes needed?
   
   `_LEGACY_ERROR_TEMP_*` conditions are placeholders without stable, 
meaningful names or SQLSTATEs, so applications cannot handle these errors by 
condition or SQLSTATE, and several messages are vague or misleading.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The listed errors now report the new condition names and SQLSTATEs, and 
their messages change. For example, `SELECT * FROM t TABLESAMPLE ()` used to 
fail with:
   
   ```
   [_LEGACY_ERROR_TEMP_0014] TABLESAMPLE does not accept empty inputs.
   ```
   
   and now fails with:
   
   ```
   [INVALID_SQL_SYNTAX.EMPTY_TABLESAMPLE] Invalid SQL syntax: TABLESAMPLE 
requires a sampling method, for example TABLESAMPLE (10 PERCENT). SQLSTATE: 
42000
   ```
   
   ### How was this patch tested?
   
   - Every renamed condition that users can reach is asserted with 
`checkError`, including the SQLSTATE and exact message parameters, in 
`PlanParserSuite`, `ExpressionParserSuite`, `DDLParserSuite` (catalyst and 
core), `PlanResolutionSuite`, `DataSourceV2SQLSuite`, `SQLViewSuite`, 
`HiveDDLSuite` and `CachedTableSuite`. Three tests that matched message text 
now use `checkError`, and a test for `CREATE TEMPORARY VIEW IF NOT EXISTS` was 
added.
   - The SQL golden files for `cast.sql`, `group-analytics.sql`, 
`interval.sql`, `pipe-operators.sql`, `timezone.sql` and 
`udaf-group-analytics.sql` were regenerated with 
`SPARK_GENERATE_GOLDEN_FILES=1`.
   - `SparkThrowableSuite` passes.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Claude Fable 5.2 and Claude Opus 5.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]

Reply via email to