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/01 19:34:31 UTC

[GitHub] [arrow-datafusion] viirya opened a new pull request, #5151: Support arithmetic scalar operation with DictionaryArray

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

   # 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 #5150.
   
   # 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 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] alamb commented on a diff in pull request #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1565,6 +1660,61 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    fn plus_op_scalar() -> Result<()> {
+        let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
+        let a = Int32Array::from(vec![1, 2, 3, 4, 5]);
+
+        apply_arithmetic_scalar(
+            Arc::new(schema),
+            vec![Arc::new(a)],
+            Operator::Plus,
+            ScalarValue::Int32(Some(1)),
+            Arc::new(Int32Array::from(vec![2, 3, 4, 5, 6])),
+        )?;
+
+        Ok(())
+    }
+
+    #[test]
+    fn plus_op_dict_scalar() -> Result<()> {
+        let schema = Schema::new(vec![Field::new(
+            "a",
+            DataType::Dictionary(Box::new(DataType::Int8), Box::new(DataType::Int32)),
+            true,
+        )]);
+
+        let mut dict_builder = PrimitiveDictionaryBuilder::<Int8Type, Int32Type>::new();
+
+        dict_builder.append(1)?;
+        dict_builder.append_null();
+        dict_builder.append(2)?;
+        dict_builder.append(5)?;
+
+        let a = dict_builder.finish();
+
+        let mut dict_builder = PrimitiveDictionaryBuilder::<Int8Type, Int32Type>::new();
+
+        dict_builder.append(2)?;

Review Comment:
   👍 



##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -904,6 +977,7 @@ impl BinaryExpr {
         scalar: &ScalarValue,
     ) -> Result<Option<Result<ArrayRef>>> {
         let bool_type = &DataType::Boolean;
+        let left_type = array.data_type();

Review Comment:
   Is there any reason to pass in `left_type` to the `binary_primitive_array_op_dyn_scalar!` (as it already gets `array` maybe it could call `array.data_type()` directly when needed)?
   
   Not that I see anything wrong with this, but I was curious



##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -439,6 +448,12 @@ fn both_numeric_or_null_and_numeric(lhs_type: &DataType, rhs_type: &DataType) ->
     match (lhs_type, rhs_type) {
         (_, DataType::Null) => is_numeric(lhs_type),
         (DataType::Null, _) => is_numeric(rhs_type),
+        (DataType::Dictionary(_, value_type), _) => {
+            is_numeric(value_type) && is_numeric(rhs_type)
+        }
+        (_, DataType::Dictionary(_, value_type)) => {

Review Comment:
   I wonder if this need to handle the case when both lhs and rhs are Dictionaries 🤔 



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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

   > Looks good to me -- it would be great to eventually be able to write sql level tests for this feature, but there is no good way to make dictionary arrays yet from SQL (but I am hoping to get #5016 which would allow it).
   
   Thank you @alamb. Yea, we have internal e2e tests that use dictionary arrays but seems I don't find similar stuff on DataFusion so far. We can definitely expand test coverage for this in the future.
   


-- 
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 pull request #5151: Support arithmetic scalar operation with DictionaryArray

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

   Thanks @viirya  -- it is great to see someone else using Dictionary arrays ❤️ 
   
   Looks like there are some compilation errors on this PR. Marking as draft until those are resolved.
   
   ```
   error[E0425]: cannot find function `divide_decimal_scalar` in this scope
      --> datafusion/physical-expr/src/expressions/binary/kernels_arrow.rs:465:19
       |
   [231](https://github.com/apache/arrow-datafusion/actions/runs/4068186587/jobs/7006440910#step:8:232) | / pub(crate) fn divide_decimal_dyn_scalar(
   [232](https://github.com/apache/arrow-datafusion/actions/runs/4068186587/jobs/7006440910#step:8:233) | |     left: &dyn Array,
   [233](https://github.com/apache/arrow-datafusion/actions/runs/4068186587/jobs/7006440910#step:8:234) | |     right: i128,
   [234](https://github.com/apache/arrow-datafusion/actions/runs/4068186587/jobs/7006440910#step:8:235) | | ) -> Result<Decimal128Array> {
   ...   |
   242 | |     Ok(decimal_array)
   243 | | }
       | |_- similarly named function `divide_decimal_dyn_scalar` defined here
   ...
   465 |           let err = divide_decimal_scalar(&left_decimal_array, 0).unwrap_err();
       |                     ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `divide_decimal_dyn_scalar`
   ```


-- 
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 merged pull request #5151: Support arithmetic scalar operation with DictionaryArray

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


-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -924,18 +998,39 @@ impl BinaryExpr {
                 binary_array_op_dyn_scalar!(array, scalar.clone(), neq, bool_type)
             }
             Operator::Plus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), add)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    add,
+                    left_type
+                )
             }
             Operator::Minus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), subtract)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    subtract,
+                    left_type
+                )
             }
             Operator::Multiply => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), multiply)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    multiply,
+                    left_type
+                )
             }
             Operator::Divide => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), divide)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    divide,
+                    left_type
+                )
             }
             Operator::Modulo => {
+                // todo: change to binary_primitive_array_op_dyn_scalar! once modulo is implemented

Review Comment:
   yea, once modulo is ready to do.



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -924,18 +998,39 @@ impl BinaryExpr {
                 binary_array_op_dyn_scalar!(array, scalar.clone(), neq, bool_type)
             }
             Operator::Plus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), add)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    add,
+                    left_type
+                )
             }
             Operator::Minus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), subtract)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    subtract,
+                    left_type
+                )
             }
             Operator::Multiply => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), multiply)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    multiply,
+                    left_type
+                )
             }
             Operator::Divide => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), divide)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    divide,
+                    left_type
+                )
             }
             Operator::Modulo => {
+                // todo: change to binary_primitive_array_op_dyn_scalar! once modulo is implemented

Review Comment:
   modulo change: https://github.com/apache/arrow-rs/pull/3649



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -439,6 +448,12 @@ fn both_numeric_or_null_and_numeric(lhs_type: &DataType, rhs_type: &DataType) ->
     match (lhs_type, rhs_type) {
         (_, DataType::Null) => is_numeric(lhs_type),
         (DataType::Null, _) => is_numeric(rhs_type),
+        (DataType::Dictionary(_, value_type), _) => {
+            is_numeric(value_type) && is_numeric(rhs_type)
+        }
+        (_, DataType::Dictionary(_, value_type)) => {

Review Comment:
   Actually I'm wondering what Dictionary for `ScalaValue`(rhs here) means although I have seen DataFusion has it.
   
   It sounds reasonable to add the following:
   
   ```
   (DataType::Dictionary(_, lhs_value_type), DataType::Dictionary(_, rhs_value_type2)) => {
     is_numeric(lhs_value_type) && is_numeric(rhs_value_type2)
   }
   ```
   
   



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -315,6 +318,46 @@ macro_rules! compute_op_dyn_scalar {
     }};
 }
 
+/// Invoke a dyn compute kernel on a data array and a scalar value
+/// LEFT is Primitive or Dictionary array of numeric values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_op_dyn_scalar {
+    ($LEFT:expr, $RIGHT:expr, $OP:ident, $OP_TYPE:expr, $SCALAR_TYPE:ident) => {{
+        // generate the scalar function name, such as lt_dyn_scalar, from the $OP parameter
+        // (which could have a value of lt_dyn) and the suffix _scalar
+        if let Some(value) = $RIGHT {
+            Ok(Arc::new(paste::expr! {[<$OP _dyn_scalar>]::<$SCALAR_TYPE>}(
+                $LEFT,
+                value,
+            )?))
+        } else {
+            // when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE
+            Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len())))
+        }
+    }};
+}
+
+/// Invoke a dyn decimal compute kernel on a data array and a scalar value
+/// LEFT is Decimal or Dictionary array of decimal values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value

Review Comment:
   Copied from `compute_primitive_op_dyn_scalar` and forgot to remove it.



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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

   BTW, I think array op array is also not supported yet on dictionary arrays. I will work on it after this.


-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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

   Benchmark runs are scheduled for baseline = 224c682101949da57aebc36e92e5a881ef3040d4 and contender = c75986506ff27d60e8f79e30baa838cf5c717b86. c75986506ff27d60e8f79e30baa838cf5c717b86 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/9e8a3ec8526c459ca9135567dca507f8...6b3919231d974e768dc034996e4689aa/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/b539e3df198e40daa6bfa71f4be4ee15...bf93999d25624ca1b7ce56e557b69cbf/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/4c9a6c47327a40f6aafb8098d9e05655...d56c2d20efb044898f760126c0b81b52/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/571e0c0d76b4421f91f97455dd340be5...e23aaf220ea0415facbe545e21f48bc2/)
   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] sunchao commented on a diff in pull request #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -315,6 +318,46 @@ macro_rules! compute_op_dyn_scalar {
     }};
 }
 
+/// Invoke a dyn compute kernel on a data array and a scalar value
+/// LEFT is Primitive or Dictionary array of numeric values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_op_dyn_scalar {
+    ($LEFT:expr, $RIGHT:expr, $OP:ident, $OP_TYPE:expr, $SCALAR_TYPE:ident) => {{
+        // generate the scalar function name, such as lt_dyn_scalar, from the $OP parameter
+        // (which could have a value of lt_dyn) and the suffix _scalar
+        if let Some(value) = $RIGHT {
+            Ok(Arc::new(paste::expr! {[<$OP _dyn_scalar>]::<$SCALAR_TYPE>}(
+                $LEFT,
+                value,
+            )?))
+        } else {
+            // when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE
+            Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len())))
+        }
+    }};
+}
+
+/// Invoke a dyn decimal compute kernel on a data array and a scalar value
+/// LEFT is Decimal or Dictionary array of decimal values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value

Review Comment:
   where is `SCALAR_TYPE`?



##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -376,6 +419,37 @@ macro_rules! binary_primitive_array_op {
     }};
 }
 
+/// Invoke a compute dyn kernel on an array and a scalar
+/// The binary_primitive_array_op_dyn_scalar macro only evaluates for primitive
+/// types like integers and floats.
+macro_rules! binary_primitive_array_op_dyn_scalar {
+    ($LEFT:expr, $RIGHT:expr, $OP:ident) => {{
+        // unwrap underlying (non dictionary) value
+        let right = unwrap_dict_value($RIGHT);

Review Comment:
   It's interesting that we have "scalar dictionary":
   ```rust
       /// Dictionary type: index type and value
       Dictionary(Box<DataType>, Box<ScalarValue>),
   ```
   
   wonder how useful this is ...



##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -315,6 +318,46 @@ macro_rules! compute_op_dyn_scalar {
     }};
 }
 
+/// Invoke a dyn compute kernel on a data array and a scalar value
+/// LEFT is Primitive or Dictionary array of numeric values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_op_dyn_scalar {

Review Comment:
   maybe highlight the difference between this and `compute_op_dyn_scalar` in the comments.



##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -315,6 +318,46 @@ macro_rules! compute_op_dyn_scalar {
     }};
 }
 
+/// Invoke a dyn compute kernel on a data array and a scalar value
+/// LEFT is Primitive or Dictionary array of numeric values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_op_dyn_scalar {
+    ($LEFT:expr, $RIGHT:expr, $OP:ident, $OP_TYPE:expr, $SCALAR_TYPE:ident) => {{
+        // generate the scalar function name, such as lt_dyn_scalar, from the $OP parameter
+        // (which could have a value of lt_dyn) and the suffix _scalar
+        if let Some(value) = $RIGHT {
+            Ok(Arc::new(paste::expr! {[<$OP _dyn_scalar>]::<$SCALAR_TYPE>}(
+                $LEFT,
+                value,
+            )?))
+        } else {
+            // when the $RIGHT is a NULL, generate a NULL array of $OP_TYPE
+            Ok(Arc::new(new_null_array($OP_TYPE, $LEFT.len())))
+        }
+    }};
+}
+
+/// Invoke a dyn decimal compute kernel on a data array and a scalar value
+/// LEFT is Decimal or Dictionary array of decimal values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_decimal_op_dyn_scalar {
+    ($LEFT:expr, $RIGHT:expr, $OP:ident, $OP_TYPE:expr) => {{
+        // generate the scalar function name, such as lt_dyn_scalar, from the $OP parameter
+        // (which could have a value of lt_dyn) and the suffix _scalar

Review Comment:
   nit: "such as lt_decimal_op_dyn_scalar"



##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -924,18 +998,39 @@ impl BinaryExpr {
                 binary_array_op_dyn_scalar!(array, scalar.clone(), neq, bool_type)
             }
             Operator::Plus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), add)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    add,
+                    left_type
+                )
             }
             Operator::Minus => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), subtract)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    subtract,
+                    left_type
+                )
             }
             Operator::Multiply => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), multiply)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    multiply,
+                    left_type
+                )
             }
             Operator::Divide => {
-                binary_primitive_array_op_scalar!(array, scalar.clone(), divide)
+                binary_primitive_array_op_dyn_scalar!(
+                    array,
+                    scalar.clone(),
+                    divide,
+                    left_type
+                )
             }
             Operator::Modulo => {
+                // todo: change to binary_primitive_array_op_dyn_scalar! once modulo is implemented

Review Comment:
   we can remove `binary_primitive_array_op_scalar` once this is done?



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -315,6 +318,46 @@ macro_rules! compute_op_dyn_scalar {
     }};
 }
 
+/// Invoke a dyn compute kernel on a data array and a scalar value
+/// LEFT is Primitive or Dictionary array of numeric values, RIGHT is scalar value
+/// OP_TYPE is the return type of scalar function
+/// SCALAR_TYPE is the type of the scalar value
+macro_rules! compute_primitive_op_dyn_scalar {

Review Comment:
   Added a comment for that.



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -904,6 +977,7 @@ impl BinaryExpr {
         scalar: &ScalarValue,
     ) -> Result<Option<Result<ArrayRef>>> {
         let bool_type = &DataType::Boolean;
+        let left_type = array.data_type();

Review Comment:
   You're correct. `left_type` is not necessary to be passed to `binary_primitive_array_op_dyn_scalar!`. Let me remove it.



-- 
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 #5151: Support arithmetic scalar operation with DictionaryArray

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

   Thanks @alamb . Yea, I'm trying to fix them locally.


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