kou commented on code in PR #47297: URL: https://github.com/apache/arrow/pull/47297#discussion_r2268403021
########## cpp/src/arrow/compute/kernel.cc: ########## @@ -475,23 +475,78 @@ std::string OutputType::ToString() const { return "computed"; } +// ---------------------------------------------------------------------- +// MatchConstraint + +std::shared_ptr<MatchConstraint> DecimalsHaveSameScale() { + class DecimalsHaveSameScaleConstraint : public MatchConstraint { + public: + bool Matches(const std::vector<TypeHolder>& types) const override { + DCHECK_GE(types.size(), 2); + DCHECK(std::all_of(types.begin(), types.end(), + [](const TypeHolder& type) { return is_decimal(type.id()); })); + auto ty0 = checked_cast<const DecimalType*>(types[0].type); + DCHECK_NE(ty0, nullptr); Review Comment: > Sorry I'm not following. Those two `static_assert`s only assert the from and to types are classes. There can be cases that both are classes but without inheritance, that can still result in `nullptr`? Oh, sorry. I haven't looked at these `static_assert`s carefully... You're right. > This `is_decimal` merely checks the internal `type_id`. I'm not sure if we can assume `ty.type_id == Type::DECIMAL` implies `typeof(ty) == class DecimalType`. I think that we can assume it based on the current implementation but I'm OK with keeping this `DCHECK_NE()` now. https://github.com/apache/arrow/blob/2b8db0094baed09875d44ebe33b78dd7ce859ab5/cpp/src/arrow/type_traits.h#L1109-L1120 https://github.com/apache/arrow/blob/2b8db0094baed09875d44ebe33b78dd7ce859ab5/cpp/src/arrow/type.h#L1047-L1049 https://github.com/apache/arrow/blob/2b8db0094baed09875d44ebe33b78dd7ce859ab5/cpp/src/arrow/type.h#L1082-L1084 https://github.com/apache/arrow/blob/2b8db0094baed09875d44ebe33b78dd7ce859ab5/cpp/src/arrow/type.h#L1116-L1118 https://github.com/apache/arrow/blob/2b8db0094baed09875d44ebe33b78dd7ce859ab5/cpp/src/arrow/type.h#L1149-L1151 -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org