Commit 7e1a710
authored
fix(unparser): make
## Which issue does this PR close?
PR improves `BigQueryDialect` dialect to make generated SQL
`BigQuery`-compatible (fix execution errors).
## What changes are included in this PR?
Eight `Dialect` trait overrides added to `BigQueryDialect`:
https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types
1. `date_field_extract_style` → `Extract` +
`scalar_function_to_sql_overrides`
BigQuery does not support `date_part()`. TPC-H Q7, Q8, Q9 fail with
`Function not found: date_part`.
| Before (error) | After |
|---|---|
| `date_part('YEAR', l_shipdate)` | `EXTRACT(YEAR FROM l_shipdate)` |
2. `interval_style` → `SQLStandard`
BigQuery does not support PostgreSQL-style interval abbreviations. TPC-H
Q4, Q20 fail with `Syntax error: Unexpected ")"`.
| Before (error) | After |
|---|---|
| `INTERVAL '3 MONS'` | `INTERVAL '3' MONTH` |
3. `float64_ast_dtype` → `Float64`
BigQuery does not support `DOUBLE`. Fails with `Type not found: DOUBLE`.
| Before (error) | After |
|---|---|
| `CAST(a AS DOUBLE)` | `CAST(a AS FLOAT64)` |
4. `supports_column_alias_in_table_alias` → `false`
BigQuery does not support column aliases in table alias definitions.
Fails with `Expected ")" but got "("`.
| Before (error) | After |
|---|---|
| `SELECT c.key FROM (...) AS c(key)` | `SELECT c.key FROM (SELECT
o_orderkey AS key FROM orders) AS c` |
5. `utf8_cast_dtype` + `large_utf8_cast_dtype` → `String`
BigQuery does not support `VARCHAR`/`TEXT`. Fails with `Type not found:
VARCHAR`, `Type not found: Text`.
| Before (error) | After |
|---|---|
| `CAST(a AS VARCHAR)` | `CAST(a AS STRING)` |
| `CAST(a AS TEXT)` | `CAST(a AS STRING)` |
6. ~`int64_cast_dtype` → `Int64`~
7. `timestamp_cast_dtype` → `Timestamp` (no timezone qualifier)
https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/data-types#timestamp_type
BigQuery does not support `TIMESTAMP WITH TIME ZONE`. Fails with `Syntax
error: Expected ')' or keyword FORMAT but got keyword WITH`. `TIMESTAMP`
should be used (preserves time zone information)/
| Before (error) | After |
|---|---|
| `CAST(a AS TIMESTAMP WITH TIME ZONE)` | `CAST(a AS TIMESTAMP)` |
## Are these changes tested?
Yes. Added `test_bigquery_dialect_overrides` unit test covering all
eight overrides, verified against BigQuery before and after.
## Are there any user-facing changes?
No API changes. `BigQueryDialect` now generates valid BigQuery SQL for
the affected expressions.BigQueryDialect more robust (#21296)1 parent fd882fb commit 7e1a710
2 files changed
Lines changed: 94 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
667 | 712 | | |
668 | 713 | | |
669 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3526 | 3526 | | |
3527 | 3527 | | |
3528 | 3528 | | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
3529 | 3578 | | |
0 commit comments