Skip to content

Commit

Permalink
Fix aggregation masks and validate the size of count arguments (oap-p…
Browse files Browse the repository at this point in the history
…roject#142)

* fix aggregation mask

* validate count argument size
  • Loading branch information
rui-mo authored and zhejiangxiaomai committed Apr 20, 2023
1 parent 5657cdb commit 36797c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
23 changes: 10 additions & 13 deletions velox/substrait/SubstraitToVeloxPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,18 @@ std::shared_ptr<const core::PlanNode> SubstraitVeloxPlanConverter::toVeloxAgg(
aggregateMasks.reserve(aggRel.measures().size());
for (const auto& smea : aggRel.measures()) {
core::FieldAccessTypedExprPtr aggregateMask;
::substrait::Expression substraitAggMask = smea.filter();
// Get Aggregation Masks.
if (smea.has_filter()) {
if (substraitAggMask.ByteSizeLong() == 0) {
aggregateMask = {};
} else {
aggregateMask =
std::dynamic_pointer_cast<const core::FieldAccessTypedExpr>(
exprConverter_->toVeloxExpr(substraitAggMask, inputType));
VELOX_CHECK(
aggregateMask != nullptr,
" the agg filter expression in Aggregate Operator only support field");
}
aggregateMasks.push_back(aggregateMask);
if (!smea.has_filter()) {
aggregateMask = {};
} else {
aggregateMask =
std::dynamic_pointer_cast<const core::FieldAccessTypedExpr>(
exprConverter_->toVeloxExpr(smea.filter(), inputType));
VELOX_CHECK(
aggregateMask != nullptr,
" the agg filter expression in Aggregate Operator only support field");
}
aggregateMasks.push_back(aggregateMask);
const auto& aggFunction = smea.measure();
std::string funcName = subParser_->findVeloxFunction(
functionMap_, aggFunction.function_reference());
Expand Down
10 changes: 8 additions & 2 deletions velox/substrait/SubstraitToVeloxPlanValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,15 @@ bool SubstraitToVeloxPlanValidator::validate(
}

const auto& aggFunction = smea.measure();
funcSpecs.emplace_back(
planConverter_->findFuncSpec(aggFunction.function_reference()));
const auto& functionSpec = planConverter_->findFuncSpec(aggFunction.function_reference());
funcSpecs.emplace_back(functionSpec);
toVeloxType(subParser_->parseType(aggFunction.output_type())->type);
// Validate the size of arguments.
if (subParser_->getSubFunctionName(functionSpec) == "count" &&
aggFunction.arguments().size() > 1) {
// Count accepts only one argument.
return false;
}
for (const auto& arg : aggFunction.arguments()) {
auto typeCase = arg.value().rex_type_case();
switch (typeCase) {
Expand Down

0 comments on commit 36797c5

Please sign in to comment.