Skip to content

Commit

Permalink
matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
R-JunmingChen committed Aug 23, 2023
1 parent 84dd9ea commit f458569
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cpp/src/arrow/compute/kernels/aggregate_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,32 @@ Result<std::unique_ptr<KernelState>> MinMaxInit(KernelContext* ctx,
return visitor.Create();
}

struct AnyExceptDictionaryMatcher : TypeMatcher {
public:
AnyExceptDictionaryMatcher() {}

bool Matches(const DataType& type) const override {
return type.id() != Type::DICTIONARY;
}

std::string ToString() const override { return "Any Type except the Dictionary Type"; }

bool Equals(const TypeMatcher& other) const override {
if (this == &other) {
return true;
}
auto casted = dynamic_cast<const AnyExceptDictionaryMatcher*>(&other);
return casted != nullptr;
}
};

// For "min" and "max" functions: override finalize and return the actual value
template <MinOrMax min_or_max>
void AddMinOrMaxAggKernels(ScalarAggregateFunction* func,
ScalarAggregateFunction* min_max_func) {
auto any_except_dict_matcher = std::make_shared<AnyExceptDictionaryMatcher>();
std::shared_ptr<arrow::compute::KernelSignature> sig =
KernelSignature::Make({InputType::Any()}, FirstType);
KernelSignature::Make({InputType(any_except_dict_matcher)}, FirstType);
auto init = [min_max_func](
KernelContext* ctx,
const KernelInitArgs& args) -> Result<std::unique_ptr<KernelState>> {
Expand Down

0 comments on commit f458569

Please sign in to comment.