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: Add CREATE FILE FORMAT
Support
#3104
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3104 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 167 167
Lines 12507 12531 +24
=========================================
+ Hits 12507 12531 +24
Continue to review full report at Codecov.
|
We don't currently have an Instead what I'd suggest something like this: OneOf(
Delimited(
Ref("CsvFileFormatTypeOptions"), # TODO: Add Other File Formats.
),
AnySetOf(
Ref("CsvFileFormatTypeOptions"), # TODO: Add Other File Formats.
),
), |
Starting to go a bit crazy with this one. Here's some examples of "valid" syntax on Snowflake:
And then an example of "not valid"
🤷♂️ |
I suggest you get the basic working. Can always enhance it later. |
I've added in the remaining file types, so made a bit more progress. But think it would be helpful for your opinions at this stage @tunetheweb ! The code can now handle:
But I have deliberately ignored mixed arguments Another thing I can't currently handle is:
The above 👆 could be solved by moving type into the file optional parameters but this feels wrong, as it isn't really an optional parameter. Moving into into the optional parameters, would mean that we would parse this "invalid" syntax where
Last thing! We can't currently handle
If we did move type into the optional parameters I've created here, we would resolve the issue of TYPE appearing anywhere (see Sorry that's really long to explain - Snowflake's parser makes really weird decisions in this area. |
I would move it in to the params. SQLFluff syntax is not expected to 100% match the actual dialect - in part because we can't always match. #2426 is a suggestion to add an ability to make an option mandatory, but that's not be implemented yet. |
Okay, I think this is ready for review. Jumped around a bit here but the current thing "works". Changes:
Improvements:
Concerns:
|
Hopefully quick question @tunetheweb and @WittierDinosaur - and I will try make suggested changes today (or ASAP). Should we: (a) leave the (b) change this pattern to align with Advantages of (a):
Advantages of (b):
The reason why I want to make sure, is there is the exact same argument for The reason I went with the generalisable compression type is that:
I thought it starts to get messy if I have a different Anyway! Let me know whether to go for method (a) or (b) for the |
I think if you're having different sections for each (which you have currently done), then it makes more sense to further restrict to the actual type, rather than the whole group. I think For the over Compression Type I think two The other alternative is to generalise this into one big statement. I.e. rather than having separate |
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
…into snowflake-file-formats
Hopefully done @tunetheweb ! |
CREATE FILE FORMAT
Support
CREATE FILE FORMAT ...
is currently unparsable as it is defined inCreateStatementSegment()
which does not include parameters for file formats (it currently handles Warehouses, Pipes, and soon Integrations #3075).An example of unparsable code:
In this PR, I want to introduce
CreateFileFormatSegment()
so that we can:CreateStatementSegment()
into it's component parts.CSV, JSON, ARVO
).I have made some good progress, and the above would now be parsable. But I want to get advice from the maintainers before I continue building out this pattern. I will also post on the Slack channel for some help.
One big issue that I'm unsure on how to resolve is that both comma separation and no comma separation are valid syntax:
This PR currently only handles for no comma separation.
To do
FileFormatSegment
) to reduce duplication / redundant code.create_file_format.sql
file.Brief summary of the change made
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 intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.