Skip to content

feat: SELECT * REPLACE <Expr> AS <Identifier> for bigquery #798

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

Merged
merged 9 commits into from
Mar 1, 2023

Conversation

togami2864
Copy link
Contributor

@togami2864 togami2864 force-pushed the feat/wild-replace branch 2 times, most recently from 2902c66 to d3929c4 Compare January 23, 2023 09:28
@coveralls
Copy link

coveralls commented Jan 23, 2023

Pull Request Test Coverage Report for Build 4306895174

  • 53 of 57 (92.98%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 86.172%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ast/query.rs 9 10 90.0%
src/parser.rs 20 23 86.96%
Totals Coverage Status
Change from base Build 4216963554: 0.03%
Covered Lines: 13454
Relevant Lines: 15613

💛 - Coveralls

@AugustoFKL
Copy link
Contributor

I'll review in a few hours, really sorry for the delay @togami2864. You're on fire the last weeks hehe

src/ast/query.rs Outdated
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum ReplaceSelectItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

Two questions about this structure.

  1. Why don't you have an enum with two fields, an expression (the field) and another with an identifier?
  2. Any reason why you put the AS as mandatory? BigQuery has it as non-mandatory, but this syntax you displayed here says otherwise.

If you have a select item, the user will have to validate that the select item is not an expression or wildcard, which isn't excellent as we are such that it isn't.

  • You'll have to validate the column name expression, as it MUST be an identifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. That make sense. It's true that having a select item needs additional validation. I'll modify the implementation.
  2. I think AS is required in SELECT * Replace statement. This is the special case.
    https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#select_replace

Copy link
Contributor

Choose a reason for hiding this comment

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

@togami2864 check the syntax structure for the select statement: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax?hl=pt-br#select_list

select_all:
    [ expression. ]*
    [ EXCEPT ( column_name [, ...] ) ]
    [ REPLACE ( expression [ AS ] column_name [, ...] ) ]

AS is optional between the expression and its column, if I understood it correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my bad. Required element is expr and column_name.

@alamb
Copy link
Contributor

alamb commented Feb 17, 2023

It looks to me like this PR has some feedback that needs implementing, so marking it as draft. Please mark it as ready for review when it is next ready.

@alamb alamb marked this pull request as draft February 17, 2023 19:03
@togami2864 togami2864 marked this pull request as ready for review February 21, 2023 07:02
Copy link
Contributor

@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.

LGTM -- thank you @togami2864

@alamb alamb merged commit 70917a5 into apache:main Mar 1, 2023
@ankrgyl
Copy link
Contributor

ankrgyl commented Mar 2, 2023

(CC @alamb ) I noticed a small typo in this change while rebasing my code: the field is named colum_name instead of column_name in ReplaceSelectElement.

@alamb would it be appropriate to patch and fix this before a bunch of folks upgrade to the new release, or leave it as is?

@alamb
Copy link
Contributor

alamb commented Mar 2, 2023

@alamb would it be appropriate to patch and fix this before a bunch of folks upgrade to the new release, or leave it as is?

If someone wants to fix it up that would be great. I am would be happy to make another quick follow on release.

@togami2864
Copy link
Contributor Author

I made #822 to followup.

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.

5 participants