-
Notifications
You must be signed in to change notification settings - Fork 58
Implicit Type Conversion for Temporal Types #569
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?
Implicit Type Conversion for Temporal Types #569
Conversation
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.
Hello @Song-Quan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request introduces implicit type conversion for temporal types. Specifically, it allows string representations of dates (YYYY-MM-DD and YYYY-MM-DD HH:MM:SS) to be implicitly converted to Unix timestamps (milliseconds since epoch) when used as constants in expressions. This is achieved by adding functions to check if a string is a date and to convert it to a Unix timestamp. The translator is modified to use these functions to convert string constants to int64 when appropriate.
Highlights
- Implicit Type Conversion: Implements implicit type conversion from string to Unix milliseconds for date/time constants.
- Date String Detection: Adds a utility function to detect if a string is in a valid date/time format (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS).
- String to Unix Milliseconds Conversion: Adds a utility function to convert a date/time string to Unix milliseconds.
Changelog
- pkg/interpreter/translator/translator.go
- Imports the
stringutil
package. - Adds logic to
getTensorFromExpression
to check if a constant is a date string and convert it to Unix milliseconds if it is.
- Imports the
- pkg/util/stringutil/string_util.go
- Adds
IsDateString
function to check if a string is a date. - Adds
StringToUnixMilli
function to convert a date string to Unix milliseconds.
- Adds
- pkg/util/stringutil/string_util_test.go
- Adds tests for
IsDateString
function. - Adds tests for
StringToUnixMilli
function.
- Adds tests for
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A string of time,
To numbers we must climb,
Convert with care.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces implicit type conversion for temporal types, specifically handling date strings by converting them to Unix milliseconds. This enhancement could be beneficial for systems that rely on numerical representations of time. However, there are several areas that need improvement, particularly around error handling, input validation, and code clarity.
Summary of Findings
- Error Handling: The
StringToUnixMilli
function could benefit from more robust error handling, especially when parsing dates. The current implementation returns 0 and an error for unsupported formats, which might not be the best approach. Consider returning a specific error value or using a more descriptive error message. - Input Validation: The
IsDateString
function uses regular expressions to validate date strings. While this approach works, it might be too restrictive. Consider allowing for more flexible date formats or providing a mechanism to configure the supported formats. - Code Clarity: The logic in
getTensorFromExpression
could be simplified to improve readability. Consider extracting the date parsing logic into a separate function or using a more concise way to check the string value and convert it to Unix milliseconds. - Potential Overflow: Converting date strings to Unix milliseconds using
UnixNano() / 1e6
could lead to potential overflow issues. Consider usingUnixMilli()
which is available in newer versions of Go.
Merge Readiness
The pull request is not ready for merging. There are several issues that need to be addressed before merging, including error handling, input validation, and code clarity. I recommend addressing these issues before merging. I am unable to approve this pull request, and users should have others review and approve this code before merging.
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.
please add some query test cases
{"2024-05-01", true}, | ||
{"2024-5-1", false}, | ||
{"2024-05-01 11:12:13", true}, | ||
{"2024-05-01T11:12:13Z", false}, |
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.
why is this kind of format not correct?
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.
UnixMilli()
can only deal with the string which format is YYYY-MM-DD hh:mm:ss
proto.PrimitiveDataType_FLOAT64: true, | ||
proto.PrimitiveDataType_STRING: true, | ||
}, | ||
proto.PrimitiveDataType_FLOAT32: { |
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.
do we need the cast between float32 and float64?
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'm not sure, conversions in this map is a temporary solution. Maybe we can add more conversions as needed
support query like
SELECT ta.ID, date FROM ta right join tb on ta.ID = tb.ID where '2025-04-23 12:25:42' < ta.date;