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/01/18 12:26:29 UTC

[GitHub] [arrow-datafusion] liukun4515 opened a new pull request #1603: add test for decimal to decimal

liukun4515 opened a new pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603


   # Which issue does this PR close?
   
   - add test for decimal to decimal
   
   - move decimal test together
   
   part of #1443 
   
    # 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 `api 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-datafusion] liukun4515 commented on a change in pull request #1603: add test for decimal to decimal

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on a change in pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603#discussion_r786702536



##########
File path: datafusion/src/physical_plan/expressions/cast.rs
##########
@@ -269,6 +269,168 @@ mod tests {
         }};
     }
 
+    fn create_decimal_array(
+        array: &[i128],
+        precision: usize,
+        scale: usize,
+    ) -> Result<DecimalArray> {
+        let mut decimal_builder = DecimalBuilder::new(array.len(), precision, scale);
+        for value in array {
+            decimal_builder.append_value(*value)?
+        }
+        decimal_builder.append_null()?;
+        Ok(decimal_builder.finish())
+    }
+
+    #[test]
+    fn test_cast_decimal_to_decimal() -> Result<()> {

Review comment:
       add test for decimal to decimal




-- 
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-datafusion] liukun4515 commented on a change in pull request #1603: add test for decimal to decimal

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on a change in pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603#discussion_r786702031



##########
File path: datafusion/src/physical_plan/expressions/try_cast.rs
##########
@@ -227,6 +227,155 @@ mod tests {
         }};
     }
 
+    #[test]
+    fn test_try_cast_decimal_to_decimal() -> Result<()> {
+        // try cast one decimal data type to another decimal data type
+        let array: Vec<i128> = vec![1234, 2222, 3, 4000, 5000];
+        let decimal_array = create_decimal_array(&array, 10, 3)?;
+        generic_decimal_to_other_test_cast!(
+            decimal_array,
+            DataType::Decimal(10, 3),
+            DecimalArray,
+            DataType::Decimal(20, 6),
+            vec![
+                Some(1234_000_i128),
+                Some(2222_000_i128),
+                Some(3_000_i128),
+                Some(4000_000_i128),
+                Some(5000_000_i128),
+                None,
+            ]
+        );
+
+        let decimal_array = create_decimal_array(&array, 10, 3)?;
+        generic_decimal_to_other_test_cast!(
+            decimal_array,
+            DataType::Decimal(10, 3),
+            DecimalArray,
+            DataType::Decimal(10, 2),
+            vec![
+                Some(123_i128),
+                Some(222_i128),
+                Some(0_i128),
+                Some(400_i128),
+                Some(500_i128),
+                None,
+            ]
+        );
+
+        Ok(())
+    }
+
+    #[test]
+    fn test_try_cast_decimal_to_numeric() -> Result<()> {

Review comment:
       move test to here




-- 
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-datafusion] liukun4515 commented on a change in pull request #1603: add test for decimal to decimal

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on a change in pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603#discussion_r786701728



##########
File path: datafusion/src/physical_plan/expressions/cast.rs
##########
@@ -269,6 +269,168 @@ mod tests {
         }};
     }
 
+    fn create_decimal_array(
+        array: &[i128],
+        precision: usize,
+        scale: usize,
+    ) -> Result<DecimalArray> {
+        let mut decimal_builder = DecimalBuilder::new(array.len(), precision, scale);
+        for value in array {
+            decimal_builder.append_value(*value)?
+        }
+        decimal_builder.append_null()?;
+        Ok(decimal_builder.finish())
+    }
+
+    #[test]
+    fn test_cast_decimal_to_decimal() -> Result<()> {
+        let array: Vec<i128> = vec![1234, 2222, 3, 4000, 5000];
+        let decimal_array = create_decimal_array(&array, 10, 3)?;
+        generic_decimal_to_other_test_cast!(
+            decimal_array,
+            DataType::Decimal(10, 3),
+            DecimalArray,
+            DataType::Decimal(20, 6),
+            vec![
+                Some(1234_000_i128),
+                Some(2222_000_i128),
+                Some(3_000_i128),
+                Some(4000_000_i128),
+                Some(5000_000_i128),
+                None,
+            ],
+            DEFAULT_DATAFUSION_CAST_OPTIONS
+        );
+
+        let decimal_array = create_decimal_array(&array, 10, 3)?;
+        generic_decimal_to_other_test_cast!(
+            decimal_array,
+            DataType::Decimal(10, 3),
+            DecimalArray,
+            DataType::Decimal(10, 2),
+            vec![
+                Some(123_i128),
+                Some(222_i128),
+                Some(0_i128),
+                Some(400_i128),
+                Some(500_i128),
+                None,
+            ],
+            DEFAULT_DATAFUSION_CAST_OPTIONS
+        );
+
+        Ok(())
+    }
+
+    #[test]
+    fn test_cast_decimal_to_numeric() -> Result<()> {

Review comment:
       move test to here




-- 
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-datafusion] alamb merged pull request #1603: add test for decimal to decimal

Posted by GitBox <gi...@apache.org>.
alamb merged pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603


   


-- 
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-datafusion] liukun4515 commented on a change in pull request #1603: add test for decimal to decimal

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on a change in pull request #1603:
URL: https://github.com/apache/arrow-datafusion/pull/1603#discussion_r786702227



##########
File path: datafusion/src/physical_plan/expressions/try_cast.rs
##########
@@ -227,6 +227,155 @@ mod tests {
         }};
     }
 
+    #[test]
+    fn test_try_cast_decimal_to_decimal() -> Result<()> {

Review comment:
       add test for decimal to decimal




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