-
Notifications
You must be signed in to change notification settings - Fork 604
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
feat: Add to_date and to_time to StringValue #8908
Comments
@saschahofmann Your request makes sense! I'll look to implement this, with |
Cool. Also to happy to look into it but I would need some pointers on where these things are implemented. |
Amazing! So, ibis/ibis/expr/types/strings.py Lines 1275 to 1302 in 356e459
You would need to add functions for You'll also need to add a corresponding operator: ibis/ibis/expr/operations/temporal.py Line 74 in 356e459
Finally, you should add tests, like https://github.com/ibis-project/ibis/blob/main/ibis/backends/tests/test_temporal.py#L1431 Once you've done this, you implement translations. For example:
Since you're defining a new operator, it would require implementation across a lot of places in the codebase; let me know if this feels like something you want to tackle, first time diving into the codebase. Regardless, start small! You can fail the test for everything except BigQuery to start with, if you'd like. Also, happy to structure this in a way to set up some of the bases and you can focus on adding implementations for the backends you prefer; just let me know. |
Oh, also; I noticed that |
I guess in that case, it is acceptable to first drop the timezone? |
In general, I think we defer to the behavior of individual backends to some extent on these things. In the case of DuckDB, my understanding is they don't believe this to be a safe operation, and I'm somewhat inclined to agree. I'll also defer to @cpcloud, given he has a much clearer view on how Ibis usually treats these kinds of things. |
Alright. I finally started on adding to_date and already got a question on the SQLGlot implementation
I assume I don't see an equivalent for str_to_date. As we discussed the fallback could be to do |
I also took a look at bigquery/compiler.py but I have no idea whether something like this would just work. def visit_StringToDate(self, op, *, arg, format_str):
return self.f.parse_date(format_str, arg) or whether I can just add |
@saschahofmann -- if and in this case, since all the kwargs defined on the op are used in |
But do I need to both? Or is one of them enough? |
Just the one is sufficient |
## Description of changes * Adds `to_date` to string types that accepts a format string and parses a string to Date type. * Uses a cast to timestamp and extract time as a fallback like this ```python def visit_StringToDate(self, op, *, arg, format_str): return self.f.date(self.f.str_to_time(arg, format_str)) ``` * Implements native functions for bigquery, clickhouse, MySQL, oracle, postgres, and snowflake ## Issues closed Implements half of #8908 --------- Co-authored-by: Gil Forsyth <[email protected]>
Alright I'll finally have time to tackle the second part of this and add a to_time function if wanted. @deepyaman mentioned that DuckDB doesn't support this on purpose and that @cpcloud would have an opinion on that. Do you want to support |
Side note - if we're adding new conversion API methods, I think we might want to use an |
@saschahofmann Very sorry for not getting back to you sooner on this. Where possible, it seems it would make sense to use the time-specific parsing function (e.g. |
Alright! I will try to get to this soon! |
Is your feature request related to a problem?
No response
Describe the solution you'd like
I think it would make sense to have date and time parsing functions similar to the already existing
to_timestamp
function.A workaround right now could be to use
to_timestamp
and extract the time or date part but e.g. BigQuery supports extra parsing functionsPARSE_TIME
andPARSE_DATE
What version of ibis are you running?
8.0.0
What backend(s) are you using, if any?
BigQuery, Postgres
Code of Conduct
I agree to follow this project's Code of Conduct
to_date feat: add to_date function to StringValue #9030
to_time
The text was updated successfully, but these errors were encountered: