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

Snowflake: Split out CREATE VIEW into its own segment #2217

Merged
merged 7 commits into from Jan 1, 2022

Conversation

wong-codaio
Copy link
Contributor

@wong-codaio wong-codaio commented Dec 31, 2021

Brief summary of the change made

Snowflake dialect only: Create a segment specifically for Snowflake's CREATE VIEW statement.

  • Removed VIEW from the general CreateStatement in Snowflake.
  • Consolidated multiple test files around view creation into a single test file.
  • Added test cases to support the existing as well as some additional functionality on CREATE VIEW.

fixes #2000

Context

  • There is a CreateStatementSegment in Snowflake that aims to encapsulate all possibilities of CREATE statement in Snowflake. The statement however does not account for the specific needs that is targeted only for CREATE VIEW statement.
  • While it is possible to fix Snowflake create view statement results in parse error #2000 by adding extra clauses to the CreateStatement segment, it seems it's more appropriate to create a separate class for CreateViewStatementSegment - Which makes Snowflake more aligns what dialect_ansi does (Ansi also has a dedicated CreateViewStatementSegment.

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

  • CREATE VIEW segment type has been changed - from create_statement to create_view_statement in Snowflake dialect.
    • If anyone has written custom rules targeting CREATE VIEW in Snowflake's dialect, and is using create_statement as a check in their matching logic, then it'll no longer work.

Pull Request checklist

  • Included test cases to demonstrate any code changes, which may be one or more of the following:
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
      • Refactored all CREATE VIEW test cases into a single snowflake_create_view.sql file.
  • Added appropriate documentation for the change.
    • Added a link to CREATE VIEW documentation on Snowflake's site.

* Removed `VIEW` from the general `CreateStatement` in Snowflake.
* Added test cases to support most of the CREATE VIEW functionality
* Added a note w.r.t the complexity involved in column-level
  masking policy & tagging config.
@wong-codaio wong-codaio marked this pull request as ready for review December 31, 2021 13:33
@wong-codaio
Copy link
Contributor Author

@tunetheweb @Dikootje - Wanted to get how you guys feel about this change.

  • I could fix Snowflake create view statement results in parse error #2000 by adding additional clauses in the CreateStatement segment, but it felt more appropriate to have a dedicated class to handle edge cases around CREATE VIEW, rather than adding more complex logic into the overloaded CreateStatement in Snowflake.

@codecov
Copy link

codecov bot commented Dec 31, 2021

Codecov Report

Merging #2217 (9287986) into main (68f479a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2217   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          149       149           
  Lines        10825     10829    +4     
=========================================
+ Hits         10825     10829    +4     
Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_snowflake.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68f479a...9287986. Read the comment docs.

@jpy-git
Copy link
Contributor

jpy-git commented Dec 31, 2021

  • I could fix Snowflake create view statement results in parse error #2000 by adding additional clauses in the CreateStatement segment, but it felt more appropriate to have a dedicated class to handle edge cases around CREATE VIEW, rather than adding more complex logic into the overloaded CreateStatement in Snowflake.

I agree that it's a good to split into it's own segment, it better aligns with the docs and is easier to check/maintain. I imagine all the CREATE statements were originally combined to quickly get the basic statements parsing but as we develop them more we can split them out properly 👍

src/sqlfluff/dialects/dialect_snowflake.py Outdated Show resolved Hide resolved
src/sqlfluff/dialects/dialect_snowflake.py Outdated Show resolved Hide resolved
src/sqlfluff/dialects/dialect_snowflake.py Outdated Show resolved Hide resolved
src/sqlfluff/dialects/dialect_snowflake.py Outdated Show resolved Hide resolved
src/sqlfluff/dialects/dialect_snowflake.py Outdated Show resolved Hide resolved
src/sqlfluff/dialects/dialect_snowflake.py Show resolved Hide resolved
@wong-codaio wong-codaio force-pushed the wong-create-view branch 2 times, most recently from e209362 to c4f0050 Compare January 1, 2022 14:23
Copy link
Contributor

@jpy-git jpy-git left a comment

Choose a reason for hiding this comment

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

@wong-codaio looks great, thanks! LGTM 🚀 ⭐

@jpy-git jpy-git merged commit 789b46a into sqlfluff:main Jan 1, 2022
@Dikootje
Copy link

Dikootje commented Jan 1, 2022

Thanks guys!

@wong-codaio wong-codaio deleted the wong-create-view branch January 1, 2022 16:38
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.

Snowflake create view statement results in parse error
3 participants