use of org.drools.modelcompiler.constraints.BindingEvaluator in project drools by kiegroup.
the class KiePackagesBuilder method processFunctions.
private Variable processFunctions(RuleContext ctx, AccumulatePattern accPattern, RuleConditionElement source, Pattern pattern, Set<String> usedVariableName, Collection<Binding> bindings, boolean isGroupBy, AccumulateFunction accFunction, InternalReadAccessor selfReader, Accumulator[] accumulators, List<Declaration> requiredDeclarationList, int arrayIndexOffset, int i) {
Binding binding = findBindingForAccumulate(bindings, accFunction);
if (binding != null) {
for (Variable var : binding.getInputVariables()) {
usedVariableName.add(var.getName());
}
}
final BindingEvaluator bindingEvaluator = createBindingEvaluator(ctx, binding);
final Accumulator accumulator = createAccumulator(usedVariableName, bindingEvaluator, accFunction);
Variable boundVar = accPattern.getBoundVariables()[i];
Declaration declaration;
if (!isGroupBy && accumulators.length == 1) {
declaration = new Declaration(boundVar.getName(), new PatternExtractor(new ClassObjectType(boundVar.getType())), pattern, true);
} else {
// GroupBy or multi-accumulate always return an array
// If GroupBy has no bound function, it uses an anonymous one.
// The result is still in element 0 so must be offset using arrayIndexOffset
declaration = new Declaration(boundVar.getName(), new ArrayElementReader(selfReader, i + arrayIndexOffset, boundVar.getType()), pattern, true);
}
pattern.addDeclaration(declaration);
ctx.addDeclaration(boundVar, declaration);
accumulators[i] = accumulator;
Declaration[] requiredDeclarations = getRequiredDeclarationsForAccumulate(ctx, source, accFunction, binding, bindingEvaluator);
requiredDeclarationList.addAll(Arrays.asList(requiredDeclarations));
return boundVar;
}
use of org.drools.modelcompiler.constraints.BindingEvaluator in project drools by kiegroup.
the class KiePackagesBuilder method createBindingEvaluator.
private BindingEvaluator createBindingEvaluator(RuleContext ctx, Binding binding) {
if (binding == null) {
return null;
}
Variable[] inputs = binding.getInputVariables();
if (inputs.length == 1) {
return new BindingInnerObjectEvaluator(binding);
}
Declaration[] declarations = new Declaration[inputs.length];
for (int i = 0; i < inputs.length; i++) {
declarations[i] = ctx.getDeclaration(inputs[i]);
}
return new BindingEvaluator(declarations, binding);
}
Aggregations