Skip to content
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

Add support for MapArray in json writer #1149

Merged
merged 1 commit into from Jan 11, 2022
Merged

Conversation

helgikrs
Copy link
Contributor

@helgikrs helgikrs commented Jan 10, 2022

Which issue does this PR close?

This PR adds map arrays into the json writer, tracked by #538.

What changes are included in this PR?

This PR adds support for writing map arrays to json and a new test for this functionality in the json writer.

Are there any user-facing changes?

Adds a new public function, as_map_array, to arrow::array::cast.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 10, 2022
@alamb alamb requested a review from nevi-me January 10, 2022 22:03
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @helgikrs -- looks good to me


// Keys have to be strings to convert to json.
if !matches!(keys.data_type(), DataType::Utf8) {
panic!("Unsupported datatype: {:#?}", array.data_type());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be much nicer if this code did not panic when there was an unsupported datatype. However, I see that the the signature for set_column_for_json_rows does not return a Result 😢

I'll file a follow on ticket and see if someone in the community is interesting in improving this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false,
);

// [{"foo": 10}, null, {}, {"bar": 20, "baz": 30, "qux": 40}, {"quux": 50}, {}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have a better / nicer way to contruct MapArrays -- again not for this PR but eventually it would be nice to have something like

https://docs.rs/arrow/6.5.0/arrow/array/struct.StructArray.html

I will file another ticket

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb
Copy link
Contributor

alamb commented Jan 11, 2022

Thanks again @helgikrs

@alamb alamb added the enhancement Any new improvement worthy of a entry in the changelog label Jan 20, 2022
@alamb alamb changed the title feat(json): support for map arrays in json writer Add support for map arrays in json writer Jan 20, 2022
@alamb alamb changed the title Add support for map arrays in json writer Add support for MapArray in json writer Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants