Skip to content

Conversation

rogalski
Copy link
Contributor

@rogalski rogalski commented Oct 5, 2024

Add failing test cases, no fix yet.

Brief summary of the change made

Fixes #5956

Are there any other side effects of this change that we should be aware of?

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@rogalski rogalski changed the title [WIP] ST06 - Fix union of CTE/Subquery ST06 - Fix union of CTE/Subquery Oct 7, 2024
@rogalski rogalski marked this pull request as ready for review October 7, 2024 19:30
@rogalski
Copy link
Contributor Author

rogalski commented Oct 7, 2024

Not sure if CI will be 100% green, but this looks fairly good in my local environment.

Copy link
Contributor

github-actions bot commented Oct 9, 2024

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   18565      0   100%

236 files skipped due to complete coverage.

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think there's an optional way of making this even better but I love the approach.

Comment on lines 105 to 108
maybe_with_compound_statement = seg.get_parent()
if maybe_with_compound_statement is None:
break
with_compound_statement, _ = maybe_with_compound_statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coverage checks are failing because of this line, but it's very unlikely that would ever get used. If you add a comment here saying that clause is mostly a safety measure, then I think it's also ok to mark it as # pragma: no cover.

It would only be None if a fix has modified it in some way and we haven't yet re-populated the parent. Even in that scenario it's very unlikely.

):
return None

# CTE is order-sensitive only if CTE is referenced in set expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a small thing, which you can choose whether to address: The order is only sensitive if a wildcard (*) is used. In the case of a set expression where all the columns are re-specified, it would be ok to reorder them here - it's only when the set expression uses a * that it becomes a problem.

For bonus points, taking that into account would be awesome.

@alanmcruickshank alanmcruickshank dismissed their stale review October 10, 2024 10:22

Meant to click "comment"

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks for the edits 🚀

@alanmcruickshank alanmcruickshank added this pull request to the merge queue Oct 11, 2024
Merged via the queue into sqlfluff:main with commit 2b76370 Oct 11, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

structure.column_order breaks subsequent UNION ALL.
2 participants