Yang Jie created SPARK-60551:
--------------------------------
Summary: CHECK constraints added by CREATE TABLE do not pad
literals compared with a CHAR column
Key: SPARK-60551
URL: https://issues.apache.org/jira/browse/SPARK-60551
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 5.0.0
Reporter: Yang Jie
A CHECK constraint added by CREATE TABLE is resolved without the CHAR type of
the column (ResolveCatalogs), so a literal compared with a CHAR column is not
padded, while the written value is:
{noformat}
CREATE TABLE t (id INT, status CHAR(10), CONSTRAINT c CHECK (status = 'OPEN'));
INSERT INTO t VALUES (1, 'OPEN');
-- CHECK_CONSTRAINT_VIOLATION, values: - status : OPEN
CREATE TABLE t2 (id INT, status CHAR(10), CONSTRAINT c CHECK (status <>
'CLOSED'));
INSERT INTO t2 VALUES (1, 'CLOSED'); -- accepted
{noformat}
The stored predicate is status = 'OPEN'. ALTER TABLE resolves the condition
against a read of the table, where ApplyCharTypePadding pads the literal, and
stores status = 'OPEN '. A constraint checked through predicateSql has the
same problem at write time: the write query has its CHAR metadata cleaned
(TableOutputResolver), and ResolveTableConstraints runs before the post-hoc
ApplyCharTypePadding. SPARK-60032 keeps the predicate of an ALTER TABLE
constraint that reads a CHAR column for this reason.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]