This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
chore: Migrate IntegerLabelToDatetimeOp operator to SQLGlot #2310
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
af06fdd
chore: Migrate IntegerLabelToDatetimeOp operator to SQLGlot
jialuoo a537ad1
fix
jialuoo c13737e
Merge branch 'main' into migrate-integer-label-to-datetime-op
jialuoo 71ff340
Update datetime_ops.py
jialuoo 17a41a9
fix unit tests
jialuoo 761ec5f
fix mypy
jialuoo 522b388
resolve the comments
jialuoo 700bfae
refactoring
jialuoo 2d2ebb4
fix lint
jialuoo 6cc5d0a
refactor integer_label_to_datetime_op
jialuoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...le/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime/out.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| WITH `bfcte_0` AS ( | ||
| SELECT | ||
| `rowindex`, | ||
| `timestamp_col` | ||
| FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` | ||
| ), `bfcte_1` AS ( | ||
| SELECT | ||
| *, | ||
| CAST(TIMESTAMP_MICROS( | ||
| CAST(CAST(`rowindex` AS BIGNUMERIC) * 86400000000 + CAST(UNIX_MICROS(CAST(`timestamp_col` AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) | ||
| ) AS TIMESTAMP) AS `bfcol_2`, | ||
| CAST(DATETIME( | ||
| CASE | ||
| WHEN ( | ||
| MOD( | ||
| `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, | ||
| 4 | ||
| ) + 1 | ||
| ) * 3 = 12 | ||
| THEN CAST(FLOOR( | ||
| IEEE_DIVIDE( | ||
| `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, | ||
| 4 | ||
| ) | ||
| ) AS INT64) + 1 | ||
| ELSE CAST(FLOOR( | ||
| IEEE_DIVIDE( | ||
| `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, | ||
| 4 | ||
| ) | ||
| ) AS INT64) | ||
| END, | ||
| CASE | ||
| WHEN ( | ||
| MOD( | ||
| `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, | ||
| 4 | ||
| ) + 1 | ||
| ) * 3 = 12 | ||
| THEN 1 | ||
| ELSE ( | ||
| MOD( | ||
| `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, | ||
| 4 | ||
| ) + 1 | ||
| ) * 3 + 1 | ||
| END, | ||
| 1, | ||
| 0, | ||
| 0, | ||
| 0 | ||
| ) - INTERVAL 1 DAY AS TIMESTAMP) AS `bfcol_3` | ||
| FROM `bfcte_0` | ||
| ) | ||
| SELECT | ||
| `bfcol_2` AS `fixed_freq`, | ||
| `bfcol_3` AS `non_fixed_freq` | ||
| FROM `bfcte_1` |
16 changes: 16 additions & 0 deletions
16
...glot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_fixed/out.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| WITH `bfcte_0` AS ( | ||
| SELECT | ||
| `rowindex`, | ||
| `timestamp_col` | ||
| FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` | ||
| ), `bfcte_1` AS ( | ||
| SELECT | ||
| *, | ||
| CAST(TIMESTAMP_MICROS( | ||
| CAST(CAST(`rowindex` AS BIGNUMERIC) * 86400000000 + CAST(UNIX_MICROS(CAST(`timestamp_col` AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) | ||
| ) AS TIMESTAMP) AS `bfcol_2` | ||
| FROM `bfcte_0` | ||
| ) | ||
| SELECT | ||
| `bfcol_2` AS `fixed_freq` | ||
| FROM `bfcte_1` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability, can we move this "if" clauses to the
integer_label_to_datetime_opfunction"? In this way, we don't need to raise "ValueError" anymore. The expected functioninteger_label_to_datetime_opwould be like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve flattened the logic as suggested, but kept the ValueError to explicitly handle cases with an unsupported frequency rule code (e.g. rule_code='an_unsupported_value') so that this implementation’s error-handling remains consistent with the original logic: e.g. when both
rule_codeandop.freq.nanoshave valid values, it should go to the non-fixed frequency case, not the fixed one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into it. It sounds reasonable to me.