Search in sources :

Example 1 with ReducingBarrierStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep in project sqlg by pietermartin.

the class SqlgOptionalStepStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    // noinspection OptionalGetWithoutIsPresent
    if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
        return;
    }
    List<OptionalStep> optionalSteps = TraversalHelper.getStepsOfAssignableClass(OptionalStep.class, traversal);
    for (OptionalStep<S> optionalStep : optionalSteps) {
        // The predicate branch step is a local traversal.
        // As such if it contains a ReducingBarrierStep the SqlgBranchStepBarrier will not work.
        Traversal.Admin<S, S> optionalTraversal = optionalStep.getLocalChildren().get(0);
        List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClass(ReducingBarrierStep.class, optionalTraversal);
        if (!reducingBarrierSteps.isEmpty()) {
            continue;
        }
        SqlgOptionalStepBarrier sqlgOptionalStepBarrier = new SqlgOptionalStepBarrier<>(traversal, optionalTraversal);
        for (String label : optionalStep.getLabels()) {
            sqlgOptionalStepBarrier.addLabel(label);
        }
        TraversalHelper.replaceStep(optionalStep, sqlgOptionalStepBarrier, optionalStep.getTraversal());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) OptionalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) SqlgOptionalStepBarrier(org.umlg.sqlg.step.barrier.SqlgOptionalStepBarrier) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep)

Example 2 with ReducingBarrierStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep in project sqlg by pietermartin.

the class SqlgTraversalFilterStepStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    // noinspection OptionalGetWithoutIsPresent
    if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
        return;
    }
    List<TraversalFilterStep> traversalFilterSteps = TraversalHelper.getStepsOfAssignableClass(TraversalFilterStep.class, traversal);
    for (TraversalFilterStep<S> traversalFilterStep : traversalFilterSteps) {
        List<Traversal.Admin<S, ?>> filterTraversals = traversalFilterStep.getLocalChildren();
        Preconditions.checkState(filterTraversals.size() == 1);
        Traversal.Admin<S, ?> filterTraversal = filterTraversals.get(0);
        // reducing barrier steps like count does not work with Sqlg's barrier optimizations
        List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ReducingBarrierStep.class, filterTraversal);
        if (!reducingBarrierSteps.isEmpty()) {
            continue;
        }
        SqlgTraversalFilterStepBarrier sqlgTraversalFilterStepBarrier = new SqlgTraversalFilterStepBarrier<>(traversal, filterTraversal);
        for (String label : traversalFilterStep.getLabels()) {
            sqlgTraversalFilterStepBarrier.addLabel(label);
        }
        TraversalHelper.replaceStep(traversalFilterStep, sqlgTraversalFilterStepBarrier, traversalFilterStep.getTraversal());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep) SqlgTraversalFilterStepBarrier(org.umlg.sqlg.step.barrier.SqlgTraversalFilterStepBarrier)

Example 3 with ReducingBarrierStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep in project sqlg by pietermartin.

the class SqlgChooseStepStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    // noinspection OptionalGetWithoutIsPresent
    if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
        return;
    }
    List<ChooseStep> chooseSteps = TraversalHelper.getStepsOfAssignableClass(ChooseStep.class, traversal);
    for (ChooseStep<S, E, M> chooseStep : chooseSteps) {
        Traversal.Admin<S, M> predicateTraversal = chooseStep.getLocalChildren().get(0);
        // The predicate branch step is a local traversal.
        // As such if it contains a ReducingBarrierStep the SqlgBranchStepBarrier will not work.
        List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClass(ReducingBarrierStep.class, predicateTraversal);
        if (!reducingBarrierSteps.isEmpty()) {
            continue;
        }
        if (predicateTraversal.getSteps().get(predicateTraversal.getSteps().size() - 1) instanceof HasNextStep) {
            predicateTraversal.removeStep(predicateTraversal.getSteps().get(predicateTraversal.getSteps().size() - 1));
        }
        SqlgBranchStepBarrier sqlgBranchStepBarrier = new SqlgChooseStepBarrier<>(traversal, predicateTraversal);
        for (String label : chooseStep.getLabels()) {
            sqlgBranchStepBarrier.addLabel(label);
        }
        try {
            Field traversalOptionsField = chooseStep.getClass().getSuperclass().getDeclaredField("traversalOptions");
            traversalOptionsField.setAccessible(true);
            Map<M, List<Traversal.Admin<S, E>>> traversalOptions = (Map<M, List<Traversal.Admin<S, E>>>) traversalOptionsField.get(chooseStep);
            for (Map.Entry<M, List<Traversal.Admin<S, E>>> entry : traversalOptions.entrySet()) {
                for (Traversal.Admin<S, E> admin : entry.getValue()) {
                    sqlgBranchStepBarrier.addGlobalChildOption(entry.getKey(), admin);
                }
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        TraversalHelper.replaceStep(chooseStep, sqlgBranchStepBarrier, chooseStep.getTraversal());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) ChooseStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep) Field(java.lang.reflect.Field) List(java.util.List) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep) HasNextStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.HasNextStep) SqlgChooseStepBarrier(org.umlg.sqlg.step.barrier.SqlgChooseStepBarrier) Map(java.util.Map) SqlgBranchStepBarrier(org.umlg.sqlg.step.barrier.SqlgBranchStepBarrier)

Example 4 with ReducingBarrierStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep in project sqlg by pietermartin.

the class SqlgWhereTraversalStepStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    // noinspection OptionalGetWithoutIsPresent
    if (!(traversal.getGraph().get() instanceof SqlgGraph)) {
        return;
    }
    List<WhereTraversalStep> whereTraversalSteps = TraversalHelper.getStepsOfAssignableClass(WhereTraversalStep.class, traversal);
    for (WhereTraversalStep<S> whereTraversalStep : whereTraversalSteps) {
        List<Traversal.Admin<?, ?>> whereTraversals = whereTraversalStep.getLocalChildren();
        Preconditions.checkState(whereTraversals.size() == 1);
        Traversal.Admin<?, ?> whereTraversal = whereTraversals.get(0);
        // reducing barrier steps like count does not work with Sqlg's barrier optimizations
        List<ReducingBarrierStep> reducingBarrierSteps = TraversalHelper.getStepsOfAssignableClassRecursively(ReducingBarrierStep.class, whereTraversal);
        if (!reducingBarrierSteps.isEmpty()) {
            continue;
        }
        SqlgWhereTraversalStepBarrier sqlgTraversalFilterStepBarrier = new SqlgWhereTraversalStepBarrier<>(traversal, whereTraversalStep);
        for (String label : whereTraversalStep.getLabels()) {
            sqlgTraversalFilterStepBarrier.addLabel(label);
        }
        TraversalHelper.replaceStep(whereTraversalStep, sqlgTraversalFilterStepBarrier, whereTraversalStep.getTraversal());
    }
}
Also used : SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) WhereTraversalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) SqlgWhereTraversalStepBarrier(org.umlg.sqlg.step.barrier.SqlgWhereTraversalStepBarrier) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep)

Aggregations

Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)4 ReducingBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep)4 SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)4 Field (java.lang.reflect.Field)1 List (java.util.List)1 Map (java.util.Map)1 ChooseStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep)1 OptionalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.OptionalStep)1 TraversalFilterStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep)1 WhereTraversalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep)1 HasNextStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.HasNextStep)1 SqlgBranchStepBarrier (org.umlg.sqlg.step.barrier.SqlgBranchStepBarrier)1 SqlgChooseStepBarrier (org.umlg.sqlg.step.barrier.SqlgChooseStepBarrier)1 SqlgOptionalStepBarrier (org.umlg.sqlg.step.barrier.SqlgOptionalStepBarrier)1 SqlgTraversalFilterStepBarrier (org.umlg.sqlg.step.barrier.SqlgTraversalFilterStepBarrier)1 SqlgWhereTraversalStepBarrier (org.umlg.sqlg.step.barrier.SqlgWhereTraversalStepBarrier)1