Skip to content

Commit

Permalink
Support bit_xor Spark aggregate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohahaha committed Apr 26, 2023
1 parent 05c7258 commit 2fc2560
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 43 deletions.
3 changes: 2 additions & 1 deletion velox/functions/lib/BitwiseAggregateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ bool registerBitwise(const std::string& name) {
name,
inputType->kindName());
}
});
},
true);
return true;
}

Expand Down
42 changes: 0 additions & 42 deletions velox/functions/prestosql/aggregates/BitwiseAggregates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,48 +98,6 @@ class BitwiseAndAggregate : public BitwiseAggregateBase<T> {
}
};

template <template <typename U> class T>
bool registerBitwise(const std::string& name) {
// TODO Fix the signatures to match Presto.
std::vector<std::shared_ptr<exec::AggregateFunctionSignature>> signatures;
for (const auto& inputType : {"tinyint", "smallint", "integer", "bigint"}) {
signatures.push_back(exec::AggregateFunctionSignatureBuilder()
.returnType(inputType)
.intermediateType(inputType)
.argumentType(inputType)
.build());
}

exec::registerAggregateFunction(
name,
std::move(signatures),
[name](
core::AggregationNode::Step step,
const std::vector<TypePtr>& argTypes,
const TypePtr& resultType) -> std::unique_ptr<exec::Aggregate> {
VELOX_CHECK_LE(argTypes.size(), 1, "{} takes only one argument", name);
auto inputType = argTypes[0];
switch (inputType->kind()) {
case TypeKind::TINYINT:
return std::make_unique<T<int8_t>>(resultType);
case TypeKind::SMALLINT:
return std::make_unique<T<int16_t>>(resultType);
case TypeKind::INTEGER:
return std::make_unique<T<int32_t>>(resultType);
case TypeKind::BIGINT:
return std::make_unique<T<int64_t>>(resultType);
default:
VELOX_CHECK(
false,
"Unknown input type for {} aggregation {}",
name,
inputType->kindName());
}
},
true);
return true;
}

} // namespace

void registerBitwiseAggregates(const std::string& prefix) {
Expand Down
2 changes: 2 additions & 0 deletions velox/substrait/SubstraitToVeloxPlanValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ bool SubstraitToVeloxPlanValidator::validate(
"bitwise_and_agg_merge",
"bitwise_or_agg",
"bitwise_or_agg_merge",
"bit_xor",
"bit_xor_merge",
"corr",
"corr_merge",
"covar_pop",
Expand Down

0 comments on commit 2fc2560

Please sign in to comment.