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/copy into #841

Merged
merged 1 commit into from
Apr 27, 2023
Merged

Conversation

pawel-big-lebowski
Copy link
Contributor

@pawel-big-lebowski pawel-big-lebowski commented Mar 23, 2023

Support Snowflake's COPY INTO clause:

/* Standard data load */
COPY INTO [<namespace>.]<table_name>
     FROM { internalStage | externalStage | externalLocation }
[ FILES = ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
[ PATTERN = '<regex_pattern>' ]
[ FILE_FORMAT = ( { FORMAT_NAME = '[<namespace>.]<file_format_name>' |
                    TYPE = { CSV | JSON | AVRO | ORC | PARQUET | XML } [ formatTypeOptions ] } ) ]
[ copyOptions ]
[ VALIDATION_MODE = RETURN_<n>_ROWS | RETURN_ERRORS | RETURN_ALL_ERRORS ]

/* Data load with transformation */
COPY INTO [<namespace>.]<table_name> [ ( <col_name> [ , <col_name> ... ] ) ]
     FROM ( SELECT [<alias>.]$<file_col_num>[.<element>] [ , [<alias>.]$<file_col_num>[.<element>] ... ]
            FROM { internalStage | externalStage } )
[ FILES = ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
[ PATTERN = '<regex_pattern>' ]
[ FILE_FORMAT = ( { FORMAT_NAME = '[<namespace>.]<file_format_name>' |
                    TYPE = { CSV | JSON | AVRO | ORC | PARQUET | XML } [ formatTypeOptions ] } ) ]
[ copyOptions ]

Docs: https://docs.snowflake.com/en/sql-reference/sql/copy-into-table

@coveralls
Copy link

coveralls commented Mar 23, 2023

Pull Request Test Coverage Report for Build 4676350337

  • 294 of 314 (93.63%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 86.425%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ast/mod.rs 33 43 76.74%
src/dialect/snowflake.rs 109 119 91.6%
Totals Coverage Status
Change from base Build 4659102766: 0.1%
Covered Lines: 14204
Relevant Lines: 16435

💛 - Coveralls

@pawel-big-lebowski pawel-big-lebowski force-pushed the snowflake/copy-into branch 5 times, most recently from dd3f6ff to e6315ad Compare March 27, 2023 10:21
@pawel-big-lebowski pawel-big-lebowski marked this pull request as ready for review March 27, 2023 10:37
Copy link
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @pawel-big-lebowski -- looks good to me except for a few more tests

/// ```sql
/// COPY INTO
/// ```
/// See <https://docs.snowflake.com/en/sql-reference/sql/copy-into-table>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree it makes sense to use a separate struct for system specific syntax

src/ast/mod.rs Outdated
into,
from_stage,
from_stage_alias,
stage_params: _stage_params,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are stage_params ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like stage_params were totally forgotten for copy into. Thanks for spotting this.
I've included stage_params support in recent commit version.

@@ -40,6 +43,8 @@ impl Dialect for SnowflakeDialect {
|| ch.is_ascii_digit()
|| ch == '$'
|| ch == '_'
|| ch == '/'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see any test coverage of these identifier changes. Could you please add some tests (to make sure we don't break the functionality in some future refactoring)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done within test_snowflake_stage_object_names test.

into,
from_stage,
from_stage_alias,
stage_params: StageParamsObject {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see any test coverage for stage params -- could you please add some coverage for that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right. I've included test_copy_into_with_stage_params.

Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
Copy link
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Looks good to me -- thank you @pawel-big-lebowski

@alamb alamb merged commit d8af925 into sqlparser-rs:main Apr 27, 2023
9 checks passed
serprex pushed a commit to serprex/sqlparser-rs that referenced this pull request Nov 6, 2023
* Support identifiers beginning with digits in MySQL (sqlparser-rs#856)

* support COPY INTO in snowflake (sqlparser-rs#841)

Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>

* Add `dialect_from_str` and improve `Dialect` documentation (sqlparser-rs#848)

* Add `dialect_from_str` and improve `Dialect` documentation

* cleanup

* fix compilation with nostd

* Support multiple-table DELETE syntax (sqlparser-rs#855)

* Support `DISTINCT ON (...)` (sqlparser-rs#852)

* Support "DISTINCT ON (...)"

* a test

* fix the merge

* Test trailing commas (sqlparser-rs#859)

* test: add tests for trailing commas

* tweaks

* Add support for query source in COPY .. TO statement (sqlparser-rs#858)

* Add support for query source in COPY .. TO statement

* Fix compile error

* Fix logical merge conflict (sqlparser-rs#865)

* Fix tiny typo in custom_sql_parser.md (sqlparser-rs#864)

* Make Expr::Interval its own struct (sqlparser-rs#872)

* Make Expr::Interval its own struct

* Add test interval display

* Fix cargo fmt

* Include license file in published crate (sqlparser-rs#871)

* Add support for multiple expressions, order by in aggregations (sqlparser-rs#879)

* Add support for multiple expressions, order by in aggregations

* Fix formatting errors

* Resolve linter errors

* Add parse_multipart_identifier function to parser (sqlparser-rs#860)

* Add parse_multipart_identifier function to parser

* Update doc for parse_multipart_identifier

* Fix conflict

* feat: Add custom operator (sqlparser-rs#868)

* feat: Add custom operator

From sqlparser-rs#863

- It doesn't parse anything — I'm not sure how to parse ` SELECT 'a' REGEXP '^[a-d]';` with `REGEXP` as the operator... (but fine for my narrow purpose)
- If we need tests, where would I add them?

* Update src/ast/operator.rs

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* feat: Support MySQL's `DIV` operator (sqlparser-rs#876)

* feat: MySQL's DIV operator

* fix: do not use `_` prefix for used variable

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* truncate: table as optional keyword (sqlparser-rs#883)

Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>

* feat: add DuckDB dialect (sqlparser-rs#878)

* feat: add DuckDB dialect

* formatting

* fix conflict

* support // in GenericDialect

* add DucDbDialect to all_dialects

* add comment from suggestion

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* fix: support // in GenericDialect

---------

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* Add support for first, last aggregate function parsing (sqlparser-rs#882)

* Add order by parsing to functions

* Fix doc error

* minor changes

* Named window frames (sqlparser-rs#881)

* after over clause, named window can be parsed with window ... as after having clause

* Lint errors are fixed

* Support for multiple windows

* fix lint errors

* simplifications

* rename function

* Rewrite named window search in functional style

* Test added and some minor changes

* Minor changes on tests and namings, and semantic check is removed

---------

Co-authored-by: Mustafa Akur <mustafa.akur@synnada.ai>
Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>

* Fix merge conflict (sqlparser-rs#885)

* Update CHANGELOG for `0.34.0` release (sqlparser-rs#884)

* chore: Release sqlparser version 0.34.0

* Update criterion requirement from 0.4 to 0.5 in /sqlparser_bench (sqlparser-rs#890)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: AviRaboah <91826424+AviRaboah@users.noreply.github.com>
Co-authored-by: pawel.leszczynski <leszczynski.pawel@gmail.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Aljaž Mur Eržen <aljazerzen@users.noreply.github.com>
Co-authored-by: Armin Primadi <aprimadi@gmail.com>
Co-authored-by: Okue <nogideca@gmail.com>
Co-authored-by: Andrew Kane <acekane1@gmail.com>
Co-authored-by: Mustafa Akur <106137913+mustafasrepo@users.noreply.github.com>
Co-authored-by: Jeffrey <22608443+Jefffrey@users.noreply.github.com>
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
Co-authored-by: eitsupi <50911393+eitsupi@users.noreply.github.com>
Co-authored-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
Co-authored-by: Berkay Şahin <124376117+berkaysynnada@users.noreply.github.com>
Co-authored-by: Mustafa Akur <mustafa.akur@synnada.ai>
Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

None yet

3 participants