Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structure.column_order breaks subsequent UNION ALL. #5956

Open
2 of 3 tasks
rogalski opened this issue Jun 7, 2024 · 2 comments · May be fixed by #6298
Open
2 of 3 tasks

structure.column_order breaks subsequent UNION ALL. #5956

rogalski opened this issue Jun 7, 2024 · 2 comments · May be fixed by #6298
Labels
bug Something isn't working

Comments

@rogalski
Copy link

rogalski commented Jun 7, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

SQLFluff fix produces SQL with changed behavior.

Expected Behaviour

SQL before and after fix is functionally equivalent.

Observed Behaviour

T2 SELECT has reordered columns, which breaks UNION.

How to reproduce

-- noqa: disable=structure.column_order
CREATE TABLE X AS
WITH T1 AS (
    SELECT
        'a'::varchar AS A,
        1::bigint AS B

),

T2 AS (
    SELECT
        CASE WHEN COL > 1 THEN 'x' ELSE 'y' END AS A,
        COL AS B
    FROM T
)

SELECT * FROM T1
UNION ALL
SELECT * FROM T2;

Run sqlfluff fix with disable statement, all good.
Run sqlfluff fix without disable statement, output columns in T2 are reordered, which breaks subsequent union.

Dialect

snowflake

Version

3.0.7

Configuration

default

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@rogalski rogalski added the bug Something isn't working label Jun 7, 2024
@sbrugman
Copy link

Encountered the same issue with sparksql, resulting in:

pyspark.sql.utils.AnalysisException: Union can only be performed on tables with the compatible column types.

@sbrugman
Copy link

@rogalski rogalski linked a pull request Oct 5, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants