blob: 47583c4f1153236b8d57ffc7c8e47f07b6f6e3ea [file] [log] [blame]
/*
* 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.List;
import java.util.Set;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.ProviderOptimizationStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
public final class HugeGraphStepStrategy
extends AbstractTraversalStrategy<ProviderOptimizationStrategy>
implements ProviderOptimizationStrategy {
private static final long serialVersionUID = -2952498905649139719L;
private static final HugeGraphStepStrategy INSTANCE;
static {
INSTANCE = new HugeGraphStepStrategy();
}
private HugeGraphStepStrategy() {
// pass
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void apply(Traversal.Admin<?, ?> traversal) {
TraversalUtil.convAllHasSteps(traversal);
// Extract conditions in GraphStep
List<GraphStep> steps = TraversalHelper.getStepsOfClass(
GraphStep.class, traversal);
for (GraphStep originStep : steps) {
TraversalUtil.trySetGraph(originStep,
TraversalUtil.tryGetGraph(steps.get(0)));
HugeGraphStep<?, ?> newStep = new HugeGraphStep<>(originStep);
TraversalHelper.replaceStep(originStep, newStep, traversal);
TraversalUtil.extractHasContainer(newStep, traversal);
// TODO: support order-by optimize
// TraversalUtil.extractOrder(newStep, traversal);
TraversalUtil.extractRange(newStep, traversal, false);
TraversalUtil.extractCount(newStep, traversal);
}
}
@Override
public Set<Class<? extends ProviderOptimizationStrategy>> applyPost() {
return Collections.singleton(HugeCountStepStrategy.class);
}
public static HugeGraphStepStrategy instance() {
return INSTANCE;
}
}