Search in sources :

Example 6 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode 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)));
        }
    }
}
Also used : SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) EdgeValueType(com.alibaba.maxgraph.compiler.tree.value.EdgeValueType) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType)

Aggregations

PropertyNode (com.alibaba.maxgraph.compiler.tree.addition.PropertyNode)6 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)5 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)3 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)3 Message (com.alibaba.maxgraph.Message)2 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)2 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)2 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)2 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)2 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)2 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)2 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)2 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)2 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)2 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)2 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)2 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)2 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)1