Search in sources :

Example 1 with RemovePathHistoryStep

use of com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep in project GraphScope by alibaba.

the class StepMetaCollector method nextTraverser.

protected TraverserElement nextTraverser(StepMetaBuilder metaBuilder, StepId stepId) {
    TraverserElement head = metaBuilder.getHead();
    TraversalsMeta<TraversalId, PathHistoryMeta> traversalsPath = (TraversalsMeta) metaBuilder.getConfig(MetaConfig.TRAVERSALS_PATH);
    Step step = metaBuilder.getStep();
    TraversalId metaId = stepId.getTraversalId();
    // V()/E()
    if (step instanceof CachePropGaiaGraphStep) {
        TraverserElement element;
        if (((GraphStep) step).returnsVertex()) {
            element = new TraverserElement(new CompositeObject(new Vertex()));
        } else {
            element = new TraverserElement(new CompositeObject(new Edge((PropertiesCacheStep) step)));
        }
        return element;
    }
    // V()/E()
    if (step instanceof GraphStep) {
        TraverserElement element;
        if (((GraphStep) step).returnsVertex()) {
            element = new TraverserElement(new CompositeObject(new Vertex()));
        } else {
            element = new TraverserElement(new CompositeObject(new Edge()));
        }
        return element;
    }
    // out/in/both
    if (step instanceof CachePropVertexStep) {
        TraverserElement element;
        if (((VertexStep) step).returnsVertex()) {
            element = new TraverserElement(new CompositeObject(new Vertex()));
        } else {
            element = new TraverserElement(new CompositeObject(new Edge((PropertiesCacheStep) step)));
        }
        return element;
    }
    // out/in/both
    if (step instanceof VertexStep) {
        TraverserElement element;
        if (((VertexStep) step).returnsVertex()) {
            element = new TraverserElement(new CompositeObject(new Vertex()));
        } else {
            element = new TraverserElement(new CompositeObject(new Edge()));
        }
        return element;
    }
    if (step instanceof TraversalFilterStep || step instanceof BySubTaskStep) {
        // create sub traversal
        Traversal.Admin sub = ((TraversalParent) step).getLocalChildren().get(0);
        newTraversal(sub, head.fork(), metaId.fork(stepId.getStepId(), 0), metaBuilder.getConf()).translate();
        return head;
    }
    if (step instanceof HasStep || step instanceof PropertyIdentityStep || step instanceof IdentityStep || step instanceof PathFilterStep) {
        return head;
    }
    if (step instanceof WherePredicateStep) {
        TraversalRing modulateBy = PlanUtils.getTraversalRing(((WherePredicateStep) step).getLocalChildren(), true);
        Optional<String> startKey = ((WherePredicateStep) step).getStartKey();
        TraverserElement tagHead = startKey.isPresent() ? traversalsPath.get(metaId).get().get(startKey.get()).get() : head;
        newTraversal(modulateBy.next(), tagHead, metaId, metaBuilder.getConf()).translate();
        List<String> tags = PlanUtils.getSelectKeysList(step);
        for (String tag : tags) {
            tagHead = traversalsPath.get(metaId).get().get(tag).get();
            newTraversal(modulateBy.next(), tagHead, metaId, metaBuilder.getConf()).translate();
        }
        return head;
    }
    if (step instanceof RepeatStep) {
        // create sub traversal
        Traversal.Admin sub = ((Traversal.Admin) ((RepeatStep) step).getGlobalChildren().get(0));
        TraverserElement loopResult = newTraversal(sub, head.fork(), metaId.fork(stepId.getStepId(), 0), metaBuilder.getConf()).translate();
        return new TraverserElement(loopResult.getObject());
    }
    if (step instanceof PathStep) {
        return new TraverserElement(new CompositeObject(List.class, Collections.singletonList(head.getObject())));
    }
    if (step instanceof SelectOneStep) {
        Map.Entry<String, Traversal.Admin> selectOne = PlanUtils.getFirstEntry(PlanUtils.getSelectTraversalMap(step));
        TraverserElement tagHead = (traversalsPath.get(metaId).get()).get(selectOne.getKey()).get();
        Traversal.Admin sub = selectOne.getValue();
        if (sub != null) {
            return newTraversal(sub, tagHead, metaId, metaBuilder.getConf()).translate();
        } else {
            return new TraverserElement(tagHead.getObject());
        }
    }
    if (step instanceof SelectStep) {
        Map<String, Traversal.Admin> selectTraversals = PlanUtils.getSelectTraversalMap(step);
        TraverserElement tagHead = null;
        for (Map.Entry<String, Traversal.Admin> entry : selectTraversals.entrySet()) {
            tagHead = (traversalsPath.get(metaId).get()).get(entry.getKey()).get();
            if (entry.getValue() != null) {
                tagHead = newTraversal(entry.getValue(), tagHead, metaId, metaBuilder.getConf()).translate();
            }
        }
        return new TraverserElement(new CompositeObject(List.class, Arrays.asList(new CompositeObject(Map.Entry.class, Arrays.asList(new CompositeObject(String.class), tagHead.getObject())))));
    }
    if (step instanceof OrderGlobalStep || step instanceof OrderGlobalLimitStep) {
        ((ComparatorHolder) step).getComparators().forEach(k -> {
            Traversal.Admin sub = (Traversal.Admin) ((Pair) k).getValue0();
            newTraversal(sub, head, metaId, metaBuilder.getConf()).translate();
        });
        return head;
    }
    if (step instanceof GroupCountStep) {
        Traversal.Admin keyTraversal = PlanUtils.getKeyTraversal(step);
        TraverserElement element = head;
        if (keyTraversal != null) {
            element = newTraversal(keyTraversal, head, metaId, metaBuilder.getConf()).translate();
        }
        return new TraverserElement(new CompositeObject(List.class, Arrays.asList(new CompositeObject(Map.Entry.class, Arrays.asList(element.getObject(), new CompositeObject(Integer.class))))));
    }
    if (step instanceof GroupStep) {
        Traversal.Admin keyTraversal = PlanUtils.getKeyTraversal(step);
        TraverserElement value = newTraversal(PlanUtils.getValueTraversal(step), head, metaId, metaBuilder.getConf()).translate();
        TraverserElement key = head;
        if (keyTraversal != null) {
            key = newTraversal(keyTraversal, head, metaId, metaBuilder.getConf()).translate();
        }
        return new TraverserElement(new CompositeObject(List.class, Arrays.asList(new CompositeObject(Map.Entry.class, Arrays.asList(key.getObject(), value.getObject())))));
    }
    if (step instanceof FoldStep) {
        return new TraverserElement(new CompositeObject(List.class, Collections.singletonList(head.getObject())));
    }
    if (step instanceof CountGlobalStep) {
        // for next unfold step
        return new TraverserElement(new CompositeObject(List.class, Arrays.asList(new CompositeObject(Integer.class))));
    }
    if (step instanceof UnionStep) {
        TraverserElement element = null;
        boolean findIdentity = false;
        int i = 0;
        for (Object s : ((UnionStep) step).getGlobalChildren()) {
            TraverserElement current = newTraversal((Traversal.Admin) s, head.fork(), metaId.fork(stepId.getStepId(), i), metaBuilder.getConf()).translate();
            if (!findIdentity) {
                element = current;
            }
            if (((Traversal.Admin) s).getSteps().size() == 1 && ((Traversal.Admin) s).getStartStep() instanceof IdentityStep) {
                findIdentity = true;
            }
            ++i;
        }
        return new TraverserElement(element.getObject());
    }
    if (step instanceof PropertiesStep) {
        return new TraverserElement(new CompositeObject(String.class));
    }
    if (step instanceof PropertyMapStep) {
        return new TraverserElement(new CompositeObject(List.class, Arrays.asList(new CompositeObject(Map.Entry.class, Arrays.asList(new CompositeObject(String.class), new CompositeObject(String.class))))));
    }
    if (step instanceof TraversalMapStep) {
        Traversal.Admin mapTraversal = (Traversal.Admin) ((TraversalMapStep) step).getLocalChildren().get(0);
        return newTraversal(mapTraversal, head, metaId, metaBuilder.getConf()).translate();
    }
    if (step instanceof PathLocalCountStep) {
        return new TraverserElement(new CompositeObject(Integer.class));
    }
    if (step instanceof EdgeVertexStep || step instanceof EdgeOtherVertexStep) {
        return new TraverserElement(new CompositeObject(new Vertex()));
    }
    if (step instanceof DedupGlobalStep || step instanceof RangeGlobalStep || step instanceof HasAnyStep) {
        return head;
    }
    if (step instanceof UnfoldStep || step instanceof PhysicalPlanUnfoldStep) {
        if (head.getObject().getClassName() != List.class) {
            Class invalidClass = head.getObject().getClassName() == null ? head.getObject().getElement().getClass() : head.getObject().getClassName();
            throw new UnsupportedOperationException("unfold has invalid input type " + invalidClass);
        }
        return new TraverserElement(head.getObject().getSubs().get(0));
    }
    if (step instanceof TransformTraverserStep || step instanceof RemovePathHistoryStep) {
        return head;
    }
    if (step instanceof IsStep) {
        return head;
    }
    LogicPlanGlobalMap.STEP stepType = LogicPlanGlobalMap.stepType(step);
    Optional<StepMetaRequiredInfo> metaInfoOpt = LogicPlanGlobalMap.getStepMetaRequiredInfo(stepType);
    if (metaInfoOpt.isPresent()) {
        return metaInfoOpt.get().getTraverserMapFunc().apply(new StepTraverserElement(step, head));
    }
    throw new UnsupportedOperationException("step not supported " + step.getClass());
}
Also used : TraversalRing(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) PropertiesCacheStep(com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.PropertiesCacheStep) LogicPlanGlobalMap(com.alibaba.graphscope.gaia.plan.LogicPlanGlobalMap) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) StepMetaRequiredInfo(com.alibaba.graphscope.gaia.plan.meta.object.StepMetaRequiredInfo) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) TransformTraverserStep(com.alibaba.graphscope.gaia.plan.strategy.global.TransformTraverserStep) PropertiesCacheStep(com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.PropertiesCacheStep) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) RemovePathHistoryStep(com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep) RemovePathHistoryStep(com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) LogicPlanGlobalMap(com.alibaba.graphscope.gaia.plan.LogicPlanGlobalMap) TransformTraverserStep(com.alibaba.graphscope.gaia.plan.strategy.global.TransformTraverserStep)

Example 2 with RemovePathHistoryStep

use of com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep in project GraphScope by alibaba.

the class GremlinStepResource method createResourceBuilder.

public static GremlinStep.Builder createResourceBuilder(Step t, Configuration conf) {
    GremlinStep.Builder builder = GremlinStep.newBuilder();
    IdMaker tagIdMaker = PlanUtils.getTagIdMaker(conf);
    if (!t.getLabels().isEmpty()) {
        t.getLabels().forEach(k -> builder.addTags(Gremlin.StepTag.newBuilder().setTag((int) tagIdMaker.getId(k))));
    }
    if (t.getNextStep() instanceof RemovePathHistoryStep) {
        RemovePathHistoryStep removeStep = (RemovePathHistoryStep) t.getNextStep();
        if (removeStep.getRemoveTags() != null) {
            removeStep.getRemoveTags().forEach(k -> {
                builder.addRemoveTags(Gremlin.StepTag.newBuilder().setTag((int) tagIdMaker.getId(k)));
            });
        }
    }
    return builder;
}
Also used : RemovePathHistoryStep(com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep) GremlinStep(com.alibaba.graphscope.common.proto.Gremlin.GremlinStep) IdMaker(com.alibaba.graphscope.gaia.idmaker.IdMaker)

Aggregations

RemovePathHistoryStep (com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep)2 GremlinStep (com.alibaba.graphscope.common.proto.Gremlin.GremlinStep)1 IdMaker (com.alibaba.graphscope.gaia.idmaker.IdMaker)1 LogicPlanGlobalMap (com.alibaba.graphscope.gaia.plan.LogicPlanGlobalMap)1 StepMetaRequiredInfo (com.alibaba.graphscope.gaia.plan.meta.object.StepMetaRequiredInfo)1 TransformTraverserStep (com.alibaba.graphscope.gaia.plan.strategy.global.TransformTraverserStep)1 PropertiesCacheStep (com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.PropertiesCacheStep)1 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)1 UnionStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)1 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)1 EmptyStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep)1 TraversalRing (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing)1