[
https://issues.apache.org/jira/browse/SPARK-57379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18088594#comment-18088594
]
Anupam Yadav commented on SPARK-57379:
--------------------------------------
Confirmed reproducible on current master. Both paths currently allow a
session/temporary variable to be referenced in a CHECK constraint expression
and persist it without error:
{code:sql}
DECLARE OR REPLACE VARIABLE my_var INT DEFAULT 5;
-- (a) CREATE TABLE: succeeds, persists CONSTRAINT c1 CHECK (val > my_var)
CREATE TABLE t (id INT, val INT, CONSTRAINT c1 CHECK (val > my_var)) USING
parquet;
-- (b) ALTER TABLE ADD CONSTRAINT: succeeds, persists the temp-var reference
CREATE TABLE t2 (id INT, val INT) USING parquet;
ALTER TABLE t2 ADD CONSTRAINT c2 CHECK (val > my_var);
{code}
Since a CHECK constraint is persisted with the table but a session variable is
session-scoped, the persisted constraint becomes invalid in any other session.
Spark already blocks the analogous case for persistent views via the
{{INVALID_TEMP_OBJ_REFERENCE}} error class (SQLSTATE 42K0F). I plan to apply
the same approach for CHECK constraints (both CREATE TABLE and ALTER TABLE ADD
CONSTRAINT paths), mirroring the recent fix for generated columns in
SPARK-57360.
> Block temporary variables in CHECK constraint expressions
> ---------------------------------------------------------
>
> Key: SPARK-57379
> URL: https://issues.apache.org/jira/browse/SPARK-57379
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 5.0.0
> Reporter: Szehon Ho
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]