[ 
https://issues.apache.org/jira/browse/SPARK-62261?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Wenchen Fan resolved SPARK-62261.
---------------------------------
    Fix Version/s: 4.4.0
       Resolution: Fixed

Issue resolved by pull request 60803
[https://github.com/apache/spark/pull/60803]

> Schema sync of a SCHEMA EVOLUTION view keeps stale query column names, so a 
> later ALTER VIEW ... WITH SCHEMA can return swapped columns
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-62261
>                 URL: https://issues.apache.org/jira/browse/SPARK-62261
>             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
>             Fix For: 4.4.0
>
>
> h3. Problem
> Spark 4.0 stores a list of query column names (view.query.out.*) for WITH 
> SCHEMA EVOLUTION views. Since SPARK-52417 (4.1.0), when a read finds that the 
> underlying table changed, Spark updates the view schema but leaves this old 
> list as it is, so the list is wrong. If the view is then switched to another 
> mode with ALTER VIEW ... WITH SCHEMA, Spark uses the old list: the view can 
> return values under the wrong column names, or fail.
> SPARK-62259 fixes this when the number of columns changed. This issue covers 
> changes that keep the number of columns, such as reordered or renamed columns.
> h3. Steps to reproduce (Spark 4.1.0 or later)
> {code:sql}
> CREATE TABLE sales (gross DOUBLE, net DOUBLE) USING parquet;
> CREATE VIEW sales_v WITH SCHEMA EVOLUTION AS SELECT * FROM sales;
> -- Stand-in for the names Spark 4.0 stores (or create the view on Spark 4.0 
> instead):
> ALTER VIEW sales_v SET TBLPROPERTIES (
>   'view.query.out.numCols' = '2',
>   'view.query.out.col.0' = 'gross',
>   'view.query.out.col.1' = 'net');
> -- Recreate the table with the same columns in a different order.
> DROP TABLE sales;
> CREATE TABLE sales (net DOUBLE, gross DOUBLE) USING parquet;
> INSERT INTO sales VALUES (80.0, 100.0);
> SELECT gross, net FROM sales_v;          -- 100.0, 80.0 (the view schema is 
> synced)
> ALTER VIEW sales_v WITH SCHEMA BINDING;
> SELECT gross, net FROM sales_v;
> {code}
> h3. Current result
> {noformat}
> 80.0, 100.0
> {noformat}
> gross and net are swapped, with no error. If a column is renamed instead (for 
> example amt to amount), the last query fails with 
> INCOMPATIBLE_VIEW_SCHEMA_CHANGE: column amt cannot be resolved.
> h3. Expected result
> {noformat}
> 100.0, 80.0
> {noformat}



--
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