You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2023/02/04 21:38:23 UTC

[GitHub] [arrow-datafusion] viirya opened a new pull request, #5179: Fix decimal scalar dyn kernels

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

   # 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.
   -->
   
   Follow of #5151.
   
   # 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.  
   -->
   
   For `add_decimal_dyn_scalar` and `subtract_decimal_dyn_scalar`, it should call `get_precision_scale` and `decimal_array_with_precision_scale` like `multiply_decimal_dyn_scalar` and `divide_decimal_dyn_scalar` as the input/output could be DictionaryArray.
   
   # 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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # 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] viirya merged pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya merged PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179


-- 
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] viirya commented on a diff in pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#discussion_r1096767895


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1694,6 +1694,49 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn plus_op_dict_scalar_decimal() -> Result<()> {
+        let schema = Schema::new(vec![Field::new(
+            "a",
+            DataType::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(DataType::Decimal128(10, 0)),
+            ),
+            true,
+        )]);
+
+        let value = 123;
+        let decimal_array = Arc::new(create_decimal_array(
+            &[Some(value), None, Some(value - 1), Some(value + 1)],
+            10,
+            0,
+        )) as ArrayRef;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let a = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let decimal_array = create_decimal_array(
+            &[Some(value + 1), None, Some(value), Some(value + 2)],
+            10,
+            0,
+        );
+        let expected = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        apply_arithmetic_scalar(
+            Arc::new(schema),
+            vec![Arc::new(a)],
+            Operator::Plus,
+            ScalarValue::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(ScalarValue::Decimal128(Some(1), 10, 0)),

Review Comment:
   No, original code still modifies precision/scale for output array, but it just worked for primitive array not dictionary array.



-- 
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] viirya commented on a diff in pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#discussion_r1096767895


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1694,6 +1694,49 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn plus_op_dict_scalar_decimal() -> Result<()> {
+        let schema = Schema::new(vec![Field::new(
+            "a",
+            DataType::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(DataType::Decimal128(10, 0)),
+            ),
+            true,
+        )]);
+
+        let value = 123;
+        let decimal_array = Arc::new(create_decimal_array(
+            &[Some(value), None, Some(value - 1), Some(value + 1)],
+            10,
+            0,
+        )) as ArrayRef;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let a = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let decimal_array = create_decimal_array(
+            &[Some(value + 1), None, Some(value), Some(value + 2)],
+            10,
+            0,
+        );
+        let expected = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        apply_arithmetic_scalar(
+            Arc::new(schema),
+            vec![Arc::new(a)],
+            Operator::Plus,
+            ScalarValue::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(ScalarValue::Decimal128(Some(1), 10, 0)),

Review Comment:
   No, original code still modifies precision/scale for output array, but it just works for primitive array not dictionary array.



-- 
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] viirya commented on a diff in pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#discussion_r1096768138


##########
.github/workflows/dev.yml:
##########
@@ -54,4 +54,5 @@ jobs:
             '!datafusion/CHANGELOG.md' \
             README.md \
             CONTRIBUTING.md
+          git config --global --add safe.directory "$GITHUB_WORKSPACE" 

Review Comment:
   Reverted CI related change.



-- 
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] ursabot commented on pull request #5179: Fix decimal scalar dyn kernels

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#issuecomment-1418672952

   Benchmark runs are scheduled for baseline = a213d62b33e011cbc10e937de06b6acea1c7157f and contender = 423375235499f4dc9b645c0c0489ce4530e5000b. 423375235499f4dc9b645c0c0489ce4530e5000b is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/b52301400b0f49a4b1b39aebbd57a42e...5e859a162e5f47e989bad94849817885/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/9ad1d9bad38544759867f99089361400...0ce71f1895ca4f74a601df77fcf60db5/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/073ee605bde044c8beca6798f1cb6fc3...54e0fb234c0546969bc93fb5389b700a/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e3fedcb4a3664feb9888143bf43d5401...477db8b99ab14355aa0b59c755524651/)
   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
   


-- 
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] viirya commented on a diff in pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#discussion_r1096589323


##########
datafusion/physical-expr/src/expressions/binary/kernels_arrow.rs:
##########
@@ -189,28 +189,20 @@ pub(crate) fn add_decimal(
 }
 
 pub(crate) fn add_decimal_dyn_scalar(left: &dyn Array, right: i128) -> Result<ArrayRef> {
-    let left_decimal = left.as_any().downcast_ref::<Decimal128Array>().unwrap();
+    let (precision, scale) = get_precision_scale(left)?;

Review Comment:
   In last PR, forgot to update this and there.



-- 
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] viirya commented on pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#issuecomment-1416860961

   CI seems broken:
   
   ```
   warning: Not a git repository. Use --no-index to compare two paths outside a working tree
   usage: git diff --no-index [<options>] <path> <path>
   ```


-- 
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] viirya commented on pull request #5179: Fix decimal scalar dyn kernels

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#issuecomment-1416874050

   Proposed CI fix at #5182.


-- 
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 commented on a diff in pull request #5179: Fix decimal scalar dyn kernels

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5179:
URL: https://github.com/apache/arrow-datafusion/pull/5179#discussion_r1096664517


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1694,6 +1694,49 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn plus_op_dict_scalar_decimal() -> Result<()> {
+        let schema = Schema::new(vec![Field::new(
+            "a",
+            DataType::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(DataType::Decimal128(10, 0)),
+            ),
+            true,
+        )]);
+
+        let value = 123;
+        let decimal_array = Arc::new(create_decimal_array(
+            &[Some(value), None, Some(value - 1), Some(value + 1)],
+            10,
+            0,
+        )) as ArrayRef;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let a = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        let keys = Int8Array::from(vec![0, 2, 1, 3, 0]);
+        let decimal_array = create_decimal_array(
+            &[Some(value + 1), None, Some(value), Some(value + 2)],
+            10,
+            0,
+        );
+        let expected = DictionaryArray::try_new(&keys, &decimal_array)?;
+
+        apply_arithmetic_scalar(
+            Arc::new(schema),
+            vec![Arc::new(a)],
+            Operator::Plus,
+            ScalarValue::Dictionary(
+                Box::new(DataType::Int8),
+                Box::new(ScalarValue::Decimal128(Some(1), 10, 0)),

Review Comment:
   without this PR's code, is the actual type of the output array whatever the default precision of `Decimal128` is (rather than `10, 0`)?



##########
.github/workflows/dev.yml:
##########
@@ -54,4 +54,5 @@ jobs:
             '!datafusion/CHANGELOG.md' \
             README.md \
             CONTRIBUTING.md
+          git config --global --add safe.directory "$GITHUB_WORKSPACE" 

Review Comment:
   I think this is no longer needed after updating to latest master



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