-
Notifications
You must be signed in to change notification settings - Fork 63
chore: Migrate IntegerLabelToDatetimeOp operator to SQLGlot #2310
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
base: main
Are you sure you want to change the base?
Conversation
| to=sge.DataType.build("INT64"), | ||
| ), | ||
| ), | ||
| to=_dtype_to_sql_string(y.dtype), # type: ignore |
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.
we can call sqlglot_types.from_bigframes_dtype instead and remove "# type: igore"
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.
Yeah better.
| this=first, to=sge.DataType.build("BIGNUMERIC") | ||
| ), | ||
| ), | ||
| to=sge.DataType.build("INT64"), |
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.
to="INT64" works too and can simple the expression a little bit. If so, can we apply to all the "to" parameter of the "sge.Cast" method?
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.
Yeah it works.
| us = n * 7 * 24 * 60 * 60 * 1000000 | ||
| first = sge.func( | ||
| "UNIX_MICROS", | ||
| sge.Add( | ||
| this=sge.TimestampTrunc( | ||
| this=sge.Cast(this=y.expr, to="TIMESTAMP"), | ||
| unit=sge.Var(this="WEEK(MONDAY)"), | ||
| ), | ||
| expression=sge.Interval( | ||
| this=sge.convert(6), unit=sge.Identifier(this="DAY") | ||
| ), | ||
| ), | ||
| ) | ||
| x_label = sge.Cast( | ||
| this=sge.func( | ||
| "TIMESTAMP_MICROS", | ||
| sge.Cast( | ||
| this=sge.Add( | ||
| this=sge.Mul( | ||
| this=sge.Cast(this=x.expr, to="BIGNUMERIC"), | ||
| expression=sge.convert(us), | ||
| ), | ||
| expression=sge.Cast(this=first, to="BIGNUMERIC"), | ||
| ), | ||
| to="INT64", | ||
| ), | ||
| ), | ||
| to=sqlglot_types.from_bigframes_dtype(y.dtype), | ||
| ) |
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.
Style nit: could we define separate helper functions to handle different frequencies? This would help reduce the size of the function _integer_label_to_datetime_op_non_fixed_frequency and improve readability.
The improved function should look like this
def _integer_label_to_datetime_op_non_fixed_frequency():
....
if rule_code is weekly:
return _integer_label_to_datetime_op_weekly_freq()
elif rule_code is monthly:
....
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes b/447388852 🦕