You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/05 18:55:01 UTC

[GitHub] [arrow-rs] viirya opened a new pull request, #2006: Add Decimal256Builder and Decimal256Array (generic approach)

viirya opened a new pull request, #2006:
URL: https://github.com/apache/arrow-rs/pull/2006

   # 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 #1999.
   
   This is alternative PR that implements Decimal256Builder and Decimal256Array in generic approach. 
   
   # 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.
   -->
   
   # 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.
   -->
   
   # Are there any user-facing changes?
   
   
   <!---
   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 add the `breaking change` label.
   -->
   


-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914123744


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {
+    data: ArrayData,
+    value_data: RawPtrBox<u8>,
+    precision: usize,
+    scale: usize,
+    phantom: PhantomData<T>,
+}

Review Comment:
   Compared to #2000, which defines a trait and let `DecimalArray` and `Decimal256Array` extend the trait, this generic approach defines a struct `GenericDecimalArray` and generalize on Decimal type (Decimal128/Decimal256).
   
   Honestly I prefer #2000's trait approach. It looks more clear to me. But one cons of #2000 is that it needs to use macro to reduce code duplication, though it is not complicated usage.



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914294001


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {

Review Comment:
   Don't we need a type bound to `Decimal<BYTE_LENGTH>` even for const generic?



-- 
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


[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914246297


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {

Review Comment:
   One little concern is that we could remove `T: BasicDecimal` if we also do const generic on `Decimal128` and `Decimal256`.



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914216492


##########
arrow/src/array/equal_json.rs:
##########
@@ -359,19 +361,16 @@ impl PartialEq<FixedSizeBinaryArray> for Value {
     }
 }
 
-impl JsonEqual for DecimalArray {
+impl<T: BasicDecimal + 'static, const VALUE_LENGTH: i32> JsonEqual
+    for GenericDecimalArray<T, VALUE_LENGTH>
+{
     fn equals_json(&self, json: &[&Value]) -> bool {
         if self.len() != json.len() {
             return false;
         }
 
         (0..self.len()).all(|i| match json[i] {
-            JString(s) => {
-                self.is_valid(i)
-                    && (s
-                        .parse::<i128>()
-                        .map_or_else(|_| false, |v| v == self.value(i).as_i128()))
-            }
+            JString(s) => self.is_valid(i) && (s == &self.value(i).to_string()),

Review Comment:
   This is one issue on generic approach. We cannot keep original `JsonEqual` behavior for DecimalArray. This causes some test failures.



-- 
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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914123744


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {
+    data: ArrayData,
+    value_data: RawPtrBox<u8>,
+    precision: usize,
+    scale: usize,
+    phantom: PhantomData<T>,
+}

Review Comment:
   Compared to #2000, which defines a trait and let `DecimalArray` and `Decimal256Array` extend the trait, this generic approach defines a struct `GenericDecimalArray` and generalize on Decimal type (Decimal128/Decimal256).
   
   Honestly I prefer #2000's trait approach. It looks more clear to me. But one cons of #2000 is that it needs to use macro to reduce code duplication.



-- 
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


[GitHub] [arrow-rs] viirya closed pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya closed pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)
URL: https://github.com/apache/arrow-rs/pull/2006


-- 
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


[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914348541


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {

Review Comment:
   I tried to find some help from the rust-lang team: https://users.rust-lang.org/t/how-to-seal-the-const-generic/77947.



-- 
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


[GitHub] [arrow-rs] viirya commented on pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#issuecomment-1177709132

   As this has some issues, I'd close this and prefer #2000 now.


-- 
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


[GitHub] [arrow-rs] HaoYang670 commented on a diff in pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on code in PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#discussion_r914338039


##########
arrow/src/array/array_decimal.rs:
##########
@@ -32,7 +32,16 @@ use crate::datatypes::{
     DECIMAL_MAX_SCALE,
 };
 use crate::error::{ArrowError, Result};
-use crate::util::decimal::{BasicDecimal, Decimal128};
+use crate::util::decimal::{BasicDecimal, Decimal128, Decimal256};
+use std::marker::PhantomData;
+
+pub struct GenericDecimalArray<T: BasicDecimal, const VALUE_LENGTH: i32> {

Review Comment:
   Actually we need it. But just as I said in [#2001](https://github.com/apache/arrow-rs/issues/2001#issuecomment-1174489633), this is an unstable, which is the major disadvantage of using `const generic`.  



-- 
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


[GitHub] [arrow-rs] HaoYang670 commented on pull request #2006: Add Decimal256Builder and Decimal256Array (generic approach)

Posted by GitBox <gi...@apache.org>.
HaoYang670 commented on PR #2006:
URL: https://github.com/apache/arrow-rs/pull/2006#issuecomment-1178428536

   👍 Thank you for the trying @viirya .


-- 
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