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

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5151: Support arithmetic scalar operation with DictionaryArray

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