Search in sources :

Example 31 with SourceDelegateNode

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);
}
Also used : SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Example 32 with SourceDelegateNode

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);
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Example 33 with SourceDelegateNode

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;
}
Also used : PageRankStep(com.alibaba.maxgraph.tinkerpop.steps.PageRankStep) WherePredicateStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep) SampleGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep) DedupGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep) Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) StringUtils(org.apache.commons.lang3.StringUtils) ShortestPathVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ShortestPathVertexProgramStep) OrStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep) ShortestPathStep(com.alibaba.maxgraph.tinkerpop.steps.ShortestPathStep) ProfileStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.ProfileStrategy) Pair(org.apache.commons.lang3.tuple.Pair) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) OutputVineyardStep(com.alibaba.maxgraph.tinkerpop.steps.OutputVineyardStep) PeerPressureVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PeerPressureVertexProgramStep) LambdaFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.LambdaFilterStep) org.apache.tinkerpop.gremlin.process.traversal.step.map(org.apache.tinkerpop.gremlin.process.traversal.step.map) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) VertexRatioProgram(com.alibaba.maxgraph.sdkcommon.compiler.custom.program.VertexRatioProgram) ReflectionUtils(com.alibaba.maxgraph.compiler.utils.ReflectionUtils) RegexPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.RegexPredicate) Message(com.alibaba.maxgraph.Message) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep) CountFlagNode(com.alibaba.maxgraph.compiler.tree.addition.CountFlagNode) ListKeyPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.ListKeyPredicate) LabelPropagationStep(com.alibaba.maxgraph.tinkerpop.steps.LabelPropagationStep) SideEffectCapStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectCapStep) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) java.util(java.util) CustomVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.CustomVertexProgramStep) MxGraphStepStrategy(com.alibaba.maxgraph.tinkerpop.strategies.MxGraphStepStrategy) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) AdjacentToIncidentStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.AdjacentToIncidentStrategy) StringKeyPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.StringKeyPredicate) AllPathStep(com.alibaba.maxgraph.tinkerpop.steps.AllPathStep) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) Supplier(java.util.function.Supplier) VertexProgram(org.apache.tinkerpop.gremlin.process.computer.VertexProgram) CustomPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.CustomPredicate) Lists(com.google.common.collect.Lists) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) ConnectedComponentVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ConnectedComponentVertexProgramStep) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) TraversalRing(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalRing) LpaVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.LpaVertexProgramStep) ComputerAwareStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) PropertyType(org.apache.tinkerpop.gremlin.structure.PropertyType) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) CustomCaseWhenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomCaseWhenFunction) StandardVerificationStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.StandardVerificationStrategy) CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) T(org.apache.tinkerpop.gremlin.structure.T) OptimizeConfig(com.alibaba.maxgraph.compiler.optimizer.OptimizeConfig) Direction(org.apache.tinkerpop.gremlin.structure.Direction) IncidentToAdjacentStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.IncidentToAdjacentStrategy) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) SchemaUtils(com.alibaba.maxgraph.sdkcommon.util.SchemaUtils) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) ListPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.ListPredicate) HitsVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.HitsVertexProgramStep) Pop(org.apache.tinkerpop.gremlin.process.traversal.Pop) LoggerFactory(org.slf4j.LoggerFactory) CreateGraphStep(com.alibaba.maxgraph.tinkerpop.steps.CreateGraphStep) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RangeSumFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction) AggregateLocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateLocalStep) ConnectedComponentsStep(com.alibaba.maxgraph.tinkerpop.steps.ConnectedComponentsStep) org.apache.tinkerpop.gremlin.process.traversal.lambda(org.apache.tinkerpop.gremlin.process.traversal.lambda) RepeatUnrollStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.RepeatUnrollStrategy) EstimateCountStep(com.alibaba.maxgraph.tinkerpop.steps.EstimateCountStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) CompilerUtils(com.alibaba.maxgraph.compiler.utils.CompilerUtils) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) Predicate(java.util.function.Predicate) AndStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep) LazyBarrierStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy) MapPropFillFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) MaxGraphFilterRankingStrategy(com.alibaba.maxgraph.compiler.strategy.traversal.MaxGraphFilterRankingStrategy) HitsStep(com.alibaba.maxgraph.tinkerpop.steps.HitsStep) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) EdgeVertexWithByStep(com.alibaba.maxgraph.tinkerpop.steps.EdgeVertexWithByStep) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) CustomWhenThenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomWhenThenFunction) NotImplementedException(org.apache.commons.lang3.NotImplementedException) VertexByModulatingStep(com.alibaba.maxgraph.tinkerpop.steps.VertexByModulatingStep) MaxGraphStep(com.alibaba.maxgraph.tinkerpop.steps.MaxGraphStep) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) PredicateType(com.alibaba.maxgraph.sdkcommon.compiler.custom.PredicateType) TreeNodeUtils(com.alibaba.maxgraph.compiler.utils.TreeNodeUtils) DataType(com.alibaba.maxgraph.compiler.api.schema.DataType) VertexWithByStep(com.alibaba.maxgraph.tinkerpop.steps.VertexWithByStep) PathFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.PathFilterStep) Function(java.util.function.Function) FilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep) BiPredicate(java.util.function.BiPredicate) ChooseStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) MapConfiguration(org.apache.commons.configuration2.MapConfiguration) SampleNode(com.alibaba.maxgraph.compiler.tree.addition.SampleNode) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) RegexKeyPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.RegexKeyPredicate) Logger(org.slf4j.Logger) NotStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep) FilterRankingStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.FilterRankingStrategy) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) ConnectiveStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.ConnectiveStep) TraversalVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.TraversalVertexProgramStep) Maps(com.google.common.collect.Maps) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) PageRankVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) StringPredicate(com.alibaba.maxgraph.sdkcommon.compiler.custom.StringPredicate) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) SubgraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphStep) OutputStep(com.alibaba.maxgraph.tinkerpop.steps.OutputStep) TraversalOptionParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalOptionParent) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) BranchStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchStep) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) Pop(org.apache.tinkerpop.gremlin.process.traversal.Pop)

Example 34 with SourceDelegateNode

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;
    }
}
Also used : SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode)

Example 35 with SourceDelegateNode

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)));
        }
    }
}
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

SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)38 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)27 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)21 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)20 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)20 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)20 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)17 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)17 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)17 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)11 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)11 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)10 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)10 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)9 Pair (org.apache.commons.lang3.tuple.Pair)7 ValueType (com.alibaba.maxgraph.compiler.tree.value.ValueType)5 ValueValueType (com.alibaba.maxgraph.compiler.tree.value.ValueValueType)5 VertexValueType (com.alibaba.maxgraph.compiler.tree.value.VertexValueType)5 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)4 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)4