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

Fails to parse TypedString expressions in BigQuery with triple quoted strings #1673

Closed
MartinSahlen opened this issue Jan 21, 2025 · 1 comment · Fixed by #1679
Closed

Fails to parse TypedString expressions in BigQuery with triple quoted strings #1673

MartinSahlen opened this issue Jan 21, 2025 · 1 comment · Fixed by #1679

Comments

@MartinSahlen
Copy link
Contributor

i.e

select JSON """{"name": "Alice", "age": 30}"""

fails. More examples can also be found here.

I also tried to do things like SELECT timestamp """{"name": "Alice", "age": 30}""" which also fails.

Error message is:

called `Result::unwrap()` on an `Err` value: ParserError("Expected: end of statement, found: \"\"\"{\"name\": \"Alice\", \"age\": 30}\"\"\" at Line: 7, Column: 13")
@graup
Copy link
Contributor

graup commented Jan 23, 2025

The issue here is that parse_literal_string which is used by TypedString doesn't support quote styles other than single or double quoted strings.

Trying to fix this I came across two related issues:

  • currently TypedString doesn't retain any knowledge about the used quote style, so it doesn't roundtrip properly. It always formats as a single quoted string.
    • We can fix this by making TypedString contain a Value instead of a String. This also gives us support for other quote styles, addressing the issue reported here.
  • fmt::Display for EscapeQuotedString doesn't take into account the dialect, producing strings like 'foo''bar' which is invalid in BQ (should be 'foo\'bar'). So something like this SELECT JSON "{\"foo\":\"bar's\"}" currently also doesn't get formatted correctly
    • Not sure how to fix this one, seems a bit more involved.

I'll push a PR addressing this in a moment.

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 a pull request may close this issue.

2 participants