lidavidm commented on a change in pull request #11129:
URL: https://github.com/apache/arrow/pull/11129#discussion_r706232256



##########
File path: cpp/src/arrow/compute/kernels/codegen_internal.cc
##########
@@ -341,6 +342,91 @@ std::shared_ptr<DataType> CommonBinary(const 
std::vector<ValueDescr>& descrs) {
   return large_binary();
 }
 
+Status CastBinaryDecimalArgs(DecimalPromotion promotion,
+                             std::vector<ValueDescr>* descrs) {
+  auto& left_type = (*descrs)[0].type;
+  auto& right_type = (*descrs)[1].type;
+  DCHECK(is_decimal(left_type->id()) || is_decimal(right_type->id()));
+
+  // decimal + float = float
+  if (is_floating(left_type->id())) {
+    right_type = left_type;
+    return Status::OK();
+  } else if (is_floating(right_type->id())) {
+    left_type = right_type;
+    return Status::OK();
+  }
+
+  // precision, scale of left and right args
+  int32_t p1, s1, p2, s2;
+
+  // decimal + integer = decimal
+  if (is_decimal(left_type->id())) {
+    auto decimal = checked_cast<const DecimalType*>(left_type.get());
+    p1 = decimal->precision();
+    s1 = decimal->scale();
+  } else {
+    DCHECK(is_integer(left_type->id()));
+    ARROW_ASSIGN_OR_RAISE(p1, MaxDecimalDigitsForInteger(left_type->id()));

Review comment:
       I think this came up in a different PR or discussion somewhere, but this 
makes it so that decimal-integer addition works 'properly' now if the decimal 
precision wasn't big enough to hold the integer (now it will promote both to a 
larger decimal type).




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to