Skip to content

feat: bigquery struct literal #817

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

Closed
wants to merge 5 commits into from

Conversation

togami2864
Copy link
Contributor

@togami2864 togami2864 commented Feb 28, 2023

Support big query struct literal. https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#struct_literals
This PR includes

tuple syntax

SELECT (1, 2, 3), (1, 1.0, '123', true)

typeless struct syntax

SELECT STRUCT(1, 2, 3)

typed struct syntax

SELECT STRUCT<BOOL>(true)

@togami2864 togami2864 force-pushed the feat/struct-literal-bq branch from 0cf0dc0 to 280ddef Compare February 28, 2023 06:45
@coveralls
Copy link

coveralls commented Feb 28, 2023

Pull Request Test Coverage Report for Build 4341768952

  • 354 of 373 (94.91%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 86.37%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ast/mod.rs 29 32 90.63%
src/parser.rs 63 79 79.75%
Totals Coverage Status
Change from base Build 4315671296: 0.2%
Covered Lines: 13896
Relevant Lines: 16089

💛 - Coveralls

@togami2864 togami2864 force-pushed the feat/struct-literal-bq branch from 280ddef to 0d9c5e8 Compare March 6, 2023 09:08
@togami2864 togami2864 force-pushed the feat/struct-literal-bq branch from c8dc171 to c6610ea Compare March 6, 2023 09:15
Comment on lines +433 to +440
// TODO: support "ARRAY in STRUCT", "STRUCT in STRUCT"
// let sql = r#"SELECT STRUCT<STRUCT<STRING>>(STRUCT("foo"))"#;
// let select = bigquery().verified_only_select(sql);
// assert_eq!(1, select.projection.len());

// let sql = r#"SELECT STRUCT<ARRAY<STRING>>(["foo"])"#;
// let select = bigquery().verified_only_select(sql);
// assert_eq!(1, select.projection.len());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to postpone this. I have no idea to parse this now because Lexer treats ">>" as shiftleft.

Copy link
Contributor

Choose a reason for hiding this comment

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

@togami2864 I think I may have misunderstood your intent -- do you want to postpone the entire PR or just this portion of the syntax?

@togami2864 togami2864 changed the title [WIP] bigquery struct literal feat: bigquery struct literal Mar 6, 2023
@togami2864 togami2864 marked this pull request as ready for review March 6, 2023 15:34
@alamb alamb marked this pull request as draft April 27, 2023 15:27
@alamb
Copy link
Contributor

alamb commented Apr 27, 2023

This PR seems like it waiting for time to respond to feedback, so marking it as a draft

iffyio added a commit to validio-io/sqlparser-rs that referenced this pull request Oct 15, 2023
This builds on top of apache#817

- `STRUCT` literal support via `STRUCT` keyword
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#constructing_a_struct
- `STRUCT` and `ARRAY` type declarations
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_an_array_type
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type

It works around the issue of not being able to parse nested types
like `ARRAY<ARRAY<INT>>` due to the right angle bracket ambiguity
where the tokenizer chooses the right-shift operator (this affects
other dialects like Hive that have similar syntax).
When parsing such types, we accept a closing `>` or `>>` and track
which variant is in use in order to preserve correctness.

Fixes apache#901
Closes apache#817
iffyio added a commit to validio-io/sqlparser-rs that referenced this pull request Oct 15, 2023
This builds on top of apache#817

- `STRUCT` literal support via `STRUCT` keyword
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#constructing_a_struct
- `STRUCT` and `ARRAY` type declarations
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_an_array_type
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type

It works around the issue of not being able to parse nested types
like `ARRAY<ARRAY<INT>>` due to the right angle bracket ambiguity
where the tokenizer chooses the right-shift operator (this affects
other dialects like Hive that have similar syntax).
When parsing such types, we accept a closing `>` or `>>` and track
which variant is in use in order to preserve correctness.

Fixes apache#901
Closes apache#817
iffyio added a commit to validio-io/sqlparser-rs that referenced this pull request Oct 15, 2023
This builds on top of apache#817

- `STRUCT` literal support via `STRUCT` keyword
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#constructing_a_struct
- `STRUCT` and `ARRAY` type declarations
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_an_array_type
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type

It works around the issue of not being able to parse nested types
like `ARRAY<ARRAY<INT>>` due to the right angle bracket ambiguity
where the tokenizer chooses the right-shift operator (this affects
other dialects like Hive that have similar syntax).
When parsing such types, we accept a closing `>` or `>>` and track
which variant is in use in order to preserve correctness.

Fixes apache#901
Closes apache#817
iffyio added a commit to validio-io/sqlparser-rs that referenced this pull request Oct 15, 2023
This builds on top of apache#817

- `STRUCT` literal support via `STRUCT` keyword
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#constructing_a_struct
- `STRUCT` and `ARRAY` type declarations
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_an_array_type
   https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#declaring_a_struct_type

It works around the issue of not being able to parse nested types
like `ARRAY<ARRAY<INT>>` due to the right angle bracket ambiguity
where the tokenizer chooses the right-shift operator (this affects
other dialects like Hive that have similar syntax).
When parsing such types, we accept a closing `>` or `>>` and track
which variant is in use in order to preserve correctness.

Fixes apache#901
Closes apache#817
@alamb alamb closed this in #1003 Oct 25, 2023
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.

3 participants