imbajin commented on code in PR #3039:
URL: https://github.com/apache/hugegraph/pull/3039#discussion_r3351304886


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -181,6 +204,203 @@ public static void extractHasContainer(HugeGraphStep<?, 
?> newStep,
         }
     }
 
+    private static boolean followedByMatchStep(Step<?, ?> step) {
+        Step<?, ?> next = step.getNextStep();
+        while (next instanceof HasStep ||
+               next instanceof NoOpBarrierStep ||
+               next instanceof IdentityStep) {
+            next = next.getNextStep();
+        }
+        return next instanceof MatchStep;
+    }
+
+    private static boolean hasUnusableMatchPredicate(HugeGraphStep<?, ?> step,
+                                                     HasContainerHolder 
holder) {
+        HugeGraph graph = tryGetGraph(step);
+        for (HasContainer has : holder.getHasContainers()) {
+            if (!hasMatchIndexSensitivePredicate(has)) {
+                continue;
+            }
+            if (graph == null || !hasUsableMatchIndex(graph, step, has)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static List<HasContainer> extractUsableHasContainers(
+            HugeGraphStep<?, ?> step, HasContainerHolder holder) {
+        List<HasContainer> extracted = new ArrayList<>();
+        HugeGraph graph = tryGetGraph(step);
+        for (HasContainer has : holder.getHasContainers()) {
+            if (hasMatchIndexSensitivePredicate(has) &&
+                !hasUsableMatchIndex(graph, step, has)) {

Review Comment:
   ‼️ **Handle missing graph before checking match indexes**
   
   When `extractUsableHasContainers()` evaluates a match-sensitive predicate, 
this branch calls `hasUsableMatchIndex(graph, step, has)` even when 
`tryGetGraph(step)` returned `null`. The existing non-match path keeps such has 
steps local, but a graph-less traversal shaped like `__.V().has("age", 
P.gt(18)).match(...)` now throws `NullPointerException` at 
`graph.propertyKey(...)` instead. Please treat `graph == null` as not usable 
here, matching `hasUnusableMatchPredicate()` above, and keep the `HasStep` in 
the traversal.
   
   Evidence: a local regression test adding that traversal to 
`TraversalUtilOptimizeTest` fails with `Cannot invoke 
"org.apache.hugegraph.HugeGraph.propertyKey(String)" because "graph" is null`; 
the existing targeted suite still passes 30 tests, so this path is currently 
unprotected.



-- 
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]

Reply via email to