ZhangHuiGui commented on code in PR #41012:
URL: https://github.com/apache/arrow/pull/41012#discussion_r1604537627
##########
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:
> As long as it checks only the types and the code is simple enough that we
can reason about the set of combinations handled.
Thanks, it's more concise to use `TypeMatcher` check the input types.
--
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]