You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "korowa (via GitHub)" <gi...@apache.org> on 2025/01/16 05:18:49 UTC
[PR] fix: column writer for dictionary decimal primitive type [arrow-rs]
korowa opened a new pull request, #6987:
URL: https://github.com/apache/arrow-rs/pull/6987
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Currently Parquet reads/writes for Arrow `Dictionary(Decimal)` type where Decimal is INT-based is falling back to `arrow_cast::cast`, which leads to losing precision.
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
For `Dictionary(Decimal)` type where decimal is int-based, writer and reader now perform `arrow_cast::cast` only for dictionary packing/unpacking, while values are only casted to required integer type without being modified, similar to how regular `Decimal` works.
# Are there any user-facing changes?
No
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please call them out.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: column writer for dictionary decimal primitive type [arrow-rs]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #6987:
URL: https://github.com/apache/arrow-rs/pull/6987#discussion_r1918983332
##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -270,6 +270,59 @@ where
Arc::new(array) as ArrayRef
}
+ ArrowType::Dictionary(_, value_type) => match value_type.as_ref() {
+ ArrowType::Decimal128(p, s) => {
+ let array = match array.data_type() {
+ ArrowType::Int32 => array
+ .as_any()
+ .downcast_ref::<Int32Array>()
+ .unwrap()
+ .unary(|i| i as i128)
+ as Decimal128Array,
+ ArrowType::Int64 => array
+ .as_any()
+ .downcast_ref::<Int64Array>()
+ .unwrap()
+ .unary(|i| i as i128)
+ as Decimal128Array,
+ _ => {
+ return Err(arrow_err!(
+ "Cannot convert {:?} to decimal dictionary",
+ array.data_type()
+ ));
+ }
+ }
+ .with_precision_and_scale(*p, *s)?;
+
+ arrow_cast::cast(&array, target_type)?
Review Comment:
Taking a second look, I'm curious why the cast here rather than creating the `ArrayRef` directly as is done above? Will this have any performance implications?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: Parquet column writer `Dictionary(_, Decimal128)` and `Dictionary(_, Decimal256)` [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6987:
URL: https://github.com/apache/arrow-rs/pull/6987#issuecomment-2602406282
Thanks again @korowa and @etseidl
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: column writer for dictionary decimal primitive type [arrow-rs]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #6987:
URL: https://github.com/apache/arrow-rs/pull/6987#discussion_r1918983332
##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -270,6 +270,59 @@ where
Arc::new(array) as ArrayRef
}
+ ArrowType::Dictionary(_, value_type) => match value_type.as_ref() {
+ ArrowType::Decimal128(p, s) => {
+ let array = match array.data_type() {
+ ArrowType::Int32 => array
+ .as_any()
+ .downcast_ref::<Int32Array>()
+ .unwrap()
+ .unary(|i| i as i128)
+ as Decimal128Array,
+ ArrowType::Int64 => array
+ .as_any()
+ .downcast_ref::<Int64Array>()
+ .unwrap()
+ .unary(|i| i as i128)
+ as Decimal128Array,
+ _ => {
+ return Err(arrow_err!(
+ "Cannot convert {:?} to decimal dictionary",
+ array.data_type()
+ ));
+ }
+ }
+ .with_precision_and_scale(*p, *s)?;
+
+ arrow_cast::cast(&array, target_type)?
Review Comment:
Taking a second look, I'm curious why the cast here rather than creating the `ArrayRef` directly as is done above? Will this have any performance implications?
Edit: ah, ok. We need to cast to dictionary. Disregard 😅
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: Parquet column writer `Dictionary(_, Decimal128)` and `Dictionary(_, Decimal256)` [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6987:
URL: https://github.com/apache/arrow-rs/pull/6987
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: column writer for dictionary decimal primitive type [arrow-rs]
Posted by "etseidl (via GitHub)" <gi...@apache.org>.
etseidl commented on code in PR #6987:
URL: https://github.com/apache/arrow-rs/pull/6987#discussion_r1918886625
##########
parquet/src/arrow/array_reader/primitive_array.rs:
##########
@@ -270,6 +270,59 @@ where
Arc::new(array) as ArrayRef
}
+ ArrowType::Dictionary(_, value_type) => match value_type.as_ref() {
Review Comment:
This looks correct to me. It would be nice if we could get some code reuse here.
##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -2670,6 +2712,52 @@ mod tests {
one_column_roundtrip_with_schema(Arc::new(d), schema);
}
+ #[test]
+ fn arrow_writer_decimal128_dictionary() {
Review Comment:
Verified that tests fail if the read changes are reverted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org