use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method travelTraversalDirectly.
private <S, E> TreeNode travelTraversalDirectly(Traversal.Admin<S, E> admin, TreeNode parent) {
if (admin instanceof TokenTraversal) {
return new TokenTreeNode(parent, schema, TokenTraversal.class.cast(admin).getToken());
} else if (admin instanceof ValueTraversal) {
ValueTraversal elementValueTraversal = ValueTraversal.class.cast(admin);
String propKey = elementValueTraversal.getPropertyKey();
TreeNode bypassTreeNode = null;
Traversal.Admin<?, ?> bypassTraversal = ReflectionUtils.getFieldValue(AbstractLambdaTraversal.class, elementValueTraversal, "bypassTraversal");
if (null != bypassTraversal) {
bypassTreeNode = travelTraversalAdmin(bypassTraversal, new SourceDelegateNode(parent, schema));
}
return new ElementValueTreeNode(parent, propKey, bypassTreeNode, schema);
} else if (admin instanceof ColumnTraversal) {
ColumnTraversal columnTraversal = ColumnTraversal.class.cast(admin);
return new ColumnTreeNode(parent, schema, columnTraversal.getColumn());
} else if (admin instanceof IdentityTraversal) {
return parent;
} else if (admin instanceof TrueTraversal) {
return parent;
} else if (admin instanceof ConstantTraversal) {
return new ConstantTreeNode(parent, schema, admin.next());
} else if (admin instanceof CustomAggregationListTraversal) {
CustomAggregationListTraversal customAggregationListTraversal = CustomAggregationListTraversal.class.cast(admin);
List<TreeNode> aggNodeList = Lists.newArrayList();
boolean saveFlag = this.rootPathFlag;
this.rootPathFlag = false;
List<Traversal<?, ?>> traversalList = customAggregationListTraversal.getTraversalList();
for (Traversal<?, ?> aggTraversal : traversalList) {
aggNodeList.add(travelTraversalAdmin(aggTraversal.asAdmin(), new SourceDelegateNode(parent, schema)));
}
this.rootPathFlag = saveFlag;
return new AggregationListTreeNode(parent, schema, customAggregationListTraversal.getNameList(), aggNodeList);
} else {
throw new IllegalArgumentException("Not deal with direct traversal => " + admin);
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitUnionStep.
private TreeNode visitUnionStep(UnionStep step, TreeNode prev) {
List<Traversal.Admin<?, ?>> unionTraversalList = step.getGlobalChildren();
List<TreeNode> unionTreeNodeList = Lists.newArrayList();
unionTraversalList.forEach(v -> unionTreeNodeList.add(travelTraversalAdmin(v, new SourceDelegateNode(prev, schema))));
UnionTreeNode unionTreeNode = new UnionTreeNode(prev, schema, unionTreeNodeList);
return unionTreeNode;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitAndStep.
private TreeNode visitAndStep(AndStep step, TreeNode prev) {
List<Traversal.Admin<?, ?>> traversals = ReflectionUtils.getFieldValue(ConnectiveStep.class, step, "traversals");
List<TreeNode> andTreeNodeList = Lists.newArrayList();
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
traversals.forEach(v -> {
TreeNode treeNode = travelTraversalAdmin(v, new SourceDelegateNode(prev, schema));
if (treeNode instanceof HasTreeNode) {
TreeNode hasInputNode = ((HasTreeNode) treeNode).getInputNode();
if (hasInputNode instanceof SourceVertexTreeNode || hasInputNode instanceof SourceEdgeTreeNode || hasInputNode instanceof EdgeTreeNode) {
prev.addHasContainerList(((HasTreeNode) treeNode).getHasContainerList());
} else {
andTreeNodeList.add(treeNode);
}
} else {
andTreeNodeList.add(treeNode);
}
});
rootPathFlag = saveFlag;
if (andTreeNodeList.isEmpty()) {
return prev;
} else {
AndTreeNode andTreeNode = new AndTreeNode(prev, schema);
andTreeNode.getAndTreeNodeList().addAll(andTreeNodeList);
return andTreeNode;
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitLambdaMapStep.
private TreeNode visitLambdaMapStep(LambdaMapStep step, TreeNode prev) {
Function functionObj = step.getMapFunction();
Function mapFunction;
if (functionObj instanceof FunctionTraverser) {
mapFunction = ReflectionUtils.getFieldValue(FunctionTraverser.class, functionObj, "function");
} else {
mapFunction = functionObj;
}
if (mapFunction instanceof CustomCaseWhenFunction) {
CustomCaseWhenFunction customCaseWhenFunction = CustomCaseWhenFunction.class.cast(mapFunction);
return processCaseWhenFunction(prev, customCaseWhenFunction);
} else if (mapFunction instanceof CustomAggregationListTraversal) {
CustomAggregationListTraversal customAggregationListTraversal = CustomAggregationListTraversal.class.cast(mapFunction);
List<Traversal<?, ?>> aggregateTraversalList = customAggregationListTraversal.getTraversalList();
List<TreeNode> aggregateNodeList = Lists.newArrayList();
boolean saveFlag = rootPathFlag;
this.rootPathFlag = false;
for (Traversal<?, ?> traversal : aggregateTraversalList) {
aggregateNodeList.add(travelTraversalAdmin(traversal.asAdmin(), new SourceDelegateNode(prev, schema)));
}
this.rootPathFlag = saveFlag;
return new AggregationListTreeNode(prev, schema, customAggregationListTraversal.getNameList(), aggregateNodeList);
} else if (mapFunction instanceof MapPropFillFunction || mapFunction instanceof RangeSumFunction) {
return new LambdaMapTreeNode(prev, schema, mapFunction, null);
} else {
if (this.lambdaEnableFlag) {
return new LambdaMapTreeNode(prev, schema, mapFunction, buildLambdaIndex(step));
} else {
throw new UnsupportedOperationException("Not support lambda map yet");
}
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitBranchStep.
private TreeNode visitBranchStep(BranchStep step, TreeNode prev) {
Traversal.Admin<?, ?> branchTraversal = ReflectionUtils.getFieldValue(BranchStep.class, step, "branchTraversal");
Map<TraversalOptionParent.Pick, List<Traversal.Admin<?, ?>>> traversalPickOptions = ReflectionUtils.getFieldValue(BranchStep.class, step, "traversalPickOptions");
List<org.javatuples.Pair<Traversal.Admin, Traversal.Admin<?, ?>>> traversalOptions = ReflectionUtils.getFieldValue(BranchStep.class, step, "traversalOptions");
checkNotNull(branchTraversal, "branch traversal can't be null");
checkArgument(!traversalPickOptions.isEmpty() || !traversalOptions.isEmpty(), "traversal options can't be empty");
Map<Object, List<Traversal.Admin<?, ?>>> traversalAllOptions = new HashMap<>();
traversalAllOptions.putAll(traversalPickOptions);
traversalOptions.forEach(pair -> {
Traversal.Admin left = pair.getValue0();
if (left instanceof PredicateTraversal.Admin) {
PredicateTraversal predicateTraversal = (PredicateTraversal) left;
P p = ReflectionUtils.getFieldValue(PredicateTraversal.class, predicateTraversal, "predicate");
traversalAllOptions.computeIfAbsent(p.getValue(), k -> Lists.newArrayList()).add(pair.getValue1());
}
});
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
TreeNode branchTreeNode = travelTraversalAdmin(branchTraversal, new SourceDelegateNode(prev, schema));
rootPathFlag = saveFlag;
TreeNode noneTreeNode = null, anyTreeNode = null;
Map<Object, List<TreeNode>> branchOptionList = Maps.newHashMap();
BranchTreeNode branchOptionTreeNode = new BranchTreeNode(prev, schema, branchTreeNode);
for (Map.Entry<Object, List<Traversal.Admin<?, ?>>> entry : traversalAllOptions.entrySet()) {
if (entry.getKey() == TraversalOptionParent.Pick.none) {
checkArgument(entry.getValue().size() == 1);
noneTreeNode = travelTraversalAdmin(entry.getValue().get(0), new SourceDelegateNode(prev, schema));
} else if (entry.getKey() == TraversalOptionParent.Pick.any) {
checkArgument(entry.getValue().size() == 1);
anyTreeNode = travelTraversalAdmin(entry.getValue().get(0), new SourceDelegateNode(prev, schema));
} else {
List<TreeNode> optionTreeNodeList = Lists.newArrayList();
for (Traversal.Admin<?, ?> v : entry.getValue()) {
TreeNode optionTreeNode = travelTraversalAdmin(v, new SourceDelegateNode(prev, schema));
optionTreeNodeList.add(optionTreeNode);
}
branchOptionList.put(entry.getKey(), optionTreeNodeList);
}
}
branchOptionTreeNode.setNoneTreeNode(noneTreeNode);
branchOptionTreeNode.setAnyTreeNode(anyTreeNode);
branchOptionTreeNode.setOptionTreeNodeList(branchOptionList);
return branchOptionTreeNode;
}
Aggregations