Skip to content

fix: Support partitioning by DATE or Date #1116

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions sqlalchemy_bigquery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ def visit_label(self, *args, within_group_by=False, **kwargs):
column_label = args[0]
sql_keywords = {"GROUPING SETS", "ROLLUP", "CUBE"}
for keyword in sql_keywords:
if keyword in str(column_label):
break
# if keyword in str(column_label):
# break
pass
else: # for/else always happens unless break gets called
kwargs["render_label_as_label"] = column_label

Expand Down Expand Up @@ -838,7 +839,7 @@ def _process_time_partitioning(
field = time_partitioning.field
if isinstance(
table.columns[time_partitioning.field].type,
sqlalchemy.sql.sqltypes.DATE,
(sqlalchemy.sql.sqltypes.DATE, sqlalchemy.sql.sqltypes.Date),
):
return f"PARTITION BY {field}"
elif isinstance(
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_table_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,15 @@ def test_table_time_partitioning_with_timestamp_dialect_option(faux_conn):
)


def test_table_time_partitioning_with_date_dialect_option(faux_conn):
@pytest.mark.parametrize("date_type", [sqlalchemy.DATE, sqlalchemy.Date])
def test_table_time_partitioning_with_date_dialect_option(faux_conn, date_type):
# expect table creation to fail as SQLite does not support partitioned tables
with pytest.raises(sqlite3.OperationalError):
setup_table(
faux_conn,
"some_table_2",
sqlalchemy.Column("id", sqlalchemy.Integer),
sqlalchemy.Column("createdAt", sqlalchemy.DATE),
sqlalchemy.Column("createdAt", date_type),
bigquery_time_partitioning=TimePartitioning(field="createdAt"),
)

Expand Down