use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitOrStep.
private TreeNode visitOrStep(OrStep step, TreeNode prev) {
List<Traversal.Admin<?, ?>> traversals = ReflectionUtils.getFieldValue(ConnectiveStep.class, step, "traversals");
List<TreeNode> orTreeNodeList = Lists.newArrayList();
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
traversals.forEach(v -> orTreeNodeList.add(travelTraversalAdmin(v, new SourceDelegateNode(prev, schema))));
rootPathFlag = saveFlag;
return new OrTreeNode(orTreeNodeList, prev, schema);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method processPathRequirement.
private void processPathRequirement(TreeNode treeNode, Set<String> propKeyList, Set<ValueType> pathValueList) {
if (treeNode instanceof SourceDelegateNode) {
processPathRequirement(SourceDelegateNode.class.cast(treeNode).getDelegate(), propKeyList, pathValueList);
return;
}
if (treeNode instanceof SourceTreeNode || treeNode.getNodeType() == NodeType.AGGREGATE) {
return;
}
UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(treeNode);
if (treeNode instanceof RepeatTreeNode) {
RepeatTreeNode repeatTreeNode = RepeatTreeNode.class.cast(treeNode);
TreeNode repeatBodyTreeNode = repeatTreeNode.getRepeatBodyTreeNode();
processPathRequirement(repeatBodyTreeNode, propKeyList, pathValueList);
} else {
if (treeNode.isPathFlag()) {
treeNode.addPathRequirement();
if (treeNode instanceof PathTreeNode) {
((PathTreeNode) treeNode).disablePathDelete();
}
ValueType inputValueType = unaryTreeNode.getInputNode().getOutputValueType();
pathValueList.add(inputValueType);
if (null != propKeyList && !propKeyList.isEmpty() && inputValueType instanceof VertexValueType) {
if (unaryTreeNode.getInputNode() instanceof PropFillTreeNode) {
PropFillTreeNode propFillTreeNode = PropFillTreeNode.class.cast(unaryTreeNode.getInputNode());
propFillTreeNode.getPropKeyList().addAll(propKeyList);
} else {
PropFillTreeNode propFillTreeNode = new PropFillTreeNode(null, propKeyList, schema);
TreeNode inputTreeNode = unaryTreeNode.getInputNode();
unaryTreeNode.setInputNode(propFillTreeNode);
propFillTreeNode.setInputNode(inputTreeNode);
}
}
}
}
processPathRequirement(unaryTreeNode.getInputNode(), propKeyList, pathValueList);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitSelectStep.
private TreeNode visitSelectStep(SelectStep step, TreeNode prev) {
List<String> selectKeyList = ReflectionUtils.getFieldValue(SelectStep.class, step, "selectKeys");
Pop pop = step.getPop();
List<Traversal.Admin<?, ?>> ringTraversalList = step.getLocalChildren();
if (selectKeyList.size() < 2) {
throw new IllegalArgumentException("select key size < 2 for select operator");
}
Map<String, List<TreeNode>> labelTreeNodeList = Maps.newHashMap();
selectKeyList.forEach(v -> {
if (treeNodeLabelManager.getLabelIndexList().containsKey(v)) {
labelTreeNodeList.put(v, treeNodeLabelManager.getTreeNodeList(v));
}
});
SelectTreeNode selectTreeNode = new SelectTreeNode(prev, selectKeyList, pop, labelTreeNodeList, schema);
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
if (!ringTraversalList.isEmpty()) {
Set<ValueType> valueTypeList = selectKeyList.stream().map(v -> treeNodeLabelManager.getValueType(v, pop)).collect(Collectors.toSet());
ValueType selectValueType = valueTypeList.size() > 1 ? new VarietyValueType(valueTypeList) : valueTypeList.iterator().next();
ringTraversalList.forEach(v -> {
SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(selectTreeNode, schema);
sourceDelegateNode.setDelegateOutputValueType(selectValueType);
selectTreeNode.addTraversalTreeNode(travelTraversalAdmin(v, sourceDelegateNode));
});
}
rootPathFlag = saveFlag;
return selectTreeNode;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitTraversalFilterStep.
private TreeNode visitTraversalFilterStep(TraversalFilterStep step, TreeNode prev) {
Traversal.Admin<?, ?> filterTraversal = (Traversal.Admin<?, ?>) step.getLocalChildren().get(0);
TreeNode filterTreeNode;
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
filterTreeNode = travelTraversalAdmin(filterTraversal, new SourceDelegateNode(prev, schema));
rootPathFlag = saveFlag;
if (!(filterTreeNode instanceof RangeGlobalTreeNode)) {
TreeNode currentTreeNode = filterTreeNode;
boolean addRangeFlag = false;
while (currentTreeNode instanceof UnaryTreeNode) {
if (currentTreeNode.getNodeType() == NodeType.FILTER || currentTreeNode.getNodeType() == NodeType.MAP) {
currentTreeNode = UnaryTreeNode.class.cast(currentTreeNode).getInputNode();
continue;
}
if (currentTreeNode.getNodeType() == NodeType.FLATMAP) {
addRangeFlag = true;
}
break;
}
if (addRangeFlag) {
filterTreeNode = new RangeGlobalTreeNode(filterTreeNode, schema, 0, 1);
}
}
if (filterTreeNode instanceof SourceTreeNode) {
throw new IllegalArgumentException();
} else if (UnaryTreeNode.class.cast(filterTreeNode).getInputNode() instanceof SourceTreeNode && (filterTreeNode instanceof SelectOneTreeNode || filterTreeNode instanceof PropertyNode)) {
String key;
if (filterTreeNode instanceof SelectOneTreeNode) {
key = SelectOneTreeNode.class.cast(filterTreeNode).getSelectLabel();
} else {
key = PropertyNode.class.cast(filterTreeNode).getPropKeyList().iterator().next();
}
HasContainer hasContainer = new HasContainer(key, null);
if (prev instanceof SourceTreeNode && !(prev instanceof SourceDelegateNode)) {
SourceTreeNode.class.cast(prev).addHasContainer(hasContainer);
return prev;
} else {
return new HasTreeNode(prev, Lists.newArrayList(hasContainer), schema);
}
} else {
TraversalFilterTreeNode traversalFilterTreeNode = new TraversalFilterTreeNode(prev, schema);
traversalFilterTreeNode.setFilterTreeNode(filterTreeNode);
return traversalFilterTreeNode;
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeManager method validOrderResult.
/**
* Add order node to reorder result
*/
private void validOrderResult() {
TreeNode currentTreeNode = treeLeaf;
TreeNode orderTreeNode = null;
while (!(currentTreeNode instanceof SourceTreeNode)) {
if (currentTreeNode instanceof OrderGlobalTreeNode) {
orderTreeNode = currentTreeNode;
break;
} else {
currentTreeNode = UnaryTreeNode.class.cast(currentTreeNode).getInputNode();
}
}
if (null != orderTreeNode) {
OrderGlobalTreeNode orderGlobalTreeNode = OrderGlobalTreeNode.class.cast(orderTreeNode);
TreeNode aggTreeNode = orderTreeNode.getOutputNode();
while (aggTreeNode != null && aggTreeNode.getNodeType() != NodeType.AGGREGATE) {
aggTreeNode = aggTreeNode.getOutputNode();
}
if (null != aggTreeNode) {
if (aggTreeNode instanceof FoldTreeNode) {
TreeNode inputTreeNode = UnaryTreeNode.class.cast(aggTreeNode).getInputNode();
if (inputTreeNode == orderTreeNode) {
return;
}
UnaryTreeNode inputUnaryTreeNode = UnaryTreeNode.class.cast(inputTreeNode);
if (inputUnaryTreeNode.getInputNode() == orderTreeNode && (inputUnaryTreeNode instanceof EdgeVertexTreeNode && EdgeVertexTreeNode.class.cast(inputUnaryTreeNode).getDirection() != Direction.BOTH)) {
return;
}
String orderLabel = orderGlobalTreeNode.enableOrderFlag(labelManager);
SelectOneTreeNode selectOneTreeNode = new SelectOneTreeNode(new SourceDelegateNode(inputUnaryTreeNode, schema), orderLabel, Pop.last, Lists.newArrayList(), schema);
selectOneTreeNode.setConstantValueType(new ValueValueType(Message.VariantType.VT_INT));
OrderGlobalTreeNode addOrderTreeNode = new OrderGlobalTreeNode(inputUnaryTreeNode, schema, Lists.newArrayList(Pair.of(selectOneTreeNode, Order.asc)));
UnaryTreeNode.class.cast(aggTreeNode).setInputNode(addOrderTreeNode);
}
} else {
if (treeLeaf instanceof OrderGlobalTreeNode) {
return;
}
TreeNode currTreeNode = orderTreeNode.getOutputNode();
boolean hasSimpleShuffle = false;
while (currTreeNode != null) {
if (currTreeNode.getNodeType() == NodeType.FLATMAP || (currTreeNode instanceof PropertyNode && !(UnaryTreeNode.class.cast(currTreeNode).getInputNode().getOutputValueType() instanceof EdgeValueType))) {
hasSimpleShuffle = true;
break;
}
currTreeNode = currTreeNode.getOutputNode();
}
if (!hasSimpleShuffle) {
return;
}
UnaryTreeNode outputTreeNode = UnaryTreeNode.class.cast(treeLeaf);
if (outputTreeNode.getInputNode() == orderTreeNode) {
if (outputTreeNode instanceof EdgeVertexTreeNode && EdgeVertexTreeNode.class.cast(outputTreeNode).getDirection() != Direction.BOTH) {
return;
}
if (orderTreeNode.getOutputValueType() instanceof EdgeValueType && outputTreeNode instanceof PropertyNode) {
return;
}
}
String orderLabel = orderGlobalTreeNode.enableOrderFlag(labelManager);
SelectOneTreeNode selectOneTreeNode = new SelectOneTreeNode(new SourceDelegateNode(treeLeaf, schema), orderLabel, Pop.last, Lists.newArrayList(), schema);
selectOneTreeNode.setConstantValueType(new ValueValueType(Message.VariantType.VT_INT));
treeLeaf = new OrderGlobalTreeNode(treeLeaf, schema, Lists.newArrayList(Pair.of(selectOneTreeNode, Order.asc)));
}
}
}
Aggregations