Yang Jie created SPARK-60455:
--------------------------------

             Summary: ALTER TABLE ADD CONSTRAINT CHECK fails with 
INTERNAL_ERROR when the condition folds to a constant
                 Key: SPARK-60455
                 URL: https://issues.apache.org/jira/browse/SPARK-60455
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 5.0.0
            Reporter: Yang Jie


ALTER TABLE ... ADD CONSTRAINT ... CHECK validates existing rows with the plan 
Filter(Not(cond), relation). When cond folds to a constant, the optimizer 
prunes the filter before V2 scan push-down, and the only planner strategy for 
AddCheckConstraint matches a DataSourceV2ScanRelation 
(DataSourceV2Strategy.scala:810), so planning fails:

{noformat}
ALTER TABLE t ADD CONSTRAINT c CHECK (current_date() > DATE'2023-01-01');
-- [INTERNAL_ERROR] The Spark SQL phase planning failed with an internal error.
ALTER TABLE t ADD CONSTRAINT c CHECK (1 > 0);  -- the same
{noformat}

CREATE TABLE accepts these conditions. ALTER TABLE should accept them too, or 
reject them with a user-facing error.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to