feat: add json_arrow_type parameter to allow overriding the JSON data type in to_arrow and to_arrow_iterable#2149
Closed
feat: add json_arrow_type parameter to allow overriding the JSON data type in to_arrow and to_arrow_iterable#2149
json_arrow_type parameter to allow overriding the JSON data type in to_arrow and to_arrow_iterable#2149Conversation
…o_dataframe` * add regression tests for empty dataframe * fix arrow test to be compatible with old pyarrow
…ta type in `to_arrow` and `to_arrow_iterable`
6 tasks
tswast
commented
Mar 19, 2025
| ] | ||
|
|
||
|
|
||
| def test_to_arrow_with_json_arrow_type(): |
Contributor
Author
There was a problem hiding this comment.
Currently fails with
rows = google.cloud.bigquery.table.RowIterator(
client=None,
api_request=None,
path=None,
schema=[
bigquery.SchemaField.from_api_repr(field)
for field in resource["schema"]["fields"]
],
first_page_response=resource,
)
> records = rows.to_arrow(json_arrow_type=db_dtypes.JSONArrowType())
tests/unit/test_table_arrow.py:275:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
google/cloud/bigquery/table.py:2227: in to_arrow
return pyarrow.Table.from_batches(record_batches, schema=arrow_schema)
pyarrow/table.pxi:4994: in pyarrow.lib.Table.from_batches
???
pyarrow/error.pxi:155: in pyarrow.lib.pyarrow_internal_check_status
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E pyarrow.lib.ArrowInvalid: Schema at index 0 was different:
E json: extension<dbjson<JSONArrowType>>
E reference: struct<uri: string, authorizer: string, version: string, details: extension<dbjson<JSONArrowType>>>
E repeated_json: list<item: extension<dbjson<JSONArrowType>>> not null
E vs
E json: string
E reference: struct<uri: string, authorizer: string, version: string, details: string>
E repeated_json: list<item: string> not null
pyarrow/error.pxi:92: ArrowInvalid
I think we need to call https://arrow.apache.org/docs/python/generated/pyarrow.compute.cast.html instead of relying on the Table.from_batches constructor.
Contributor
Author
|
I think we'll need some kind of two-phase thing where we take the schema as we would get from the BQ Storage Read API and manually cast each field/subfield into the desired type to make it work. I don't think the approach I'm using in this PR as of now will work. It'll have to do some post-processing on the arrow Table we'd normally get. |
… JSON data type in `to_arrow` and `to_arrow_iterable`" This reverts commit c47db36.
Contributor
Author
|
Closing as obsolete. Ideally we stay consistent with the BQ Storage API. We should revisit this if the BQ Storage API adds support for the JSON extension type. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #1876 (comment)
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 #<issue_number_goes_here> 🦕