dejankrak-db opened a new pull request, #60535:
URL: https://github.com/apache/spark/pull/60535
### What changes were proposed in this pull request?
This PR improves the FILE type errors added in SPARK-60386 (#59640):
- `FILE_TYPE_MISSING_QUALIFIER` now names the column and its type: "The
column `c`.`f1` of type "FILE" holds a FILE without a qualifier, which a column
definition requires. Use FILE EXTERNAL." This applies to CREATE TABLE, REPLACE
TABLE, ALTER TABLE ADD COLUMNS, REPLACE COLUMNS and ALTER COLUMN TYPE. A FILE
in a struct field is reported at that field. A FILE in an array or a map is
reported at the array or map column.
- `FILE_TYPE_UNKNOWN_WRITE` reports nested paths for CREATE TABLE AS SELECT
and CREATE TABLE LIKE, as it already did for schema evolution, for example
`[`s`.`f`]` instead of `[`s`]`.
- `FILE_TYPE_UNSUPPORTED_COLUMN_USAGE` reports the full path of a nested
column, for example `` `arr`.`f` `` for `CLUSTER BY (arr.f)` instead of `` `f`
``. It has two new subclasses:
- `BUCKET_COLUMN`, for `CLUSTERED BY (f) INTO n BUCKETS` and the V2
`bucket(n, f)` transform. These were reported as `PARTITION_COLUMN`.
- `BUCKET_SORT_COLUMN`, for `SORTED BY (f)`. A V1 table got
`_LEGACY_ERROR_TEMP_3072` ("Cannot use file for sorting column") here, and a V2
table got `PARTITION_COLUMN`.
- `FILE_TYPE_IN_ROUTINE_SIGNATURE_UNSUPPORTED_QUALIFIER` and
`FILE_TYPE_IN_ROUTINE_SIGNATURE_UNSUPPORTED_MAP_KEY` no longer take the kind of
routine (`function`) as text from the code. They name the routine only, as in
"The FILE type in the signature of `fn` ...".
Code changes:
- The usage of a column is a sealed `FileTypeColumnUsage` instead of a
string spliced into the error class name, so a mistyped usage does not compile.
- The three `TypeUtils` helpers that throw `FILE_TYPE_UNKNOWN_WRITE`
(`checkNoUnknownFileTypeWrite`, `checkNoUnknownFileTypeInTableSchema` and
`checkNoUnknownFileTypeInColumns`) are folded into
`checkNoUnknownFileTypeWrite`, which takes either the paths and types of
columns or a schema. `checkFileTypeHasQualifier` takes the same.
- `fileTypeMissingQualifierError` moves from `sql/api` `CompilationErrors`
to `QueryCompilationErrors`, with the other FILE error builders.
The SQLSTATEs are unchanged: 42601 for a FILE type that a definition cannot
declare, 42K01 for a FILE whose mode is not specified, and 0A000 for an
unsupported use of a column.
### Why are the changes needed?
These come from the review of #59640 (SPARK-61301):
- On a wide table, `FILE_TYPE_MISSING_QUALIFIER` did not say which column to
fix.
- The errors named the wrong clause for a bucket column, and the wrong
column for a nested field.
- A V1 bucket sort column got a legacy error.
- Error messages should not include text supplied by the code.
### Does this PR introduce _any_ user-facing change?
Yes, the FILE errors above change their parameters and messages, and two
subclasses are added. The FILE type is not released yet and is behind
`spark.sql.fileType.enabled`, which is off by default.
### How was this patch tested?
Updated `FileTypeRestrictionsSuite` to check the new parameters of every
FILE error it raises. Added cases for:
- a bucket sort column on V1 and V2 tables, with and without a query;
- a FILE in a struct field of a CREATE TABLE AS SELECT;
- a nested write-ordering column.
Ran `FileTypeRestrictionsSuite` and `SparkThrowableSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
--
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]