Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugegraph-pd/hg-pd-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-shaded</artifactId>
<version>3.5.1</version>
<version>${tinkerpop.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
/*
* 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
* 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.
* 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<Object> {

private static final long serialVersionUID = 9094970577400072902L;

private ConditionP(final BiPredicate<Object, Object> predicate,
Object value) {
super(predicate, value);
private final Condition.RelationType relationType;

/**
* Adapter to wrap HugeGraph RelationType into a TinkerPop PBiPredicate
*/
private static class RelationAdapter implements PBiPredicate<Object, Object> {

private final Condition.RelationType type;

RelationAdapter(Condition.RelationType type) {
this.type = type;
}

@Override
public boolean test(Object value, Object condition) {
return type.test(value, condition);
}

@Override
public String toString() {
return type.name();
}
}

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);
}
Expand All @@ -48,7 +84,12 @@ public static ConditionP containsV(Object value) {
}

public static ConditionP eq(Object value) {
// EQ that can compare two array
return new ConditionP(Condition.RelationType.EQ, value);
}

@Override
public String toString() {
return this.relationType.name().toLowerCase() +
"(" + this.getValue() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/*
* 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
* 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.
* 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;
Expand All @@ -25,6 +27,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;
Expand Down Expand Up @@ -56,7 +59,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;
}
Expand All @@ -75,35 +80,41 @@ public void apply(Traversal.Admin<?, ?> traversal) {
if (propertyStep.getCardinality() == Cardinality.single
|| propertyStep.getCardinality() == null) {

Object[] kvs = new Object[2];
List<Object> 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<Object> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HasContainer> getHasContainers();

void addHasContainer(HasContainer has);

String SYSPROP_PAGE = "~page";

Expand Down
Loading
Loading