Rikkola commented on code in PR #6909:
URL: https://github.com/apache/incubator-kie/pull/6909#discussion_r3923053630
##########
drools-core/src/main/java/org/drools/core/reteoo/builder/PhreakNodeFactory.java:
##########
@@ -113,6 +128,83 @@ public TupleToObjectNode buildRightInputNode(int id,
LeftTupleSource leftInput,
}
return new TupleToObjectNode(id, leftInput, startTupleSource, context
);
}
+ public SequenceNode buildSequenceNode(final int id,
+ final LeftTupleSource tupleSource,
+ final Sequence seq,
+ final BuildContext context) {
+ SequenceNode node = new SequenceNode(id, tupleSource, context);
+ node.setSequencer(new Sequencer(seq));
+
+ NodeFactory nFactory =
CoreComponentFactory.get().getNodeFactoryService();
+
+ Pattern[] patterns = seq.getFilters();
+
+ // first attach the OTN sources in Rete.
+ // Use LinkedHashSet to preserve insertion order (first-seen per type),
+ // so objectTypeList index aligns with the first pattern index for
that type.
+ Set<ObjectType> objectTypeSet = new LinkedHashSet<>();
+ Arrays.stream(patterns).forEach(p ->
objectTypeSet.add(p.getObjectType()));
+ List<ObjectType> objectTypeList = new ArrayList<>(objectTypeSet);
+
+ Map<ObjectType, Integer> objectTypeIndex = new
HashMap<>(objectTypeList.size() * 2);
+ ObjectSource[] otns = new ObjectSource[objectTypeList.size()];
+ EntryPointNode epn =
context.getRuleBase().getRete().getEntryPointNode(context.getCurrentEntryPoint());
+ Map<ObjectType, ObjectTypeNode> existingOtns =
epn.getObjectTypeNodes();
+ for ( int i = 0; i < objectTypeList.size(); i++ ) {
+ ObjectType objectType = objectTypeList.get(i);
+ objectTypeIndex.put(objectType, i);
+ ObjectTypeNode existing = existingOtns.get(objectType);
+ if (existing != null) {
+ // Reuse the existing OTN — building a fresh one and calling
attach()
+ // would call EntryPointNode.addObjectSink which is a Map.put,
silently
+ // replacing the existing OTN and cutting off all rules
already wired to it.
+ otns[i] = existing;
+ } else {
+ otns[i] =
nFactory.buildObjectTypeNode(context.getNextNodeId(), epn, objectType, context);
+ otns[i].attach(context);
+ }
+ }
+
+ // For each source create an alpha adapter, which will map it to any
filters on the stack.
+ AlphaAdapter[] adapters = new AlphaAdapter[objectTypeList.size()];
+ for ( int i = 0; i < objectTypeList.size(); i++ ) {
+ adapters[i] = new AlphaAdapter(context.getNextNodeId(), otns[i],
+ context.getPartitionId(), node, i);
+
+ adapters[i].attach(context);
+ }
+ node.setAlphaAdapters(adapters);
+
+
+ // Create all the dynamic filters, these are added on demand to the
stack.
+ // filterIndex (i) is the pattern index — one per step.
+ // adapterIndex is the index of this pattern's type in objectTypeList
— one per distinct type.
+ DynamicFilterProto[] filters = new DynamicFilterProto[patterns.length];
+ for ( int i = 0; i < patterns.length; i++ ) {
+ List<Constraint> constraints = patterns[i].getConstraints();
+ if (constraints.isEmpty()) {
+ throw new IllegalArgumentException(
+ "sequence step " + i + " has no constraint expression.
" +
+ "Every sequence step must have at least one expr(). " +
+ "Add an expr() to the pattern, or use a dedicated fact
type per step.");
+ }
+ AlphaNodeFieldConstraint combined;
+ if (constraints.size() == 1) {
+ combined = (AlphaNodeFieldConstraint) constraints.get(0);
Review Comment:
Well spotted, but instead of reporting the limitation the limitation had to
be removed and support for comparing to declarations outside of the sequence
has been added.
--
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]