dongjoon-hyun opened a new pull request, #60344: URL: https://github.com/apache/spark/pull/60344
### What changes were proposed in this pull request? This PR fixes `ApplyCharTypePadding` so that a `DELETE` that is not rewritten into a row-level operation no longer fails with `[INTERNAL_ERROR] Unexpected table relation: Project [...]` when the table has a `CHAR` column. - The target table of a `DeleteFromTable` is no longer wrapped in the read-side padding `Project`, because that plan never reads the table. - The condition of the `DeleteFromTable` evaluates the read-side padding of its `CHAR` columns itself, after its comparisons are padded, so it matches what a read of the table returns. ### Why are the changes needed? `DeleteFromTable` stays as is for tables that support deletes only with filters, and for `DELETE` without `WHERE` on a `TruncatableTable`. Since read-side padding was added in 3.4.0 (SPARK-40697), `ApplyCharTypePadding` wraps the relation of such a plan in a `Project`, and `DataSourceV2Strategy` only expects a scan relation there. So every `DELETE` on such a table with a `CHAR` column fails, whatever the condition and whether or not the values are stored with padding: ```sql CREATE TABLE cat.t (id INT, dep CHAR(8)) PARTITIONED BY (id, dep); DELETE FROM cat.t WHERE id = 1; -- [INTERNAL_ERROR] Unexpected table relation: Project [id#8, static_invoke(CharVarcharCodegenUtils.readSidePadding(dep#9, 8)) AS dep#12] ... ``` A `DELETE` on a V1 table with a `CHAR` column hits the same internal error instead of `UNSUPPORTED_FEATURE.TABLE_OPERATION`. A comparison with a `CHAR` column cannot simply be translated by attribute name, as it was before 3.4.0: the data source would compare the padded literal with the stored values and silently skip the values stored without padding. With this PR the filter keeps the padding, and the delete fails with the existing "Cannot delete from table" error unless the data source accepts it, e.g. `CHAR_READ_SIDE_PADDING` from SPARK-60479. This is the same shape as the error that `spark.sql.readSideCharPadding=false` already raises with `RPAD`. ### Does this PR introduce _any_ user-facing change? Yes. For a V2 table with a `CHAR` column that is deleted from with filters: - `DELETE` with a condition that does not use a `CHAR` column, `DELETE` without `WHERE`, and `IS [NOT] NULL` on a `CHAR` column now succeed instead of failing with `INTERNAL_ERROR`. - A comparison with a `CHAR` column fails with `Cannot delete from table ... where [(CHAR_READ_SIDE_PADDING(dep, 8, ' ')) = 'hr ']` instead of `INTERNAL_ERROR`, unless the data source accepts that filter. With `spark.sql.charVarchar.standardSemantics.enabled`, it fails with `cannot translate expression to source filter`. - `DELETE` on a V1 table with a `CHAR` column fails with `UNSUPPORTED_FEATURE.TABLE_OPERATION` instead of `INTERNAL_ERROR`. ### How was this patch tested? Added two tests to `DeleteFromTests`, which run against the V1 and V2 filter catalogs of `DataSourceV2SQLSuite`. All four runs fail on master and pass with this PR. Each branch of the change was also disabled in turn, and every variant made the tests fail. ``` build/sbt 'sql/testOnly *DataSourceV2SQLSuite* *CharVarcharTestSuite *DeleteFromTableSuite *EnhancedDeleteFilterSuite *UpdateTableSuite *MergeInto*Suite *DataSourceV2DataFrameSuite *PlanResolutionSuite' ``` passes (29 suites, 3475 tests), as does `sql/scalastyle` and `sql/Test/scalastyle`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: 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]
