Yang Jie created SPARK-60787:
--------------------------------
Summary: CHECK constraints checked through predicateSql resolve a
function name without parentheses to a column added later
Key: SPARK-60787
URL: https://issues.apache.org/jira/browse/SPARK-60787
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 5.0.0
Reporter: Yang Jie
By default, a function name without parentheses in a CHECK condition, such as
current_date, current_timestamp, current_user or user, parses as a name. A
write that checks the constraint through predicateSql (ResolveTableConstraints)
resolves the name to a column first and to the function only when no column
matches (ColumnResolutionHelper). CREATE TABLE stores such a condition without
a predicate, so after a column of that name is added, the check silently
compares with the column:
{noformat}
CREATE TABLE t (id INT, owner STRING, CONSTRAINT c CHECK (owner = user));
ALTER TABLE t ADD COLUMN user STRING;
INSERT INTO t VALUES (1, 'bob', 'bob'); -- accepted, the check now compares
two columns
INSERT INTO t VALUES (2, 'bob', NULL); -- accepted, owner = NULL is NULL
{noformat}
ADD COLUMN does not look at the constraints. A condition with a lambda has no
V2 predicate either, so ALTER TABLE stores it the same way, and forall(ds, x ->
x <= current_date) compares with the column after ADD COLUMN current_date DATE.
For other ALTER TABLE conditions, SPARK-60032 keeps the predicate built from
the optimized plan.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]