use of org.drools.drl.ast.descr.GroupByDescr in project drools by kiegroup.
the class GroupByVisitor method processAccumulateFunctions.
protected void processAccumulateFunctions(AccumulateDescr descr, PatternDescr basePattern, BaseDescr input, MethodCallExpr accumulateDSL) {
accumulateDSL.setName(GROUP_BY_CALL);
GroupByDescr groupByDescr = (GroupByDescr) descr;
Expression expr = parseExpression(groupByDescr.getGroupingFunction());
TypedExpressionResult result = new ExpressionTyper(context).toTypedExpression(expr);
Optional<TypedExpression> optResult = result.getTypedExpression();
if (!optResult.isPresent()) {
context.addCompilationError(new InvalidExpressionErrorResult("Unable to parse grouping expression: " + groupByDescr.getGroupingFunction()));
return;
}
for (String used : result.getUsedDeclarations()) {
accumulateDSL.addArgument(context.getVarExpr(used));
}
TypedExpression typedExpression = optResult.get();
String groupingKey = groupByDescr.getGroupingKey() != null ? groupByDescr.getGroupingKey() : generateUUID();
context.addDeclaration(new DeclarationSpec(groupingKey, typedExpression.getRawClass()));
accumulateDSL.addArgument(toVar(groupingKey));
accumulateDSL.addArgument(buildConstraintExpression(typedExpression.getExpression(), result.getUsedDeclarations()));
super.processAccumulateFunctions(descr, basePattern, input, accumulateDSL);
}
Aggregations