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

Support reading decimal arrays from json #3805

Merged
merged 9 commits into from
Mar 6, 2023

Conversation

spebern
Copy link
Contributor

@spebern spebern commented Mar 5, 2023

Which issue does this PR close?

Closes #2900

Rationale for this change

The json reader does not support parsing into a decimal array.

What changes are included in this PR?

Support parsing json into decimal array fields.

Are there any user-facing changes?

82408a9?diff=unified#diff-b5489a31aca7aecfa14106360899e04266d43dfdd365638382b0f5bcfb91266bR711


When "123.456" (string) is parsed into a decimal with precision 5, then the 6 at the end will get cut off. I took this behavior from the csv logic and am wondering if it might be worth to round here?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Mar 5, 2023
arrow-array/src/types.rs Outdated Show resolved Hide resolved
arrow-array/src/types.rs Outdated Show resolved Hide resolved
arrow-array/src/types.rs Outdated Show resolved Hide resolved
arrow-array/src/types.rs Outdated Show resolved Hide resolved
@@ -1019,6 +1019,72 @@ impl Decoder {
))
}

fn build_decimal128_array(
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI Decoder is deprecated and slated to be removed shortly #3610

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have noticed it. The json reader is used in https://github.com/delta-io/delta-rs/tree/main/rust with the serde Value arguments. Maybe I can find some time to integrate the new interface, but for now it would already help if decimals were supported in the old decoder.

Thank you for your time to review it and point me to the locations of adding the parsing logic. I mostly moved it out of arrow-csv.

arrow-cast/src/parse.rs Outdated Show resolved Hide resolved
arrow-cast/src/parse.rs Outdated Show resolved Hide resolved
@@ -3352,4 +3417,72 @@ mod tests {
let cloned = options.clone();
assert_eq!(options, cloned);
}

macro_rules! decimal_json_tests {
Copy link
Contributor

@tustvold tustvold Mar 6, 2023

Choose a reason for hiding this comment

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

Does this need to be a macro, or could we use a generic function here? They're easier to maintain and debug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced the macro by a generic function. Maybe the bounds can be written in a better way though.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed f7e4aa6 which cleans up the constraints a little

tustvold
tustvold previously approved these changes Mar 6, 2023
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

Just some minor nits

spebern and others added 3 commits March 6, 2023 19:50
Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
Co-authored-by: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com>
arrow-json/src/reader.rs Outdated Show resolved Hide resolved
arrow-json/src/reader.rs Outdated Show resolved Hide resolved
arrow-json/src/reader.rs Outdated Show resolved Hide resolved
@tustvold tustvold dismissed their stale review March 6, 2023 20:47

Incorrect test

@tustvold tustvold merged commit 3df7c00 into apache:master Mar 6, 2023
@ursabot
Copy link

ursabot commented Mar 6, 2023

Benchmark runs are scheduled for baseline = 7f460af and contender = 3df7c00. 3df7c00 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@bubbajoe
Copy link

bubbajoe commented Mar 7, 2023

Late, but should Scientific notation also be supported?

@tustvold
Copy link
Contributor

tustvold commented Mar 7, 2023

I think that would be a valuable further enhancement

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support reading DecimalArray from JSON data
4 participants