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


##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeConnectiveLabelStepStrategy.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hugegraph.traversal.optimize;
+
+import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Set;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
+import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.InlineFilterStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.T;
+
+public final class HugeConnectiveLabelStepStrategy
+        extends 
AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy>
+        implements TraversalStrategy.OptimizationStrategy {
+
+    private static final long serialVersionUID = 2532355470697047377L;
+
+    private static final HugeConnectiveLabelStepStrategy INSTANCE =
+            new HugeConnectiveLabelStepStrategy();
+
+    private HugeConnectiveLabelStepStrategy() {
+        // pass
+    }
+
+    @Override
+    public void apply(Traversal.Admin<?, ?> traversal) {
+        Set<Traversal.Admin<?, ?>> visited =
+                Collections.newSetFromMap(new IdentityHashMap<>());
+        markConnectiveLabelSteps(traversal, visited);
+    }
+
+    @Override
+    public Set<Class<? extends TraversalStrategy.OptimizationStrategy>> 
applyPost() {
+        return Collections.singleton(InlineFilterStrategy.class);
+    }
+
+    public static HugeConnectiveLabelStepStrategy instance() {
+        return INSTANCE;
+    }
+
+    private static void markConnectiveLabelSteps(Traversal.Admin<?, ?> 
traversal,
+                                                Set<Traversal.Admin<?, ?>> 
visited) {
+        if (!visited.add(traversal)) {
+            return;
+        }
+
+        for (AndStep<?> step : TraversalHelper.getStepsOfClass(AndStep.class,

Review Comment:
   ‼️ `OrStep` connective label filters still miss this optimization path.
   
   This strategy only scans `AndStep`, but label-only `or()` children can hit 
the same unsafe range + connective-label shape as the fixed 
`and(__.hasLabel(...))` case. I verified the PR head still fails for a 
traversal like:
   
   ```java
   g.E().has("ep4", P.lt(0.32696354F))
        .or(__.hasLabel("el2"), __.hasLabel("el3"))
        .count()
   ```
   
   It still throws `NoIndexException` for the non-indexed `ep4` range under one 
of the labels. Please generalize the marker pass to cover label-only `OrStep` 
as well, or operate on the relevant connective step abstraction while keeping 
the same safety checks, and add a regression test for `or(__.hasLabel("el2"), 
__.hasLabel("el3"))`.



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