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

Fix DoubleColon cast skipping AT TIME ZONE #1266 #1267

Merged
merged 1 commit into from May 11, 2024

Conversation

dmitrybugakov
Copy link
Contributor

@dmitrybugakov dmitrybugakov commented May 9, 2024

Closes: #1266

src/ast/mod.rs Outdated
@@ -424,7 +424,7 @@ pub enum CastKind {
/// See <https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#safe_casting>.
SafeCast,
/// `<expr> :: <datatype>`
DoubleColon,
DoubleColonCast,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename this back to DoubleColon. The others have the word Cast because you actually use the word CAST in the syntax. This is also a breaking change without enough benefit to justify.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

Copy link
Contributor

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

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

Can we also remove the formatting changes that are not related to the PR ?

@lovasoa
Copy link
Contributor

lovasoa commented May 10, 2024

Is CastFormat::ValueAtTimeZone still needed if we parse the cast as a separate "at time zone" ast node ?

@dmitrybugakov
Copy link
Contributor Author

Is CastFormat::ValueAtTimeZone still needed if we parse the cast as a separate "at time zone" ast node ?

I'm currently working on the infix part where there is no formatting involved. However, in the prefix part, we are using the BigQuery style where the format is a part of the expression itself.

/// Options for `CAST` / `TRY_CAST`

@dmitrybugakov dmitrybugakov changed the title Fix DoubleColonCast skipping AT TIME ZONE #1266 Fix DoubleColon cast skipping AT TIME ZONE #1266 May 10, 2024
@jmhain
Copy link
Contributor

jmhain commented May 10, 2024

This isn't something this PR necessarily needs to address, but I think we should actually get rid Expr::AtTimeZone and add BinaryOperator::AtTimeZone. Reasons;

  • AT TIME ZONE is a binary operator like any other we have. The RHS can actually be any expression that resolves to a timezone, e.g. <expr> AT TIME ZONE ('America/' || 'Los_Angeles') works, as do column references, none of which successfully parse right now.
  • Once we support expressions on the RHS, a whole bunch of other precedence issues come into play. For example, does <expr> at time zone <tz> || 'foo' concat to the timezone or to the entire at time zone expr? (iirc it's the latter and pg will implicitly cast the ts to a string). We should be handling these ambiguities using the existing Pratt parsing logic we have.

@lovasoa
Copy link
Contributor

lovasoa commented May 10, 2024

agreed. but we should merge this pr first. It fixes a clear bug and does not require a refactoring

Copy link
Contributor

@jmhain jmhain left a comment

Choose a reason for hiding this comment

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

lgtm, cc @alamb

I filed #1270 for addressing my comment above.

@alamb
Copy link
Collaborator

alamb commented May 11, 2024

Thanks @dmitrybugakov @jmhain and @lovasoa 🙏

@coveralls
Copy link

Pull Request Test Coverage Report for Build 9029285843

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 35 of 40 (87.5%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 89.212%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tests/sqlparser_common.rs 14 15 93.33%
src/parser/mod.rs 21 25 84.0%
Files with Coverage Reduction New Missed Lines %
src/parser/mod.rs 1 92.83%
Totals Coverage Status
Change from base Build 9016176897: -0.003%
Covered Lines: 24470
Relevant Lines: 27429

💛 - Coveralls

@alamb alamb merged commit 49d1784 into sqlparser-rs:main May 11, 2024
10 checks passed
@dmitrybugakov dmitrybugakov deleted the fix-timezone-skipping-1266 branch May 11, 2024 19:57
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.

The DoubleColon cast always skips the AT TIME ZONE part, leading to strange behavior.
5 participants