Search in sources :

Example 1 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode in project GraphScope by alibaba.

the class CostEstimate method estimateNetworkCost.

public double estimateNetworkCost(TreeNode node) {
    if (node instanceof FoldTreeNode) {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * NET_FOLD_RATIO;
    } else if (node.getNodeType() == NodeType.AGGREGATE) {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO;
    } else if (node instanceof PropertyNode) {
        PropertyNode propertyNode = (PropertyNode) node;
        Set<String> propNameList = propertyNode.getPropKeyList();
        if (propNameList.size() <= 0) {
            return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * PROP_DEFAULT_COUNT;
        } else {
            return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * propNameList.size();
        }
    } else if (node.getOutputValueType() instanceof VertexValueType) {
        return NET_DEFAULT_COST;
    } else {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO;
    }
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode)

Example 2 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode in project GraphScope by alibaba.

the class TreeNodeUtils method buildFilterTreeNode.

/**
 * Build logical plan with filter tree node and output the input value
 */
public static LogicalVertex buildFilterTreeNode(TreeNode treeNode, ContextManager contextManager, LogicalQueryPlan logicalQueryPlan, LogicalVertex sourceVertex, GraphSchema schema) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    TreeNode filterTreeNode = TreeNodeUtils.optimizeSubFilterNode(treeNode);
    UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(filterTreeNode);
    LogicalVertex outputVertex;
    if (unaryTreeNode.getInputNode() instanceof SourceTreeNode && (unaryTreeNode instanceof SelectOneTreeNode || unaryTreeNode instanceof PropertyNode)) {
        // optimize traversal filter to filter operator
        int propId;
        if (unaryTreeNode instanceof SelectOneTreeNode) {
            propId = labelManager.getLabelIndex(SelectOneTreeNode.class.cast(unaryTreeNode).getSelectLabel());
        } else {
            propId = SchemaUtils.getPropId(PropertyNode.class.cast(unaryTreeNode).getPropKeyList().iterator().next(), schema);
        }
        Message.LogicalCompare logicalCompare = Message.LogicalCompare.newBuilder().setCompare(Message.CompareType.EXIST).setPropId(propId).build();
        ProcessorFilterFunction processorFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.HAS);
        if (propId < 0) {
            processorFunction.getUsedLabelList().add(propId);
        }
        processorFunction.getLogicalCompareList().add(logicalCompare);
        outputVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, sourceVertex);
        logicalQueryPlan.addLogicalVertex(outputVertex);
        logicalQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentFilterTreeNode = TreeNodeUtils.buildSingleOutputNode(filterTreeNode, schema);
        // build filter plan, and use join direct filter vertex to filter left stream
        LogicalSubQueryPlan filterPlan = TreeNodeUtils.buildSubQueryPlan(currentFilterTreeNode, sourceVertex, contextManager);
        TreeNode filterSourceNode = TreeNodeUtils.getSourceTreeNode(currentFilterTreeNode);
        sourceVertex = filterSourceNode.getOutputVertex();
        LogicalVertex rightVertex = filterPlan.getOutputVertex();
        logicalQueryPlan.mergeLogicalQueryPlan(filterPlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentFilterTreeNode)) {
            LogicalBinaryVertex filterJoinVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_DIRECT_FILTER), false, sourceVertex, rightVertex);
            logicalQueryPlan.addLogicalVertex(filterJoinVertex);
            logicalQueryPlan.addLogicalEdge(sourceVertex, filterJoinVertex, new LogicalEdge());
            logicalQueryPlan.addLogicalEdge(rightVertex, filterJoinVertex, new LogicalEdge());
            outputVertex = filterJoinVertex;
        } else if (TreeNodeUtils.checkSelectFlag(currentFilterTreeNode)) {
            String inputLabel = labelManager.createSysLabelStart(sourceVertex, "input");
            ProcessorFunction selectFunction = createSelectOneFunction(inputLabel, Pop.last, labelManager.getLabelIndexList());
            LogicalUnaryVertex selectVertex = new LogicalUnaryVertex(vertexIdManager.getId(), selectFunction, false, rightVertex);
            logicalQueryPlan.addLogicalVertex(selectVertex);
            logicalQueryPlan.addLogicalEdge(rightVertex, selectVertex, new LogicalEdge());
            outputVertex = logicalQueryPlan.getOutputVertex();
        } else {
            outputVertex = logicalQueryPlan.getOutputVertex();
        }
    }
    return outputVertex;
}
Also used : TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Message(com.alibaba.maxgraph.Message) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexTreeNode(com.alibaba.maxgraph.compiler.tree.VertexTreeNode) MaxTreeNode(com.alibaba.maxgraph.compiler.tree.MaxTreeNode) RangeGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode) TreeNode(com.alibaba.maxgraph.compiler.tree.TreeNode) TokenTreeNode(com.alibaba.maxgraph.compiler.tree.TokenTreeNode) MinTreeNode(com.alibaba.maxgraph.compiler.tree.MinTreeNode) CountGlobalTreeNode(com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode) HasTreeNode(com.alibaba.maxgraph.compiler.tree.HasTreeNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) PropertyMapTreeNode(com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode) SumTreeNode(com.alibaba.maxgraph.compiler.tree.SumTreeNode) UnaryTreeNode(com.alibaba.maxgraph.compiler.tree.UnaryTreeNode) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SelectOneTreeNode(com.alibaba.maxgraph.compiler.tree.SelectOneTreeNode) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 3 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode in project GraphScope by alibaba.

the class BranchTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    int optionLabelId = 0;
    boolean optionJoinFlag = true;
    UnaryTreeNode branchUnaryNode = UnaryTreeNode.class.cast(branchTreeNode);
    if (branchUnaryNode.getInputNode() instanceof SourceTreeNode) {
        if (branchUnaryNode instanceof PropertyNode) {
            String prop = PropertyNode.class.cast(branchUnaryNode).getPropKeyList().iterator().next();
            optionLabelId = SchemaUtils.getPropId(prop, schema);
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof SelectOneTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(SelectOneTreeNode.class.cast(branchUnaryNode).getSelectLabel());
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof TokenTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(TokenTreeNode.class.cast(branchUnaryNode).getToken().getAccessor());
            optionJoinFlag = false;
        }
    }
    if (optionJoinFlag) {
        // join the value stream to get value and set it to label
        if (branchUnaryNode instanceof JoinZeroNode) {
            ((JoinZeroNode) branchUnaryNode).disableJoinZero();
        }
        TreeNode currentBranchTreeNode = TreeNodeUtils.buildSingleOutputNode(branchTreeNode, schema);
        LogicalQueryPlan branchValuePlan = TreeNodeUtils.buildSubQueryPlan(currentBranchTreeNode, sourceVertex, contextManager);
        TreeNode branchSourceNode = TreeNodeUtils.getSourceTreeNode(currentBranchTreeNode);
        sourceVertex = branchSourceNode.getOutputVertex();
        LogicalVertex branchValueVertex = branchValuePlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(branchValuePlan);
        String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
        optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
        QueryFlowOuterClass.OperatorType joinOperatorType = CompilerUtils.parseJoinOperatorType(branchTreeNode);
        ProcessorFunction joinFunction = new ProcessorFunction(joinOperatorType, Message.Value.newBuilder().setIntValue(optionLabelId));
        LogicalBinaryVertex joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinFunction, false, sourceVertex, branchValueVertex);
        logicalSubQueryPlan.addLogicalVertex(joinVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(branchValueVertex, joinVertex, new LogicalEdge());
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    if (optionLabelId > 0) {
        ProcessorFunction fillFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addIntValueList(optionLabelId));
        LogicalVertex fillPropVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), fillFunction, true, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(fillPropVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, fillPropVertex, outputVertex.isPropLocalFlag() ? new LogicalEdge(EdgeShuffleType.FORWARD) : new LogicalEdge());
        outputVertex = fillPropVertex;
    }
    Map<Object, Message.LogicalCompare> pickCompareList = Maps.newHashMap();
    List<Message.LogicalCompare> noneCompareList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> pickEntry : optionPickList.entrySet()) {
        Object pick = pickEntry.getKey();
        Object pickValue = pick;
        if (optionLabelId == TreeConstants.LABEL_INDEX) {
            final String pickString = pick.toString();
            pickValue = schema.getElement(pickString).getLabelId();
        } else if (optionLabelId == TreeConstants.ID_INDEX) {
            pickValue = Long.parseLong(pick.toString());
        }
        Message.VariantType variantType = CompilerUtils.parseVariantType(pickValue.getClass(), pickValue);
        Message.Value.Builder valueBuilder = Message.Value.newBuilder().setValueType(variantType);
        switch(variantType) {
            case VT_INT:
                {
                    if (pickValue instanceof Integer) {
                        valueBuilder.setIntValue((Integer) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setIntValue((int) number);
                    }
                    break;
                }
            case VT_LONG:
                {
                    if (pickValue instanceof Long) {
                        valueBuilder.setLongValue((Long) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setLongValue((long) number);
                    }
                    break;
                }
            case VT_STRING:
                {
                    valueBuilder.setStrValue((String) pickValue).build();
                    break;
                }
            default:
                {
                    throw new UnsupportedOperationException(pickValue + " for branch option operator");
                }
        }
        Message.Value value = valueBuilder.build();
        pickCompareList.put(pick, Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.EQ).setValue(value).setType(variantType).build());
        noneCompareList.add(Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.NEQ).setValue(value).setType(variantType).build());
    }
    List<LogicalVertex> unionVertexList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> optionEntry : this.optionPickList.entrySet()) {
        List<TreeNode> optionTreeNodeList = optionEntry.getValue();
        Message.LogicalCompare logicalCompare = checkNotNull(pickCompareList.get(optionEntry.getKey()));
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().add(logicalCompare);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        for (TreeNode treeNode : optionTreeNodeList) {
            LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(treeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
            unionVertexList.add(subQueryPlan.getOutputVertex());
            logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
        }
    }
    if (null != noneTreeNode) {
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().addAll(noneCompareList);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(noneTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    if (null != anyTreeNode) {
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(anyTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), outputVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    LogicalVertex currentUnionVertex = unionVertexList.remove(0);
    for (LogicalVertex logicalVertex : unionVertexList) {
        LogicalVertex unionVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, currentUnionVertex, logicalVertex);
        logicalSubQueryPlan.addLogicalVertex(unionVertex);
        logicalSubQueryPlan.addLogicalEdge(currentUnionVertex, unionVertex, LogicalEdge.forwardEdge());
        logicalSubQueryPlan.addLogicalEdge(logicalVertex, unionVertex, LogicalEdge.forwardEdge());
        currentUnionVertex = unionVertex;
    }
    addUsedLabelAndRequirement(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) Message(com.alibaba.maxgraph.Message) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) List(java.util.List) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) Map(java.util.Map)

Example 4 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode in project GraphScope by alibaba.

the class TreeBuilder method visitVertexByModulatingStep.

private TreeNode visitVertexByModulatingStep(VertexByModulatingStep step, TreeNode prev) {
    checkNotNull(prev);
    Direction direction = step.getDirection();
    String[] edgeLabels = step.getEdgeLabels();
    SampleGlobalStep sampleGlobalStep = step.getSampleGlobalStep();
    SampleNode sampleNode;
    if (step.returnsVertex()) {
        sampleNode = new VertexTreeNode(prev, direction, edgeLabels, schema);
    } else {
        sampleNode = new EdgeTreeNode(prev, direction, edgeLabels, schema);
    }
    if (null != sampleGlobalStep) {
        int amountToSample = ReflectionUtils.getFieldValue(SampleGlobalStep.class, sampleGlobalStep, "amountToSample");
        Traversal.Admin<?, ?> probabilityTraversal = ReflectionUtils.getFieldValue(SampleGlobalStep.class, sampleGlobalStep, "probabilityTraversal");
        boolean saveFlag = rootPathFlag;
        rootPathFlag = false;
        String probabilityProperty = null;
        TreeNode probabilityTreeNode = travelTraversalAdmin(probabilityTraversal, new SourceDelegateNode((TreeNode) sampleNode, schema));
        if (probabilityTreeNode instanceof SourceTreeNode) {
            probabilityProperty = "";
        } else if ((UnaryTreeNode.class.cast(probabilityTreeNode).getInputNode() instanceof SourceTreeNode && (probabilityTreeNode instanceof PropertyNode))) {
            probabilityProperty = PropertyNode.class.cast(probabilityTreeNode).getPropKeyList().iterator().next();
        } else {
            throw new IllegalArgumentException("Only support sample by property here.");
        }
        rootPathFlag = saveFlag;
        sampleNode.setSample(amountToSample, probabilityProperty);
    }
    return (TreeNode) sampleNode;
}
Also used : SampleGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) 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) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) 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) SampleNode(com.alibaba.maxgraph.compiler.tree.addition.SampleNode)

Example 5 with PropertyNode

use of com.alibaba.maxgraph.compiler.tree.addition.PropertyNode 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)

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