Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

feat: (Preview) Support automatic load of timedelta from BQ tables.#1429

Merged
sycai merged 20 commits intomainfrom
sycai_timedelta_autoload
Mar 4, 2025
Merged

feat: (Preview) Support automatic load of timedelta from BQ tables.#1429
sycai merged 20 commits intomainfrom
sycai_timedelta_autoload

Conversation

@sycai
Copy link
Copy Markdown
Contributor

@sycai sycai commented Feb 25, 2025

This works only with read_gbq_table() under the hood, because read_gbq_query() erases column descriptions.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Feb 25, 2025
@sycai sycai marked this pull request as ready for review February 26, 2025 20:56
@sycai sycai requested review from a team and GarrettWu February 26, 2025 20:56
@sycai sycai requested review from TrevorBergeron, chelsea-lin and tswast and removed request for GarrettWu February 26, 2025 20:57
@tswast tswast added the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 26, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 26, 2025
Comment thread bigframes/dtypes.py Outdated
Comment thread bigframes/session/executor.py Outdated
@sycai sycai requested a review from tswast February 27, 2025 17:52
Comment thread bigframes/session/executor.py Outdated
Comment thread bigframes/dataframe.py Outdated
@sycai
Copy link
Copy Markdown
Contributor Author

sycai commented Feb 27, 2025

Closing the PR for now to think about annotations for RECORD and ARRAY. I will prepare another PR once everything falls into place

@sycai sycai closed this Feb 27, 2025
@sycai sycai reopened this Mar 3, 2025
@sycai sycai requested a review from TrevorBergeron March 3, 2025 23:24
Comment thread bigframes/session/executor.py Outdated
self._attach_timedelta_metadata(query_job.destination, array_value)
return query_job

def _attach_timedelta_metadata(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not put this logic instead in convert_to_schema_field? it is the natural inverse of convert_schema_field

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call! That makes the code cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Though interestingly, in export_gbq we rely on the BigQuery engine to figure out the schema based on the provided SQL. I need to update the schema again afterwards to include the tag

Comment thread bigframes/dtypes.py Outdated
elif (
field.field_type == "INTEGER"
and field.description is not None
and TIMEDELTA_DESCRIPTION_TAG in field.description
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: but I do wonder if once in a while, we might catch a user description that accidentally uses '#microseconds' somewhere? maybe restrict to beginning, or put some odds character sequence to ensure non-accidental triggering

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SG. Changed the logic to check whether the description ends with the tag.

@sycai sycai requested a review from TrevorBergeron March 4, 2025 00:09
Comment thread bigframes/session/executor.py Outdated
@sycai sycai enabled auto-merge (squash) March 4, 2025 01:21
@sycai sycai merged commit b2917bb into main Mar 4, 2025
@sycai sycai deleted the sycai_timedelta_autoload branch March 4, 2025 06:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants