felipecrv commented on code in PR #41012:
URL: https://github.com/apache/arrow/pull/41012#discussion_r1600296592


##########
cpp/src/arrow/compute/kernels/scalar_compare.cc:
##########
@@ -385,6 +385,23 @@ struct VarArgsCompareFunction : ScalarFunction {
   }
 };
 
+Result<TypeHolder> ResolveDecimalCompareOutputType(KernelContext*,
+                                                   const 
std::vector<TypeHolder>& types) {
+  // casted types should be same size decimals
+  const auto& left_type = checked_cast<const DecimalType&>(*types[0]);
+  const auto& right_type = checked_cast<const DecimalType&>(*types[1]);
+  DCHECK_EQ(left_type.id(), right_type.id());
+
+  // check the casted decimal scales according kAdd promotion rule
+  const int32_t s1 = left_type.scale();
+  const int32_t s2 = right_type.scale();
+  if (s1 != s2) {
+    return Status::Invalid("Comparison of two decimal  ", "types s1 != s2. (", 
s1, s2,
+                           ").");
+  }
+  return boolean();
+}
+

Review Comment:
   > Is this reasonable for the design of TypeMatcher?
   
   As long as it checks only the types and the code is simple enough that we 
can reason about the set of combinations handled.
   
   If some combinations are invalid, but you want to generate a message, I 
think you could have the type matcher route bad combinations to these fail 
kernels that produce an error instead of automatically casting inputs.



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