use of com.alibaba.graphscope.gaia.plan.meta.object.StepMetaRequiredInfo 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());
}
Aggregations