-
Notifications
You must be signed in to change notification settings - Fork 605
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: to_json_string
(alternatively, to_json
, but that could get confusing with the JSON type)
#9542
Comments
Seems like a good thing to add that wouldn't be particularly contentious, especially given it's already supported by multiple backends! |
Following #9788, I think we might be better served by an |
Looking more into this, IIUC semantically this should be the same as: t.some_col.cast("json").cast("string") If that's correct, I wonder if we could just stick with that spelling as a user-facing API. For backends that implement an optimized function (and may not handle this in their optimizer themselves?) we could always use a simple rewrite rule to compile to a specific one-call version like bigquery's |
BigQuery doesn't support casting to JSON directly.
fails with But, I can do this:
Similarly, I can't cast from
fails with So, the SQL for
Comparing the previous SQL with one that omits
I suspect the reason for the difference is that the JSON type in BQ is optimized for flexible schemas and lookups, so it is a more expensive type to build than just going straight to a JSON string. That's all to say, a specific optimization for |
Is your feature request related to a problem?
Some DB engines provide a TO_JSON_STRING or TO_JSON method to get a JSON serialization of an arbitrary value.
What is the motivation behind your request?
As seen in #9470, it can be useful to get a string representation of types, where cast to string is either ambiguous or not supported.
BigQuery DataFrames uses
TO_JSON_STRING
for the same reason (fallback for types that don't support cast to string) as well as for interop with extensions such as passing rows to Remote Functions.Describe the solution you'd like
Value.to_json_string()
would make sense to me. I would avoidValue.to_json()
, as I would expect that to return the JSON type in engines that support it.What version of ibis are you running?
8.x, working on 9.x upgrade
What backend(s) are you using, if any?
BigQuery
Code of Conduct
The text was updated successfully, but these errors were encountered: