Skip to content

feat: add date functions to bigframes.bigquery module#17514

Open
tswast wants to merge 1 commit into
mainfrom
tswast-bbq
Open

feat: add date functions to bigframes.bigquery module#17514
tswast wants to merge 1 commit into
mainfrom
tswast-bbq

Conversation

@tswast

@tswast tswast commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Used the following prompt:

Update the descriptions and argument names in scripts/data/sql-functions/global-namespace/date.yaml according to the following SQL documentation:

(Paste from https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/date_functions)

Also, if there is a natural argument to use for series_accessor_arg in this yaml or others, add it.

Towards BigQuery SQL API coverage. 🦕

Used the following prompt:

> Update the descriptions and argument names in scripts/data/sql-functions/global-namespace/date.yaml according to the following SQL documentation:
>
> (Paste from https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/date_functions)
>
> Also, if there is a natural argument to use for `series_accessor_arg` in this yaml or others, add it.
@tswast tswast requested review from a team as code owners June 18, 2026 21:07
@tswast tswast requested review from mpovoa and removed request for a team June 18, 2026 21:07
"timestamp": "dtypes.TIMESTAMP_DTYPE",
"decimal<38,9>": "dtypes.NUMERIC_DTYPE",
"decimal<76,38>": "dtypes.BIGNUMERIC_DTYPE",
"interval_day": "dtypes.TIMEDELTA_DTYPE",

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.

Not strictly true, but OK for now?

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces support for BigQuery date operations in BigFrames, including the generation of date functions, series accessors, and corresponding unit tests. The reviewer identified several issues in the date.yaml configuration file where timestamp signatures were incorrectly added to functions that only support DATE or DATETIME expressions in BigQuery (such as DATE_ADD, DATE_BUCKET, DATE_DIFF, DATE_SUB, DATE_TRUNC, FORMAT_DATE, and LAST_DAY). Additionally, the reviewer noted that the EXTRACT function signatures omitting the required part argument are incorrect and should be removed to prevent runtime SQL compilation errors.

Comment on lines +83 to +97
# Signature: date_add:pts_i64_any
- args:
- name: "date_expression"
value: timestamp
optional: false
keyword_only: false
- name: "int64_expression"
value: i64
optional: false
keyword_only: false
- name: "date_part"
value: any1
optional: false
keyword_only: false
return: timestamp

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.

high

In BigQuery, the DATE_ADD function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides a separate TIMESTAMP_ADD function. Including the timestamp signature here will cause bigframes to generate invalid SQL (e.g., DATE_ADD(timestamp_col, ...)), which will fail with a compilation error at runtime in BigQuery. Please remove this signature.

Comment on lines +117 to +131
# Signature: date_bucket:pts_iday_pts
- args:
- name: "date_in_bucket"
value: timestamp
optional: false
keyword_only: false
- name: "bucket_width"
value: interval_day
optional: false
keyword_only: false
- name: "bucket_origin"
value: timestamp
optional: true
keyword_only: false
return: timestamp

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.

high

In BigQuery, the DATE_BUCKET function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides TIMESTAMP_BUCKET. Including the timestamp signature here will cause runtime SQL compilation errors. Please remove this signature.

Comment on lines +151 to +165
# Signature: date_diff:pts_pts_any
- args:
- name: "end_date"
value: timestamp
optional: false
keyword_only: false
- name: "start_date"
value: timestamp
optional: false
keyword_only: false
- name: "granularity"
value: any1
optional: false
keyword_only: false
return: i64

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.

high

In BigQuery, the DATE_DIFF function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides TIMESTAMP_DIFF. Including the timestamp signature here will cause runtime SQL compilation errors. Please remove this signature.

Comment on lines +196 to +210
# Signature: date_sub:pts_i64_any
- args:
- name: "date_expression"
value: timestamp
optional: false
keyword_only: false
- name: "int64_expression"
value: i64
optional: false
keyword_only: false
- name: "date_part"
value: any1
optional: false
keyword_only: false
return: timestamp

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.

high

In BigQuery, the DATE_SUB function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides TIMESTAMP_SUB. Including the timestamp signature here will cause runtime SQL compilation errors. Please remove this signature.

Comment on lines +226 to +251
# Signature: date_trunc:pts_any
- args:
- name: "date_value"
value: timestamp
optional: false
keyword_only: false
- name: "granularity"
value: any1
optional: false
keyword_only: false
return: timestamp
# Signature: date_trunc:pts_any_str
- args:
- name: "date_value"
value: timestamp
optional: false
keyword_only: false
- name: "granularity"
value: any1
optional: false
keyword_only: false
- name: "time_zone"
value: string
optional: true
keyword_only: false
return: timestamp

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.

high

In BigQuery, the DATE_TRUNC function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides TIMESTAMP_TRUNC. Including the timestamp signatures here will cause runtime SQL compilation errors. Please remove these signatures.

Comment on lines +315 to +332
# Signature: extract:pts_str
- args:
- name: "date_expression"
value: timestamp
optional: false
keyword_only: false
- name: "time_zone"
value: string
optional: true
keyword_only: false
return: time
# Signature: extract:pts
- args:
- name: "date_expression"
value: timestamp
optional: false
keyword_only: false
return: time

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.

high

In BigQuery, the EXTRACT function always requires a part argument (e.g., EXTRACT(part FROM expression)). The signatures extract:pts_str and extract:pts omit the part argument, which is incorrect and will cause signature matching issues or invalid SQL generation. Please remove these incorrect signatures.

Comment on lines +348 to +373
# Signature: format_date:str_pts
- args:
- name: "format_string"
value: string
optional: false
keyword_only: false
- name: "date_expr"
value: timestamp
optional: false
keyword_only: false
return: string
# Signature: format_date:str_pts_str
- args:
- name: "format_string"
value: string
optional: false
keyword_only: false
- name: "date_expr"
value: timestamp
optional: false
keyword_only: false
- name: "time_zone"
value: string
optional: true
keyword_only: false
return: string

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.

high

In BigQuery, the FORMAT_DATE function only supports DATE expressions. For TIMESTAMP expressions, BigQuery provides FORMAT_TIMESTAMP. Including the timestamp signatures here will cause runtime SQL compilation errors. Please remove these signatures.

Comment on lines +411 to +421
# Signature: last_day:pts_any
- args:
- name: "date_expression"
value: timestamp
optional: false
keyword_only: false
- name: "date_part"
value: any1
optional: true
keyword_only: false
return: date

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.

high

In BigQuery, the LAST_DAY function only supports DATE and DATETIME expressions, not TIMESTAMP expressions. Including the timestamp signature here will cause runtime SQL compilation errors. Please remove this signature.

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.

1 participant