Search in sources :

Example 16 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class TreeBuilder method visitFlatMapStep.

private TreeNode visitFlatMapStep(TraversalFlatMapStep step, TreeNode prev) {
    Traversal.Admin<?, ?> flatMapTraversal = ReflectionUtils.getFieldValue(TraversalFlatMapStep.class, step, "flatMapTraversal");
    boolean saveFlag = rootPathFlag;
    rootPathFlag = false;
    TreeNode flatMapNode = travelTraversalAdmin(flatMapTraversal, new SourceDelegateNode(prev, schema));
    rootPathFlag = saveFlag;
    return new TraversalFlatMapTreeNode(prev, schema, flatMapNode);
}
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) 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)

Example 17 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class TreeBuilder method visitRepeatStep.

private TreeNode visitRepeatStep(RepeatStep step, TreeNode prev) {
    Traversal.Admin<?, ?> repeatTraversal = ReflectionUtils.getFieldValue(RepeatStep.class, step, "repeatTraversal");
    Traversal.Admin<?, ?> untilTraversal = ReflectionUtils.getFieldValue(RepeatStep.class, step, "untilTraversal");
    Traversal.Admin<?, ?> emitTraversal = ReflectionUtils.getFieldValue(RepeatStep.class, step, "emitTraversal");
    String repeatTraversalString = repeatTraversal.toString();
    String untilTraversalString = untilTraversal == null ? "" : untilTraversal.toString();
    String emitTraversalString = emitTraversal == null ? "" : emitTraversal.toString();
    if (StringUtils.contains(repeatTraversalString, "RepeatStep") || StringUtils.contains(untilTraversalString, "RepeatStep") || StringUtils.contains(emitTraversalString, "RepeatStep")) {
        throw new UnsupportedOperationException("Not support nest repeat");
    }
    boolean untilFirst = ReflectionUtils.getFieldValue(RepeatStep.class, step, "untilFirst");
    boolean emitFirst = ReflectionUtils.getFieldValue(RepeatStep.class, step, "emitFirst");
    RepeatTreeNode repeatTreeNode = new RepeatTreeNode(prev, schema, this.queryConfig);
    SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(prev, schema);
    sourceDelegateNode.enableRepeatFlag();
    repeatTreeNode.setRepeatBodyTreeNode(travelTraversalAdmin(repeatTraversal, sourceDelegateNode));
    boolean saveFlag = rootPathFlag;
    this.rootPathFlag = false;
    if (null != untilTraversal) {
        if (untilTraversal instanceof LoopTraversal) {
            repeatTreeNode.setMaxLoopTimes(LoopTraversal.class.cast(untilTraversal).getMaxLoops());
        } else {
            if (untilFirst) {
                repeatTreeNode.setUntilFirstTreeNode(travelTraversalAdmin(untilTraversal, new SourceDelegateNode(prev, schema)));
            }
            Step finalEndStep = untilTraversal.getEndStep();
            if (finalEndStep instanceof OrStep) {
                OrStep orStep = OrStep.class.cast(finalEndStep);
                List<Traversal.Admin<?, ?>> traversals = ReflectionUtils.getFieldValue(ConnectiveStep.class, orStep, "traversals");
                checkArgument(traversals.size() == 2, "Only support two condition in until yet");
                Traversal.Admin<?, ?> firstTraversal = traversals.get(0);
                Traversal.Admin<?, ?> secondTraversal = traversals.get(1);
                Traversal.Admin<?, ?> loopTraversal;
                if (firstTraversal.getSteps().get(0) instanceof LoopsStep && !(secondTraversal.getSteps().get(0) instanceof LoopsStep)) {
                    repeatTreeNode.setUntilTreeNode(travelTraversalAdmin(secondTraversal, new SourceDelegateNode(prev, schema)));
                    loopTraversal = firstTraversal;
                } else if (secondTraversal.getSteps().get(0) instanceof LoopsStep && !(firstTraversal.getSteps().get(0) instanceof LoopsStep)) {
                    repeatTreeNode.setUntilTreeNode(travelTraversalAdmin(firstTraversal, new SourceDelegateNode(prev, schema)));
                    loopTraversal = secondTraversal;
                } else {
                    throw new UnsupportedOperationException("There's no looop condition in until");
                }
                List<Step> loopStepList = loopTraversal.getSteps();
                checkArgument(loopStepList.size() == 2 && loopStepList.get(1) instanceof IsStep, "Only support loops().is(gt(loop count)) yet.");
                IsStep isStep = (IsStep) loopStepList.get(1);
                P predicate = isStep.getPredicate();
                BiPredicate biPredicate = predicate.getBiPredicate();
                checkArgument(biPredicate == Compare.gt || biPredicate == Compare.gte || biPredicate == Compare.eq, "Only support loops().is(gt/eq/gte(loop count)) yet.");
                long loopCount = Long.parseLong(predicate.getValue().toString());
                if (biPredicate == Compare.gt) {
                    loopCount += 1;
                }
                checkArgument(loopCount > 0, "Invalid loop count must > 0");
                repeatTreeNode.setMaxLoopTimes(loopCount);
            } else if (finalEndStep instanceof AndStep) {
                throw new IllegalArgumentException("Not support and operator in until yet.");
            } else {
                repeatTreeNode.setUntilTreeNode(travelTraversalAdmin(untilTraversal, new SourceDelegateNode(prev, schema)));
            }
        }
    }
    if (null != emitTraversal) {
        if (emitFirst) {
            repeatTreeNode.setEmitFirstTreeNode(travelTraversalAdmin(emitTraversal, new SourceDelegateNode(prev, schema)));
        }
        repeatTreeNode.setEmitTreeNode(travelTraversalAdmin(emitTraversal, new SourceDelegateNode(prev, schema)));
    }
    rootPathFlag = saveFlag;
    return repeatTreeNode;
}
Also used : 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) 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) 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) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep) 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) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep) LabelPropagationStep(com.alibaba.maxgraph.tinkerpop.steps.LabelPropagationStep) SideEffectCapStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectCapStep) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) CustomVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.CustomVertexProgramStep) AllPathStep(com.alibaba.maxgraph.tinkerpop.steps.AllPathStep) ConnectedComponentVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ConnectedComponentVertexProgramStep) LpaVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.LpaVertexProgramStep) ComputerAwareStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) HitsVertexProgramStep(com.alibaba.maxgraph.tinkerpop.steps.HitsVertexProgramStep) CreateGraphStep(com.alibaba.maxgraph.tinkerpop.steps.CreateGraphStep) AggregateLocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.AggregateLocalStep) ConnectedComponentsStep(com.alibaba.maxgraph.tinkerpop.steps.ConnectedComponentsStep) EstimateCountStep(com.alibaba.maxgraph.tinkerpop.steps.EstimateCountStep) AndStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep) HitsStep(com.alibaba.maxgraph.tinkerpop.steps.HitsStep) EdgeVertexWithByStep(com.alibaba.maxgraph.tinkerpop.steps.EdgeVertexWithByStep) VertexByModulatingStep(com.alibaba.maxgraph.tinkerpop.steps.VertexByModulatingStep) MaxGraphStep(com.alibaba.maxgraph.tinkerpop.steps.MaxGraphStep) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) VertexWithByStep(com.alibaba.maxgraph.tinkerpop.steps.VertexWithByStep) PathFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.PathFilterStep) FilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep) ChooseStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseStep) NotStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep) 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) PageRankVertexProgramStep(org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) 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) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) BranchStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) AndStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep) OrStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep) BiPredicate(java.util.function.BiPredicate)

Example 18 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class TreeBuilder method visitOrderGlobalStep.

private TreeNode visitOrderGlobalStep(OrderGlobalStep step, TreeNode prev) {
    List<org.javatuples.Pair<Traversal.Admin<?, ?>, Comparator<?>>> comparatorList = step.getComparators();
    List<Pair<TreeNode, Order>> treeNodeOrderList = Lists.newArrayList();
    boolean saveFlag = rootPathFlag;
    rootPathFlag = false;
    SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(prev, schema);
    comparatorList.forEach(v -> treeNodeOrderList.add(Pair.of(travelTraversalAdmin(v.getValue0(), sourceDelegateNode), Order.class.cast(v.getValue1()))));
    rootPathFlag = saveFlag;
    return new OrderGlobalTreeNode(prev, schema, treeNodeOrderList);
}
Also used : Order(org.apache.tinkerpop.gremlin.process.traversal.Order) 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) Pair(org.apache.commons.lang3.tuple.Pair)

Example 19 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class TreeBuilder method visitDedupGlobalStep.

private TreeNode visitDedupGlobalStep(DedupGlobalStep step, TreeNode prev) {
    Set<String> dedupLabelList = step.getScopeKeys();
    Traversal.Admin<?, ?> dedupTraversal = step.getLocalChildren().isEmpty() ? null : (Traversal.Admin<?, ?>) step.getLocalChildren().get(0);
    DedupGlobalTreeNode dedupGlobalTreeNode = new DedupGlobalTreeNode(prev, schema, dedupLabelList);
    if (null != dedupTraversal) {
        boolean saveFlag = rootPathFlag;
        rootPathFlag = false;
        dedupGlobalTreeNode.setDedupTreeNode(travelTraversalAdmin(dedupTraversal, new SourceDelegateNode(dedupGlobalTreeNode, schema)));
        rootPathFlag = saveFlag;
    }
    List<TreeNode> treeNodeList = Lists.reverse(TreeNodeUtils.buildTreeNodeListFromLeaf(dedupGlobalTreeNode));
    TreeNode sourceTreeNode = treeNodeList.get(treeNodeList.size() - 1);
    boolean subQueryNodeFlag = sourceTreeNode instanceof SourceDelegateNode;
    for (TreeNode treeNode : treeNodeList) {
        if (subQueryNodeFlag) {
            treeNode.setSubqueryNode();
        }
        treeNode.enableDedupLocal();
        if (treeNode instanceof SelectTreeNode || treeNode instanceof SelectOneTreeNode || (treeNode instanceof WherePredicateTreeNode && !treeNodeLabelManager.getLabelIndexList().containsKey(((WherePredicateTreeNode) treeNode).getStartKey()))) {
            break;
        }
    }
    return dedupGlobalTreeNode;
}
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) 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)

Example 20 with SourceDelegateNode

use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.

the class TreeNodeUtils method buildSubQueryPlanWithKey.

/**
 * @param treeNode The given tree node
 * @param sourceVertex The source vertex
 * @param treeNodeLabelManager The given label manager
 * @param contextManager The context manager
 * @param vertexIdManager The vertex id manager
 * @return The sub query with enter key vertex
 */
public static LogicalSubQueryPlan buildSubQueryPlanWithKey(TreeNode treeNode, LogicalVertex sourceVertex, TreeNodeLabelManager treeNodeLabelManager, ContextManager contextManager, VertexIdManager vertexIdManager) {
    List<TreeNode> treeNodeList = buildTreeNodeListFromLeaf(treeNode);
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex currentSourceVertex = sourceVertex;
    for (TreeNode currentNode : treeNodeList) {
        if (currentNode instanceof AbstractUseKeyNode) {
            ((AbstractUseKeyNode) currentNode).enableUseKeyFlag(currentSourceVertex);
        }
        if (currentNode instanceof SourceDelegateNode) {
            LogicalVertex enterKeyVertex = new LogicalUnaryVertex(vertexIdManager.getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).setUniqFlag(true).build().toByteString())), false, currentSourceVertex);
            currentNode.setFinishVertex(enterKeyVertex, treeNodeLabelManager);
            logicalSubQueryPlan.addLogicalVertex(currentSourceVertex);
            logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(currentSourceVertex, enterKeyVertex, new LogicalEdge());
            currentSourceVertex = enterKeyVertex;
        }
        logicalSubQueryPlan.mergeLogicalQueryPlan(currentNode.buildLogicalQueryPlan(contextManager));
    }
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) 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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode)

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