Rikkola commented on code in PR #6909:
URL: https://github.com/apache/incubator-kie/pull/6909#discussion_r3914193059
##########
drools-model/drools-model-compiler/src/main/java/org/drools/modelcompiler/KiePackagesBuilder.java:
##########
@@ -398,15 +407,41 @@ private void processConsequence( RuleContext ctx,
Consequence consequence, Strin
Declaration[] requiredDeclarations =
getRequiredDeclarationsIfPossible( ctx, consequence, name );
boolean enabledTupleOptimization = requiredDeclarations != null &&
requiredDeclarations.length > 0;
+ Map<String, int[]> sequenceVarIndexes =
buildSequenceVarIndexesForConsequence( ctx, consequence );
+
if ( name.equals( RuleImpl.DEFAULT_CONSEQUENCE_NAME ) ) {
if ("java".equals(consequence.getLanguage())) {
- ctx.getRule().setConsequence( new LambdaConsequence(
consequence, enabledTupleOptimization ) );
+ ctx.getRule().setConsequence( new LambdaConsequence(
consequence, enabledTupleOptimization, sequenceVarIndexes ) );
} else {
throw new UnsupportedOperationException("Unknown script
language for consequence: " + consequence.getLanguage());
}
} else {
- ctx.getRule().addNamedConsequence( name, new LambdaConsequence(
consequence, enabledTupleOptimization ) );
+ ctx.getRule().addNamedConsequence( name, new LambdaConsequence(
consequence, enabledTupleOptimization, sequenceVarIndexes ) );
+ }
+ }
+
+ /**
+ * Builds a map of variable-name → sequencer-data-index for any
consequence variables
+ * that were bound by a sequence step pattern (rather than a normal LHS
pattern).
+ * These variables are not accessible via the activation tuple; they must
be resolved
+ * from SequencerMemory.getData() at consequence evaluation time.
+ */
+ private Map<String, int[]> buildSequenceVarIndexesForConsequence(
RuleContext ctx, Consequence consequence ) {
+ Map<Variable, int[]> seqIndexes = ctx.getSequenceVarIndexes();
+ if (seqIndexes.isEmpty()) {
+ return Map.of();
+ }
+ int totalSeqs = ctx.getSequenceCount();
+ Map<String, int[]> result = null;
+ for (Variable var : consequence.getDeclarations()) {
+ int[] entry = seqIndexes.get(var);
+ if (entry != null) {
+ if (result == null) result = new java.util.HashMap<>();
+ int skip = totalSeqs - 1 - entry[RuleContext.SEQ_VAR_SEQ_IDX];
+ result.put(var.getName(), new int[]{ skip,
entry[RuleContext.SEQ_VAR_FILTER_IDX] });
Review Comment:
Not an issue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]