Skip to content

Implement BigQuery Partition By statements using sqlglot #2722

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

Open
wants to merge 39 commits into
base: devel
Choose a base branch
from

Conversation

hsm207
Copy link
Collaborator

@hsm207 hsm207 commented Jun 5, 2025

Description

Imeplement

Implenent BigQuery Partition By statements using sqlglot

Related Issues

Additional Context

Copy link

netlify bot commented Jun 5, 2025

Deploy Preview for dlt-hub-docs canceled.

Name Link
🔨 Latest commit 1a2ee5e
🔍 Latest deploy log https://app.netlify.com/projects/dlt-hub-docs/deploys/68535b210f40520008e5afb3

@hsm207 hsm207 changed the title Implenent BigQuery Partition By statements using sqlglot Implement BigQuery Partition By statements using sqlglot Jun 6, 2025
from typing import Any, Dict, Type, TypeVar, Union, Literal

# Constant to avoid magic strings
PARTITION_SPEC_TYPE_KEY = "_dlt_partition_spec_type"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rudolfix if we remove the legacy ways to specify the partition expression, then we don't need this anymore.

@@ -213,7 +217,7 @@ def test_create_table_with_partition_and_cluster(gcp_client: BigQueryClient) ->
sqlfluff.parse(sql, dialect="bigquery")
# clustering must be the last
assert sql.endswith("CLUSTER BY `col2`, `col5`")
assert "PARTITION BY `col10`" in sql
assert "PARTITION BY `col10`" in sql or "PARTITION BY col10" in sql
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rudolfix do you prefer to just remove col10? By default, sqlglot does not quote the column name if it is not needed e.g. names with space

@hsm207 hsm207 marked this pull request as ready for review June 18, 2025 22:07
@hsm207 hsm207 requested a review from rudolfix June 19, 2025 00:23
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.

Use sqlglot to create partition by expressions in BigQuery
1 participant