use of com.alibaba.maxgraph.compiler.tree.value.EdgeValueType 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