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

parquet reader: Support reading decimals from parquet BYTE_ARRAY type #2160

Merged
merged 1 commit into from Jul 26, 2022

Conversation

liukun4515
Copy link
Contributor

Which issue does this PR close?

Closes #2159

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@@ -76,16 +76,6 @@ impl DecimalArrayConverter {
pub fn new(precision: i32, scale: i32) -> Self {
Self { precision, scale }
}

fn from_bytes_to_i128(b: &[u8]) -> i128 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move this method out and as a public method for this mod

@codecov-commenter
Copy link

Codecov Report

Merging #2160 (c7268f4) into master (1621c71) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2160      +/-   ##
==========================================
- Coverage   82.85%   82.83%   -0.02%     
==========================================
  Files         237      237              
  Lines       61381    61461      +80     
==========================================
+ Hits        50856    50913      +57     
- Misses      10525    10548      +23     
Impacted Files Coverage Δ
parquet/src/arrow/array_reader/builder.rs 93.46% <100.00%> (+0.31%) ⬆️
parquet/src/arrow/arrow_reader.rs 92.81% <100.00%> (+0.05%) ⬆️
parquet/src/arrow/buffer/converter.rs 84.26% <100.00%> (+0.93%) ⬆️
parquet/src/arrow/schema.rs 96.93% <100.00%> (+0.05%) ⬆️
parquet/src/arrow/schema/primitive.rs 80.86% <100.00%> (+3.87%) ⬆️
parquet/src/basic.rs 91.56% <100.00%> (+0.06%) ⬆️
arrow/src/array/iterator.rs 86.45% <0.00%> (-13.55%) ⬇️
arrow/src/util/decimal.rs 86.92% <0.00%> (-4.59%) ⬇️
arrow/src/array/array_decimal.rs 90.32% <0.00%> (-0.72%) ⬇️
arrow/src/datatypes/datatype.rs 62.69% <0.00%> (-0.32%) ⬇️
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@alamb alamb changed the title parquet reader: support read decimal from parquet binary type parquet reader: Support reading decimals from parquet BYTE_ARRAY type Jul 25, 2022
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.

This change makes sense to me -- thank you @liukun4515

Field::new("decimal1", DataType::Decimal(4,2), false),
Field::new("decimal2", DataType::Decimal(12,2), false),
Field::new("decimal3", DataType::Decimal(30,2), false),
Field::new("decimal4", DataType::Decimal(33,2), false),
Copy link
Contributor

Choose a reason for hiding this comment

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

this would this have previously failed?

Copy link
Member

Choose a reason for hiding this comment

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

Yea, this has previously failed as I just ran this test to confirm.

---- arrow::schema::tests::test_decimal_fields stdout ----
thread 'arrow::schema::tests::test_decimal_fields' panicked at 'called `Result::unwrap()` on an `Err` value: ArrowError("Unable to convert parquet BYTE_ARRAY logical type Some(Decimal { scale: 2, precision: 33 }) or converted type DECIMAL")', parquet/src/arrow/schema.rs:1734:60

@@ -233,6 +225,18 @@ fn build_primitive_reader(
column_desc,
arrow_type,
),
Some(DataType::Decimal(precision, scale)) => {
// read decimal data from parquet binary physical type
let convert = DecimalByteArrayConvert::new(DecimalArrayConverter::new(precision as i32, scale as i32));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the core change?

(namely to support reading arrow DataType::Decimal from parquet BYTE_ARRAY type where previously the code only supported DataType::Decimal in `FIXED_LEN_BYTE_ARRAY fields)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.
previously, decimal just can be read from int32,int64,byte_array, but in the definition of parquet decimal can be read from int32,int64,byte_array,fixed_length_byte_array.

@alamb
Copy link
Contributor

alamb commented Jul 25, 2022

Other reviewers might find the context on https://github.com/apache/arrow-datafusion/pull/2960/files#r928343239 helpful

// read decimal data from parquet binary physical type
let convert = DecimalByteArrayConvert::new(DecimalArrayConverter::new(precision as i32, scale as i32));
Ok(Box::new(
ComplexObjectArrayReader::<ByteArrayType,DecimalByteArrayConvert>::new(
Copy link
Member

Choose a reason for hiding this comment

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

style?

Suggested change
ComplexObjectArrayReader::<ByteArrayType,DecimalByteArrayConvert>::new(
ComplexObjectArrayReader::<ByteArrayType, DecimalByteArrayConvert>::new(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code has been formatted.

@liukun4515 liukun4515 merged commit 37dd037 into apache:master Jul 26, 2022
@liukun4515 liukun4515 deleted the decimal_parquet_binary_support branch July 26, 2022 02:59
@ursabot
Copy link

ursabot commented Jul 26, 2022

Benchmark runs are scheduled for baseline = ec3530d and contender = 37dd037. 37dd037 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

read decimal data type from parquet file with binary physical type
5 participants