use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method processCaseWhenFunction.
private TreeNode processCaseWhenFunction(TreeNode prev, CustomCaseWhenFunction customCaseWhenFunction) {
Traversal<?, ?> caseTraversal = customCaseWhenFunction.getCaseTraversal();
List<CustomWhenThenFunction> whenThenFunctionList = customCaseWhenFunction.getWhenThenFunctionList();
Traversal<?, ?> elseEndTraversal = customCaseWhenFunction.getElseEndTraversal();
boolean saveFlag = rootPathFlag;
this.rootPathFlag = false;
TreeNode caseTreeNode = travelTraversalAdmin(caseTraversal.asAdmin(), new SourceDelegateNode(prev, schema));
List<Pair<TreeNode, TreeNode>> whenThenNodeList = Lists.newArrayList();
for (CustomWhenThenFunction whenThenFunction : whenThenFunctionList) {
Pair<TreeNode, TreeNode> whenThenPair = Pair.of(travelTraversalAdmin(whenThenFunction.getWhenPredicate().asAdmin(), new SourceDelegateNode(caseTreeNode, schema)), travelTraversalAdmin(whenThenFunction.getThenTraversal().asAdmin(), new SourceDelegateNode(caseTreeNode, schema)));
whenThenNodeList.add(whenThenPair);
}
TreeNode elseEndTreeNode = elseEndTraversal == null ? null : travelTraversalAdmin(elseEndTraversal.asAdmin(), new SourceDelegateNode(caseTreeNode, schema));
this.rootPathFlag = saveFlag;
return new CaseWhenTreeNode(prev, schema, caseTreeNode, whenThenNodeList, elseEndTreeNode);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitTraversalMapStep.
private TreeNode visitTraversalMapStep(TraversalMapStep step, TreeNode prev) {
TreeNode mapTreeNode = travelTraversalAdmin(ReflectionUtils.getFieldValue(TraversalMapStep.class, step, "mapTraversal"), new SourceDelegateNode(prev, schema));
List<TreeNode> mapTreeNodeList = TreeNodeUtils.buildTreeNodeListFromLeaf(mapTreeNode);
for (TreeNode treeNode : mapTreeNodeList) {
if (treeNode.getNodeType() == NodeType.AGGREGATE || treeNode instanceof DedupGlobalTreeNode) {
throw new UnsupportedOperationException("Not support traversal in map");
}
}
return new TraversalMapTreeNode(prev, schema, mapTreeNode);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitPathStep.
private TreeNode visitPathStep(PathStep step, TreeNode prev) {
String from = ReflectionUtils.getFieldValue(PathStep.class, step, "fromLabel");
String to = ReflectionUtils.getFieldValue(PathStep.class, step, "toLabel");
Set<String> keepLabels = ReflectionUtils.getFieldValue(PathStep.class, step, "keepLabels");
if (StringUtils.isNotEmpty(from) || StringUtils.isNotEmpty(to) || (null != keepLabels && keepLabels.size() > 0)) {
throw new UnsupportedOperationException("Not support from/to/keepLabels in path step");
}
PathTreeNode pathTreeNode = new PathTreeNode(prev, schema);
pathTreeNode.addPathRequirement();
pathTreeNode.getUsedLabelList().addAll(treeNodeLabelManager.getUserLabelList());
boolean savePathFlag = this.rootPathFlag;
this.rootPathFlag = false;
Set<SourceDelegateNode> ringSourceNodeList = Sets.newHashSet();
List<Traversal.Admin<?, ?>> traversalRingList = step.getLocalChildren();
List<TreeNode> ringTreeNodeList = Lists.newArrayList();
for (Traversal.Admin<?, ?> traversalAdmin : traversalRingList) {
SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(pathTreeNode, schema);
ringSourceNodeList.add(sourceDelegateNode);
ringTreeNodeList.add(travelTraversalAdmin(traversalAdmin, sourceDelegateNode));
}
pathTreeNode.setRingTreeNodeList(ringTreeNodeList);
Set<String> propKeyList = pathTreeNode.getOutputPropList();
Set<ValueType> pathValueList = Sets.newHashSet();
processPathRequirement(pathTreeNode, propKeyList, pathValueList);
pathTreeNode.setPathValueList(pathValueList);
ringSourceNodeList.forEach(v -> {
if (pathValueList.size() > 1) {
v.setDelegateOutputValueType(new VarietyValueType(pathValueList));
} else {
v.setDelegateOutputValueType(pathValueList.iterator().next());
}
});
if (!propKeyList.isEmpty()) {
if (pathTreeNode.getInputNode() instanceof PropFillTreeNode) {
PropFillTreeNode propFillTreeNode = PropFillTreeNode.class.cast(pathTreeNode.getInputNode());
propFillTreeNode.getPropKeyList().addAll(propKeyList);
} else {
PropFillTreeNode propFillTreeNode = new PropFillTreeNode(prev, propKeyList, schema);
pathTreeNode.setInputNode(propFillTreeNode);
}
}
this.rootPathFlag = savePathFlag;
return pathTreeNode;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitMathStep.
private TreeNode visitMathStep(MathStep step, TreeNode prev) {
MathStep.TinkerExpression tinkerExpression = ReflectionUtils.getFieldValue(MathStep.class, step, "expression");
TraversalRing<?, Number> traversalRing = ReflectionUtils.getFieldValue(MathStep.class, step, "traversalRing");
List<TreeNode> ringTreeNodeList = Lists.newArrayList();
traversalRing.getTraversals().forEach(v -> ringTreeNodeList.add(travelTraversalAdmin(v, new SourceDelegateNode(prev, schema))));
return new MathTreeNode(prev, schema, ringTreeNodeList, tinkerExpression);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitSelectOneStep.
private TreeNode visitSelectOneStep(SelectOneStep step, TreeNode prev) {
Pop pop = step.getPop();
String selectLabel = (String) Lists.newArrayList(step.getScopeKeys()).get(0);
Traversal.Admin<?, ?> selectTraversal = ReflectionUtils.getFieldValue(SelectOneStep.class, step, "selectTraversal");
SelectOneTreeNode selectOneTreeNode = new SelectOneTreeNode(prev, selectLabel, pop, treeNodeLabelManager.getLabelTreeNodeList(selectLabel), schema);
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
if (null != selectTraversal) {
selectOneTreeNode.setTraversalTreeNode(travelTraversalAdmin(selectTraversal, new SourceDelegateNode(selectOneTreeNode, schema)));
}
rootPathFlag = saveFlag;
return selectOneTreeNode;
}
Aggregations