From e77f1eb2cd3b57ee98bf6ba5c3499d8a030a3a30 Mon Sep 17 00:00:00 2001 From: Chandra Kiran Bolla Date: Mon, 23 Feb 2026 23:49:14 -0500 Subject: [PATCH 1/3] Upgrade to TinkerPop 3.8.0: traversal, driver, strategy, predicate migration --- hugegraph-pd/hg-pd-test/pom.xml | 2 +- .../hugegraph/api/cypher/CypherClient.java | 6 ++- .../opencypher/CypherOpProcessor.java | 15 ++++-- .../org/apache/hugegraph/task/HugeTask.java | 1 + .../traversal/optimize/ConditionP.java | 49 ++++++++---------- .../optimize/HugeCountStepStrategy.java | 8 +-- .../optimize/HugePrimaryKeyStrategy.java | 50 ++++++++----------- .../traversal/optimize/QueryHolder.java | 8 ++- .../traversal/optimize/TraversalUtil.java | 29 ++++++++--- hugegraph-server/pom.xml | 1 - hugegraph-struct/pom.xml | 4 +- pom.xml | 6 +++ 12 files changed, 98 insertions(+), 81 deletions(-) diff --git a/hugegraph-pd/hg-pd-test/pom.xml b/hugegraph-pd/hg-pd-test/pom.xml index 44d5d084ca..0615cb90ec 100644 --- a/hugegraph-pd/hg-pd-test/pom.xml +++ b/hugegraph-pd/hg-pd-test/pom.xml @@ -193,7 +193,7 @@ org.apache.tinkerpop gremlin-shaded - 3.5.1 + ${tinkerpop.version} compile diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherClient.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherClient.java index 92ae18c54d..872e2fe9b6 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherClient.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/cypher/CypherClient.java @@ -35,8 +35,10 @@ import org.apache.tinkerpop.gremlin.driver.Cluster; import org.apache.tinkerpop.gremlin.driver.Result; import org.apache.tinkerpop.gremlin.driver.ResultSet; -import org.apache.tinkerpop.gremlin.driver.Tokens; -import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; +//import org.apache.tinkerpop.gremlin.driver.Tokens; +//import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; +import org.apache.tinkerpop.gremlin.util.Tokens; +import org.apache.tinkerpop.gremlin.util.message.RequestMessage; import org.slf4j.Logger; @ThreadSafe diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java index dfad9b9594..ebeb8d3ec2 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java @@ -19,7 +19,8 @@ import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static java.util.Optional.empty; -import static org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SERVER_ERROR; +//import static org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SERVER_ERROR; +import static org.apache.tinkerpop.gremlin.util.message.ResponseStatusCode.SERVER_ERROR; import static org.opencypher.gremlin.translation.StatementOption.EXPLAIN; import static org.slf4j.LoggerFactory.getLogger; @@ -33,10 +34,14 @@ import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; -import org.apache.tinkerpop.gremlin.driver.Tokens; -import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; +//import org.apache.tinkerpop.gremlin.driver.Tokens; +import org.apache.tinkerpop.gremlin.util.Tokens; +//import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; +import org.apache.tinkerpop.gremlin.util.message.RequestMessage; +//import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; +import org.apache.tinkerpop.gremlin.util.message.ResponseMessage; +//import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; +import org.apache.tinkerpop.gremlin.util.message.ResponseStatusCode; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal; diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeTask.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeTask.java index f9e4f120f4..1c5a086343 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeTask.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeTask.java @@ -340,6 +340,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { public boolean fail(Throwable e) { E.checkNotNull(e, "exception"); if (!(this.cancelled() && HugeException.isInterrupted(e))) { + e.printStackTrace(); LOG.warn("An exception occurred when running task: {}", this.id(), e); // Update status to FAILED if exception occurred(not interrupted) diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java index e41a0df706..002c5bed17 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java @@ -1,54 +1,47 @@ -/* - * 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.function.BiPredicate; - import org.apache.hugegraph.backend.query.Condition; import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.process.traversal.PBiPredicate; public class ConditionP extends P { private static final long serialVersionUID = 9094970577400072902L; - private ConditionP(final BiPredicate predicate, - Object value) { - super(predicate, value); + private ConditionP(final Condition.RelationType type, final Object value) { + super(new PBiPredicate() { + private static final long serialVersionUID = 1L; + + @Override + public boolean test(final Object first, final Object second) { + return type.test(first, second); + } + + @Override + public String getPredicateName() { + // Helps with serialization/debug readability + return type.name(); + } + }, value); } - public static ConditionP textContains(Object value) { + public static ConditionP textContains(final Object value) { return new ConditionP(Condition.RelationType.TEXT_CONTAINS, value); } - public static ConditionP contains(Object value) { + public static ConditionP contains(final Object value) { return new ConditionP(Condition.RelationType.CONTAINS, value); } - public static ConditionP containsK(Object value) { + public static ConditionP containsK(final Object value) { return new ConditionP(Condition.RelationType.CONTAINS_KEY, value); } - public static ConditionP containsV(Object value) { + public static ConditionP containsV(final Object value) { return new ConditionP(Condition.RelationType.CONTAINS_VALUE, value); } - public static ConditionP eq(Object value) { - // EQ that can compare two array + public static ConditionP eq(final Object value) { return new ConditionP(Condition.RelationType.EQ, value); } } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java index ef380d36b2..0c6daa2b82 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java @@ -30,8 +30,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep; import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep; import org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep; -import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateGlobalStep; -import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateLocalStep; +//import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateGlobalStep; +//import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateLocalStep; +import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep; import org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep; @@ -81,8 +82,7 @@ public void apply(Traversal.Admin traversal) { (step instanceof TraversalParent && TraversalHelper.anyStepRecursively(s -> { return s instanceof SideEffectStep || - s instanceof AggregateGlobalStep || - s instanceof AggregateLocalStep; + s instanceof AggregateStep; }, (TraversalParent) step))) { return; } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java index e6fa880837..7c864ea17a 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java @@ -1,20 +1,3 @@ -/* - * 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.LinkedList; @@ -25,6 +8,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.ProviderOptimizationStrategy; import org.apache.tinkerpop.gremlin.process.traversal.step.Mutating; +import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeStep; import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep; import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AddPropertyStep; @@ -56,7 +40,9 @@ public void apply(Traversal.Admin traversal) { if (i == 0 && step instanceof AddVertexStartStep) { curAddStep = (Mutating) step; continue; - } else if (curAddStep == null && (step) instanceof AddVertexStep) { + } + + if (curAddStep == null && step instanceof AddVertexStep) { curAddStep = (Mutating) step; continue; } @@ -75,35 +61,41 @@ public void apply(Traversal.Admin traversal) { if (propertyStep.getCardinality() == Cardinality.single || propertyStep.getCardinality() == null) { - Object[] kvs = new Object[2]; List kvList = new LinkedList<>(); propertyStep.getParameters().getRaw().forEach((k, v) -> { - if (T.key.equals(k)) { - kvs[0] = v.get(0); - } else if (T.value.equals(k)) { - kvs[1] = v.get(0); - } else { + if (!T.key.equals(k) && !T.value.equals(k)) { kvList.add(k.toString()); kvList.add(v.get(0)); } }); - curAddStep.configure(kvs); - if (!kvList.isEmpty()) { - curAddStep.configure(kvList.toArray(new Object[0])); + applyParameters(curAddStep, kvList); } removeSteps.add(step); } else { curAddStep = null; } + } + for (Step step : removeSteps) { + traversal.removeStep(step); } + } + + private void applyParameters(Mutating step, List kvList) { + + Object[] kvs = kvList.toArray(new Object[0]); + + if (step instanceof AddVertexStep) { + AddVertexStep vertexStep = (AddVertexStep) step; + vertexStep.getParameters().set(null, kvs); - for (Step index : removeSteps) { - traversal.removeStep(index); + } else if (step instanceof AddEdgeStep) { + AddEdgeStep edgeStep = (AddEdgeStep) step; + edgeStep.getParameters().set(null, kvs); } } } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/QueryHolder.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/QueryHolder.java index 917f777b95..653b393116 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/QueryHolder.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/QueryHolder.java @@ -18,14 +18,20 @@ package org.apache.hugegraph.traversal.optimize; import java.util.Iterator; +import java.util.List; import org.apache.hugegraph.backend.query.Aggregate; import org.apache.hugegraph.backend.query.Query; import org.apache.hugegraph.iterator.Metadatable; import org.apache.tinkerpop.gremlin.process.traversal.Order; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer; import org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder; -public interface QueryHolder extends HasContainerHolder, Metadatable { +public interface QueryHolder extends Metadatable { + + List getHasContainers(); + + void addHasContainer(HasContainer has); String SYSPROP_PAGE = "~page"; diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java index 11a5c0cee4..e049163770 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java @@ -168,15 +168,18 @@ public static void extractHasContainer(HugeGraphStep newStep, Step step = newStep; do { step = step.getNextStep(); - if (step instanceof HasStep) { + if (step instanceof HasContainerHolder) { HasContainerHolder holder = (HasContainerHolder) step; - for (HasContainer has : holder.getHasContainers()) { + + @SuppressWarnings("unchecked") + List containers = + (List) holder.getHasContainers(); + + for (HasContainer has : containers) { if (!GraphStep.processHasContainerIds(newStep, has)) { newStep.addHasContainer(has); } } - TraversalHelper.copyLabels(step, step.getPreviousStep(), false); - traversal.removeStep(step); } } while (step instanceof HasStep || step instanceof NoOpBarrierStep); } @@ -185,9 +188,14 @@ public static void extractHasContainer(HugeVertexStep newStep, Traversal.Admin traversal) { Step step = newStep; do { - if (step instanceof HasStep) { + if (step instanceof HasContainerHolder) { HasContainerHolder holder = (HasContainerHolder) step; - for (HasContainer has : holder.getHasContainers()) { + + @SuppressWarnings("unchecked") + List containers = + (List) holder.getHasContainers(); + + for (HasContainer has : containers) { newStep.addHasContainer(has); } TraversalHelper.copyLabels(step, step.getPreviousStep(), false); @@ -658,8 +666,13 @@ public static void convAllHasSteps(Traversal.Admin traversal) { } public static void convHasStep(HugeGraph graph, HasStep step) { - HasContainerHolder holder = step; - for (HasContainer has : holder.getHasContainers()) { + HasContainerHolder holder = (HasContainerHolder) step; + + @SuppressWarnings("unchecked") + List containers = + (List) holder.getHasContainers(); + + for (HasContainer has : containers) { convPredicateValue(graph, has); } } diff --git a/hugegraph-server/pom.xml b/hugegraph-server/pom.xml index a4dac32ab5..042bd056ae 100644 --- a/hugegraph-server/pom.xml +++ b/hugegraph-server/pom.xml @@ -42,7 +42,6 @@ 1.2.17 2.17.1 4.13.1 - 3.5.1 2.7 25.1-jre 4.5.13 diff --git a/hugegraph-struct/pom.xml b/hugegraph-struct/pom.xml index b88d0ae204..95714f0c03 100644 --- a/hugegraph-struct/pom.xml +++ b/hugegraph-struct/pom.xml @@ -34,7 +34,7 @@ 11 UTF-8 25.1-jre - 3.5.1 + @@ -86,7 +86,7 @@ org.apache.tinkerpop gremlin-shaded - 3.5.1 + ${tinkerpop.version} org.mindrot diff --git a/pom.xml b/pom.xml index d2595823fa..16796b1a2e 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ UTF-8 bash 1.5.0 + 3.8.0 @@ -117,6 +118,11 @@ provided true + + org.apache.tinkerpop + gremlin-shaded + ${tinkerpop.version} + From a4b1c8bd37144fb62c9c585172c719eabd6667e9 Mon Sep 17 00:00:00 2001 From: Chandra Kiran Bolla Date: Thu, 26 Feb 2026 12:15:12 -0500 Subject: [PATCH 2/3] WIP: Continue TinkerPop 3.8 predicate migration; remove StoreTest (removed in TP 3.8) --- .../traversal/optimize/ConditionP.java | 84 ++++++++--- .../optimize/HugePrimaryKeyStrategy.java | 19 +++ .../traversal/optimize/TraversalUtil.java | 136 ++++++++++++++++-- .../tinkerpop/ProcessBasicSuite.java | 3 - 4 files changed, 206 insertions(+), 36 deletions(-) diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java index 002c5bed17..4477425bbe 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/ConditionP.java @@ -1,3 +1,22 @@ +/* + * 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 org.apache.hugegraph.backend.query.Condition; @@ -8,40 +27,69 @@ public class ConditionP extends P { private static final long serialVersionUID = 9094970577400072902L; - private ConditionP(final Condition.RelationType type, final Object value) { - super(new PBiPredicate() { - private static final long serialVersionUID = 1L; + private final Condition.RelationType relationType; + + /** + * Adapter to wrap HugeGraph RelationType into a TinkerPop PBiPredicate + */ + private static class RelationAdapter implements PBiPredicate { + + private final Condition.RelationType type; + + RelationAdapter(Condition.RelationType type) { + this.type = type; + } - @Override - public boolean test(final Object first, final Object second) { - return type.test(first, second); - } + @Override + public boolean test(Object value, Object condition) { + return type.test(value, condition); + } - @Override - public String getPredicateName() { - // Helps with serialization/debug readability - return type.name(); - } - }, value); + @Override + public String toString() { + return type.name(); + } } - public static ConditionP textContains(final Object value) { + private ConditionP(final Condition.RelationType type, + final Object value) { + super(new RelationAdapter(type), value); + this.relationType = type; + } + + public Condition.RelationType relationType() { + return this.relationType; + } + + public static ConditionP of(Condition.RelationType type, Object value) { + return new ConditionP(type, value); + } + + // --- Restored helper factory methods --- + + public static ConditionP textContains(Object value) { return new ConditionP(Condition.RelationType.TEXT_CONTAINS, value); } - public static ConditionP contains(final Object value) { + public static ConditionP contains(Object value) { return new ConditionP(Condition.RelationType.CONTAINS, value); } - public static ConditionP containsK(final Object value) { + public static ConditionP containsK(Object value) { return new ConditionP(Condition.RelationType.CONTAINS_KEY, value); } - public static ConditionP containsV(final Object value) { + public static ConditionP containsV(Object value) { return new ConditionP(Condition.RelationType.CONTAINS_VALUE, value); } - public static ConditionP eq(final Object value) { + public static ConditionP eq(Object value) { return new ConditionP(Condition.RelationType.EQ, value); } + + @Override + public String toString() { + return this.relationType.name().toLowerCase() + + "(" + this.getValue() + ")"; + } } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java index 7c864ea17a..53b64ae4d8 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugePrimaryKeyStrategy.java @@ -1,3 +1,22 @@ +/* + * 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.LinkedList; diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java index e049163770..28ce812949 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java @@ -17,6 +17,10 @@ package org.apache.hugegraph.traversal.optimize; +//import static com.hankcs.hanlp.dictionary.other.CharType.type; +//import static jdk.incubator.vector.Float16.negate; +//import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.Symbols.has; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -54,8 +58,10 @@ import org.apache.hugegraph.util.JsonUtil; import org.apache.tinkerpop.gremlin.process.traversal.Compare; import org.apache.tinkerpop.gremlin.process.traversal.Contains; +import org.apache.tinkerpop.gremlin.process.traversal.NotP; import org.apache.tinkerpop.gremlin.process.traversal.Order; import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.process.traversal.PBiPredicate; import org.apache.tinkerpop.gremlin.process.traversal.Step; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; @@ -89,12 +95,25 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; +//import org.apache.hugegraph.backend.query.Condition; +//import org.apache.tinkerpop.gremlin.process.traversal.P; +//import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep; // (if used) +//import org.apache.tinkerpop.gremlin.process.traversal.util.AndP; +//import org.apache.tinkerpop.gremlin.process.traversal.util.OrP; +//import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP; +////import org.apache.tinkerpop.gremlin.process.traversal.util.NotP; +//import org.apache.tinkerpop.gremlin.process.traversal.TextP; +//import org.apache.tinkerpop.gremlin.process.traversal.Text; import com.google.common.collect.ImmutableList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public final class TraversalUtil { public static final String P_CALL = "P."; + private static final Logger log = LoggerFactory.getLogger(TraversalUtil.class); public static HugeGraph getGraph(Step step) { HugeGraph graph = tryGetGraph(step); @@ -355,28 +374,82 @@ public static void fillConditionQuery(ConditionQuery query, } } - public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) { + //public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) { + // P p = has.getPredicate(); + // E.checkArgument(p != null, "The predicate of has(%s) is null", has); + // BiPredicate bp = p.getBiPredicate(); + // Condition condition; + // if (keyForContainsKeyOrValue(has.getKey())) { + // condition = convContains2Relation(graph, has); + // } else if (bp instanceof Compare) { + // condition = convCompare2Relation(graph, type, has); + // } else if (bp instanceof Condition.RelationType) { + // condition = convRelationType2Relation(graph, type, has); + // } else if (bp instanceof Contains) { + // condition = convIn2Relation(graph, type, has); + // } else if (p instanceof AndP) { + // condition = convAnd(graph, type, has); + // } else if (p instanceof OrP) { + // condition = convOr(graph, type, has); + // } else { + // // TODO: deal with other Predicate + // throw newUnsupportedPredicate(p); + // } + // return condition; + //} + + public static Condition convHas2Condition(HasContainer has, + HugeType type, + HugeGraph graph) { + P p = has.getPredicate(); - E.checkArgument(p != null, "The predicate of has(%s) is null", has); + E.checkArgument(p != null, + "The predicate of has(%s) is null", has); + + // 🔴 Handle NOT FIRST (3.8 correct way) + if (p instanceof NotP) { + + P inner = p.negate(); + + Condition innerCondition = + convHas2Condition( + new HasContainer(has.getKey(), inner), + type, graph + ); + + return Condition.not(innerCondition); + } + + // 🔵 2️⃣ Handle AND + if (p instanceof AndP) { + return convAnd(graph, type, has); + } + + // 🔵 3️⃣ Handle OR + if (p instanceof OrP) { + return convOr(graph, type, has); + } + + // 🟢 4️⃣ Leaf predicates BiPredicate bp = p.getBiPredicate(); - Condition condition; + if (keyForContainsKeyOrValue(has.getKey())) { - condition = convContains2Relation(graph, has); + return convContains2Relation(graph, has); + } else if (bp instanceof Compare) { - condition = convCompare2Relation(graph, type, has); + return convCompare2Relation(graph, type, has); + } else if (bp instanceof Condition.RelationType) { - condition = convRelationType2Relation(graph, type, has); + return convRelationType2Relation(graph, type, has); + } else if (bp instanceof Contains) { - condition = convIn2Relation(graph, type, has); - } else if (p instanceof AndP) { - condition = convAnd(graph, type, has); - } else if (p instanceof OrP) { - condition = convOr(graph, type, has); - } else { - // TODO: deal with other Predicate - throw newUnsupportedPredicate(p); + return convIn2Relation(graph, type, has); + + } else if (p instanceof ConditionP) { + return convRelationType2Relation(graph, type, has); } - return condition; + + throw newUnsupportedPredicate(p); } public static Condition convAnd(HugeGraph graph, @@ -579,6 +652,39 @@ public static BackendException newUnsupportedPredicate(P predicate) { return new BackendException("Unsupported predicate: '%s'", predicate); } + + private static Condition.RelationType toHugeRelationType(final P predicate) { + + if (predicate instanceof ConditionP) { + return ((ConditionP) predicate).relationType(); + } + + throw newUnsupportedPredicate(predicate); + } + + private static Condition.RelationType convertPredicateToRelation(P predicate) { + boolean negated = false; + + //if (predicate instanceof NotP) { + // negated = true; + // predicate = ((NotP) predicate).getPredicate(); + //} + + + if (predicate instanceof ConditionP) { + Condition.RelationType type = ((ConditionP) predicate).relationType(); + return negated ? negate(type) : type; + } + + // TODO: handle Compare / Contains / Within etc as your existing code does + + throw newUnsupportedPredicate(predicate); + } + + private static Condition.RelationType negate(Condition.RelationType type) { + throw new BackendException("Unsupported negated predicate for relation: %s", type); + } + public static HugeKeys string2HugeKey(String key) { HugeKeys hugeKey = token2HugeKey(key); return hugeKey != null ? hugeKey : HugeKeys.valueOf(key); diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/ProcessBasicSuite.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/ProcessBasicSuite.java index e0fcba9832..2d79c9e07f 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/ProcessBasicSuite.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/ProcessBasicSuite.java @@ -81,7 +81,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SackTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectCapTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectTest; -import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StoreTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeTest; import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest; @@ -173,7 +172,6 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { SackTest.Traversals.class, SideEffectCapTest.Traversals.class, SideEffectTest.Traversals.class, - StoreTest.Traversals.class, SubgraphTest.Traversals.class, TreeTest.Traversals.class, @@ -261,7 +259,6 @@ public class ProcessBasicSuite extends AbstractGremlinSuite { SackTest.class, SideEffectCapTest.class, SideEffectTest.class, - StoreTest.class, SubgraphTest.class, TreeTest.class }; From 3790b386b101f91879b86ce131f72978f48cdd5f Mon Sep 17 00:00:00 2001 From: Chandra Kiran Bolla Date: Thu, 26 Feb 2026 12:34:24 -0500 Subject: [PATCH 3/3] Clean up TraversalUtil: remove temporary debug/commented code during 3.8 migration --- .../traversal/optimize/TraversalUtil.java | 44 +------------------ 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java index 28ce812949..5c3db01afb 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java @@ -17,9 +17,6 @@ package org.apache.hugegraph.traversal.optimize; -//import static com.hankcs.hanlp.dictionary.other.CharType.type; -//import static jdk.incubator.vector.Float16.negate; -//import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.Symbols.has; import java.util.ArrayList; import java.util.Collection; @@ -95,15 +92,7 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; -//import org.apache.hugegraph.backend.query.Condition; -//import org.apache.tinkerpop.gremlin.process.traversal.P; -//import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep; // (if used) -//import org.apache.tinkerpop.gremlin.process.traversal.util.AndP; -//import org.apache.tinkerpop.gremlin.process.traversal.util.OrP; -//import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP; -////import org.apache.tinkerpop.gremlin.process.traversal.util.NotP; -//import org.apache.tinkerpop.gremlin.process.traversal.TextP; -//import org.apache.tinkerpop.gremlin.process.traversal.Text; + import com.google.common.collect.ImmutableList; @@ -374,29 +363,6 @@ public static void fillConditionQuery(ConditionQuery query, } } - //public static Condition convHas2Condition(HasContainer has, HugeType type, HugeGraph graph) { - // P p = has.getPredicate(); - // E.checkArgument(p != null, "The predicate of has(%s) is null", has); - // BiPredicate bp = p.getBiPredicate(); - // Condition condition; - // if (keyForContainsKeyOrValue(has.getKey())) { - // condition = convContains2Relation(graph, has); - // } else if (bp instanceof Compare) { - // condition = convCompare2Relation(graph, type, has); - // } else if (bp instanceof Condition.RelationType) { - // condition = convRelationType2Relation(graph, type, has); - // } else if (bp instanceof Contains) { - // condition = convIn2Relation(graph, type, has); - // } else if (p instanceof AndP) { - // condition = convAnd(graph, type, has); - // } else if (p instanceof OrP) { - // condition = convOr(graph, type, has); - // } else { - // // TODO: deal with other Predicate - // throw newUnsupportedPredicate(p); - // } - // return condition; - //} public static Condition convHas2Condition(HasContainer has, HugeType type, @@ -406,7 +372,6 @@ public static Condition convHas2Condition(HasContainer has, E.checkArgument(p != null, "The predicate of has(%s) is null", has); - // 🔴 Handle NOT FIRST (3.8 correct way) if (p instanceof NotP) { P inner = p.negate(); @@ -420,17 +385,14 @@ public static Condition convHas2Condition(HasContainer has, return Condition.not(innerCondition); } - // 🔵 2️⃣ Handle AND if (p instanceof AndP) { return convAnd(graph, type, has); } - // 🔵 3️⃣ Handle OR if (p instanceof OrP) { return convOr(graph, type, has); } - // 🟢 4️⃣ Leaf predicates BiPredicate bp = p.getBiPredicate(); if (keyForContainsKeyOrValue(has.getKey())) { @@ -665,10 +627,6 @@ private static Condition.RelationType toHugeRelationType(final P predicate) { private static Condition.RelationType convertPredicateToRelation(P predicate) { boolean negated = false; - //if (predicate instanceof NotP) { - // negated = true; - // predicate = ((NotP) predicate).getPredicate(); - //} if (predicate instanceof ConditionP) {