Search in sources :

Example 26 with SourceDelegateNode

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

the class GroupCountTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex outputVertex;
    if (null == keyTreeNode || keyTreeNode instanceof SourceDelegateNode) {
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT);
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, sourceVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        if (currentKeyNode instanceof JoinZeroNode) {
            ((JoinZeroNode) currentKeyNode).disableJoinZero();
        }
        LogicalSubQueryPlan keyValuePlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager);
        LogicalVertex groupValueVertex = keyValuePlan.getOutputVertex();
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentKeyNode).getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyValuePlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentKeyNode)) {
            String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
            getUsedLabelList().add(valueLabel);
            int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
            LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(CompilerUtils.parseJoinOperatorType(currentKeyNode), Message.Value.newBuilder().setIntValue(valueLabelId)), false, enterKeyVertex, groupValueVertex);
            logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(groupValueVertex, logicalBinaryVertex, new LogicalEdge());
            ProcessorFunction selectValueFunction = TreeNodeUtils.createSelectOneFunction(valueLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectLabelVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectValueFunction, false, logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalVertex(selectLabelVertex);
            logicalSubQueryPlan.addLogicalEdge(logicalBinaryVertex, selectLabelVertex, LogicalEdge.forwardEdge());
        }
        groupValueVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT, Message.Value.newBuilder());
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, groupValueVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(groupValueVertex, outputVertex, new LogicalEdge());
    }
    ProcessorFunction foldMapFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.FOLDMAP);
    LogicalVertex foldMapVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), foldMapFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(foldMapVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, foldMapVertex, new LogicalEdge());
    addUsedLabelAndRequirement(foldMapVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(foldMapVertex, contextManager.getTreeNodeLabelManager());
    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) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 27 with SourceDelegateNode

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

the class TreeBuilder method visitChooseStep.

private TreeNode visitChooseStep(ChooseStep step, TreeNode prev) {
    List<org.javatuples.Pair<Traversal.Admin, Traversal.Admin<?, ?>>> traversalOptions = ReflectionUtils.getFieldValue(BranchStep.class, step, "traversalOptions");
    Traversal.Admin<?, ?> trueOptionTraversal, falseOptionTraversal;
    if (traversalOptions.size() == 2 && (trueOptionTraversal = getTraversalOption(true, traversalOptions)) != null && (falseOptionTraversal = getTraversalOption(false, traversalOptions)) != null) {
        boolean saveFlag = this.rootPathFlag;
        this.rootPathFlag = false;
        Traversal.Admin<?, ?> branchTraversal = ReflectionUtils.getFieldValue(BranchStep.class, step, "branchTraversal");
        TreeNode branchNode = branchTraversal == null ? null : travelTraversalAdmin(branchTraversal, new SourceDelegateNode(prev, schema));
        this.rootPathFlag = saveFlag;
        TreeNode trueOptionNode = travelTraversalAdmin(trueOptionTraversal, new SourceDelegateNode(prev, schema));
        TreeNode falseOptionNode = travelTraversalAdmin(falseOptionTraversal, new SourceDelegateNode(prev, schema));
        return new OptionalTreeNode(prev, schema, branchNode, trueOptionNode, falseOptionNode);
    } else {
        throw new UnsupportedOperationException("Not support choose yet.");
    }
}
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) Pair(org.apache.commons.lang3.tuple.Pair)

Example 28 with SourceDelegateNode

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

the class TreeBuilder method visitNotStep.

private TreeNode visitNotStep(NotStep step, TreeNode prev) {
    Traversal.Admin<?, ?> notTraversal = ReflectionUtils.getFieldValue(NotStep.class, step, "notTraversal");
    TreeNode notTreeNode;
    boolean saveFlag = rootPathFlag;
    rootPathFlag = false;
    notTreeNode = travelTraversalAdmin(notTraversal, new SourceDelegateNode(prev, schema));
    rootPathFlag = saveFlag;
    return new NotTreeNode(prev, schema, notTreeNode);
}
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 29 with SourceDelegateNode

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

the class TreeBuilder method visitWherePredicateStep.

private TreeNode visitWherePredicateStep(WherePredicateStep step, TreeNode prev) {
    Optional<String> startKeyOptional = step.getStartKey();
    Optional<P<?>> predicateOptional = step.getPredicate();
    List<String> selectKeys = ReflectionUtils.getFieldValue(WherePredicateStep.class, step, "selectKeys");
    List<Traversal.Admin<?, ?>> ringTraversalList = step.getLocalChildren();
    String sourceKey = startKeyOptional.isPresent() ? startKeyOptional.get() : null;
    String targetKey = selectKeys.iterator().next();
    WherePredicateTreeNode wherePredicateTreeNode = new WherePredicateTreeNode(prev, schema, predicateOptional.get(), sourceKey, ringTraversalList.isEmpty());
    boolean saveFlag = rootPathFlag;
    rootPathFlag = false;
    if (!ringTraversalList.isEmpty()) {
        Traversal.Admin<?, ?> sourceAdmin = ringTraversalList.get(0);
        Traversal.Admin<?, ?> targetAdmin = ringTraversalList.get(1 % ringTraversalList.size());
        TreeNode sourceNode = travelTraversalAdmin(sourceAdmin, null == sourceKey ? new SourceDelegateNode(prev, schema) : new SelectOneTreeNode(new SourceDelegateNode(prev, schema), sourceKey, Pop.last, treeNodeLabelManager.getTreeNodeList(sourceKey), schema));
        TreeNode targetNode = travelTraversalAdmin(targetAdmin, new SelectOneTreeNode(new SourceDelegateNode(prev, schema), targetKey, Pop.last, treeNodeLabelManager.getTreeNodeList(targetKey), schema));
        wherePredicateTreeNode.setSourceTargetNode(sourceNode, targetNode);
    }
    rootPathFlag = saveFlag;
    return wherePredicateTreeNode;
}
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) P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) 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)

Example 30 with SourceDelegateNode

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

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