[
https://issues.apache.org/jira/browse/SPARK-62259?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Wenchen Fan reassigned SPARK-62259:
-----------------------------------
Assignee: Ganesha S
> ALTER VIEW ... WITH SCHEMA on a SCHEMA EVOLUTION view can make the view
> unreadable (INTERNAL_ERROR)
> ---------------------------------------------------------------------------------------------------
>
> Key: SPARK-62259
> URL: https://issues.apache.org/jira/browse/SPARK-62259
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 4.1.0, 4.2.0, 4.3.0, 4.4.0
> Reporter: Ganesha S
> Assignee: Ganesha S
> Priority: Major
> Labels: pull-request-available
>
> h3. Problem
> Changing a WITH SCHEMA EVOLUTION view to another mode (COMPENSATION, BINDING
> or TYPE EVOLUTION) can succeed but leave the view unreadable. Every later
> query on the view fails with INTERNAL_ERROR.
> This happens when the view still stores query output column names
> ("view.query.out.*") from Spark 4.0. Since SPARK-52417 (4.1.0), these names
> are no longer written or updated for EVOLUTION views; the schema sync updates
> only the view schema. ALTER VIEW ... WITH SCHEMA then
> reuses the old names, so their count no longer matches the view schema.
> h3. Steps to reproduce
> A. Upgrade path (real-world case). Use the same metastore and warehouse for
> both versions.
> On Spark 4.0.x:
> {code:sql}
> CREATE TABLE t (c1 INT, c2 INT) USING parquet;
> INSERT INTO t VALUES (1, 2);
> CREATE VIEW v WITH SCHEMA EVOLUTION AS SELECT * FROM t;
> {code}
> On Spark 4.1.0 or later:
> {code:sql}
> ALTER TABLE t ADD COLUMNS (c3 INT);
> SELECT * FROM v; -- OK: 1, 2, NULL (view schema synced
> to 3 columns)
> ALTER VIEW v WITH SCHEMA COMPENSATION; -- succeeds
> SELECT * FROM v; -- fails
> {code}
> B. Single session on Spark 4.1.0 or later (simulates the names Spark 4.0
> stores):
> {code:sql}
> CREATE TABLE t (c1 INT, c2 INT) USING parquet;
> INSERT INTO t VALUES (1, 2);
> CREATE VIEW v WITH SCHEMA EVOLUTION AS SELECT * FROM t;
> ALTER VIEW v SET TBLPROPERTIES (
> 'view.query.out.numCols' = '2',
> 'view.query.out.col.0' = 'c1',
> 'view.query.out.col.1' = 'c2');
> ALTER TABLE t ADD COLUMNS (c3 INT);
> SELECT * FROM v; -- OK: 1, 2, NULL
> ALTER VIEW v WITH SCHEMA COMPENSATION; -- succeeds
> SELECT * FROM v; -- fails
> {code}
> h3. Current result
> {noformat}
> org.apache.spark.SparkException: [INTERNAL_ERROR] The Spark SQL phase
> analysis failed with an
> internal error. You hit a bug in Spark or the Spark plugins you use. ...
> Caused by: java.lang.AssertionError: assertion failed: Corrupted view
> metadata detected for view
> `spark_catalog`.`default`.`v`. The number of view query column names 2 does
> not match the number
> of columns in the view schema 3. View query column names: [c1, c2],
> View schema columns: [c1, c2, c3]. This indicates corrupted view metadata
> that needs to be repaired.
> {noformat}
> The same failure happens with WITH SCHEMA BINDING and WITH SCHEMA TYPE
> EVOLUTION.
> Workaround: recreate the view with CREATE OR REPLACE VIEW.
> h3. Expected result
> ALTER VIEW only changes the schema mode, and the view stays readable with the
> columns it had before the ALTER. The last query returns 1, 2, NULL.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]