Search in sources :

Example 26 with LogicalSubQueryPlan

use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.

the class GroupTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    QueryFlowOuterClass.EnterKeyArgumentProto enterKeyArgumentProto = null;
    if (keyTreeNode == null || keyTreeNode instanceof SourceDelegateNode) {
        enterKeyArgumentProto = QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_SELF).build();
    } else if (UnaryTreeNode.class.cast(keyTreeNode).getInputNode() instanceof SourceDelegateNode) {
        Optional<QueryFlowOuterClass.EnterKeyArgumentProto> propLabelId = TreeNodeUtils.parseEnterKeyArgument(keyTreeNode, schema, contextManager.getTreeNodeLabelManager());
        if (propLabelId.isPresent()) {
            enterKeyArgumentProto = propLabelId.get();
        }
    }
    if (null != enterKeyArgumentProto) {
        // use enter key operator to generate key data
        ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(enterKeyArgumentProto.toByteString()));
        LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, sourceVertex);
        enterKeyArgumentProto.getPropIdListList().forEach(v -> {
            if (v < 0) {
                enterKeyFunction.getUsedLabelList().add(v);
            }
        });
        if (enterKeyArgumentProto.getPropLabelId() < 0) {
            enterKeyFunction.getUsedLabelList().add(enterKeyArgumentProto.getPropLabelId());
        }
        logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, enterKeyVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        LogicalSubQueryPlan keyQueryPlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager, true);
        LogicalVertex keyValueVertex = keyQueryPlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyQueryPlan);
        sourceVertex = TreeNodeUtils.getSourceTreeNode(keyTreeNode).getOutputVertex();
        if (sourceVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.ENTER_KEY) {
            ProcessorFunction joinKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.JOIN_RIGHT_VALUE_KEY);
            LogicalBinaryVertex joinKeyVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinKeyFunction, false, sourceVertex, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(joinKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinKeyVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, joinKeyVertex, new LogicalEdge());
        } else {
            String keyValueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(keyValueVertex, "val");
            String sourceLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart(sourceVertex, "source");
            ProcessorFunction selectSourceFunction = TreeNodeUtils.createSelectOneFunction(sourceLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectSourceFunction, false, keyValueVertex);
            logicalSubQueryPlan.addLogicalVertex(selectVertex);
            logicalSubQueryPlan.addLogicalEdge(keyValueVertex, selectVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
            int keyValueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(keyValueLabel);
            ProcessorFunction enterKeyFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ENTER_KEY, Message.Value.newBuilder().setPayload(QueryFlowOuterClass.EnterKeyArgumentProto.newBuilder().setEnterKeyType(QueryFlowOuterClass.EnterKeyTypeProto.KEY_PROP_LABEL).setUniqFlag(false).setPropLabelId(keyValueLabelId).build().toByteString()));
            enterKeyFunction.getUsedLabelList().add(keyValueLabelId);
            LogicalVertex enterKeyVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), enterKeyFunction, false, selectVertex);
            logicalSubQueryPlan.addLogicalVertex(enterKeyVertex);
            logicalSubQueryPlan.addLogicalEdge(selectVertex, enterKeyVertex, new LogicalEdge(EdgeShuffleType.FORWARD));
        }
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalSubQueryPlan aggregateQueryPlan = TreeNodeUtils.buildSubQueryPlan(valueTreeNode, outputVertex, contextManager, false);
    LogicalVertex aggregateVertex = aggregateQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(aggregateQueryPlan);
    // convert by key value to entry
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.BYKEY_ENTRY);
    LogicalVertex bykeyEntryVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, aggregateVertex);
    logicalSubQueryPlan.addLogicalVertex(bykeyEntryVertex);
    logicalSubQueryPlan.addLogicalEdge(aggregateVertex, bykeyEntryVertex, new LogicalEdge());
    outputVertex = logicalSubQueryPlan.getOutputVertex();
    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) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Optional(java.util.Optional) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 27 with LogicalSubQueryPlan

use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.

the class RangeGlobalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    ProcessorFunction combinerFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.COMBINER_RANGE, createArgumentBuilder().addLongValueList(0).addLongValueList(high));
    LogicalUnaryVertex combinerVertex = new LogicalUnaryVertex(vertexIdManager.getId(), combinerFunction, false, sourceVertex);
    combinerVertex.setEarlyStopFlag(super.earlyStopArgument);
    logicalSubQueryPlan.addLogicalVertex(combinerVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, combinerVertex, LogicalEdge.forwardEdge());
    QueryFlowOuterClass.OperatorType operatorType = getUseKeyOperator(QueryFlowOuterClass.OperatorType.RANGE);
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().addLongValueList(low).addLongValueList(high);
    ProcessorFunction processorFunction = new ProcessorFunction(operatorType, argumentBuilder);
    LogicalUnaryVertex rangeVertex = new LogicalUnaryVertex(vertexIdManager.getId(), processorFunction, false, combinerVertex);
    logicalSubQueryPlan.addLogicalVertex(rangeVertex);
    logicalSubQueryPlan.addLogicalEdge(combinerVertex, rangeVertex, new LogicalEdge());
    addUsedLabelAndRequirement(rangeVertex, labelManager);
    setFinishVertex(rangeVertex, labelManager);
    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) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 28 with LogicalSubQueryPlan

use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.

the class SourceDelegateNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalSubQueryPlan.addLogicalVertex(getOutputVertex());
    return logicalSubQueryPlan;
}
Also used : LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 29 with LogicalSubQueryPlan

use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.

the class SourceDfsTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.DFS_SOURCE, Message.Value.newBuilder().setLongValue(batchSize), null);
    return processSourceVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), logicalQueryPlan, processorSourceFunction);
}
Also used : LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 30 with LogicalSubQueryPlan

use of com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan in project GraphScope by alibaba.

the class SourceVertexTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
    processLabelArgument(argumentBuilder, true);
    processIdArgument(argumentBuilder, true);
    Map<String, List<Integer>> primaryKeyLabelIdList = Maps.newHashMap();
    for (GraphVertex vertexType : this.schema.getVertexList()) {
        List<GraphProperty> primaryKeyList = vertexType.getPrimaryKeyList();
        if (null != primaryKeyList && primaryKeyList.size() == 1) {
            String propertyName = primaryKeyList.get(0).getName();
            List<Integer> labelIdList = primaryKeyLabelIdList.computeIfAbsent(propertyName, k -> Lists.newArrayList());
            labelIdList.add(vertexType.getLabelId());
        }
    }
    QueryFlowOuterClass.VertexPrimaryKeyListProto.Builder primaryKeyBuilder = QueryFlowOuterClass.VertexPrimaryKeyListProto.newBuilder();
    for (HasContainer container : this.hasContainerList) {
        String key = container.getKey();
        List<Integer> labelIdList = primaryKeyLabelIdList.get(key);
        if (null != labelIdList) {
            for (Integer labelId : labelIdList) {
                if (container.getBiPredicate() instanceof Compare && container.getBiPredicate() == Compare.eq) {
                    primaryKeyBuilder.addPrimaryKeys(QueryFlowOuterClass.VertexPrimaryKeyProto.newBuilder().setLabelId(labelId).setPrimaryKeyValue(container.getValue().toString()));
                } else if (container.getBiPredicate() instanceof Contains && container.getBiPredicate() == Contains.within) {
                    for (Object val : (Collection<Object>) container.getValue()) {
                        primaryKeyBuilder.addPrimaryKeys(QueryFlowOuterClass.VertexPrimaryKeyProto.newBuilder().setLabelId(labelId).setPrimaryKeyValue(val.toString()));
                    }
                }
            }
        }
    }
    argumentBuilder.setPayload(primaryKeyBuilder.build().toByteString()).setBoolFlag(isPartitionIdFlag());
    ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(getCountOperator(QueryFlowOuterClass.OperatorType.V), argumentBuilder, rangeLimit);
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    TreeNodeLabelManager treeNodeLabelManager = contextManager.getTreeNodeLabelManager();
    LogicalSourceVertex logicalSourceVertex = new LogicalSourceVertex(vertexIdManager.getId(), processorSourceFunction);
    logicalSourceVertex.getBeforeRequirementList().addAll(buildBeforeRequirementList(treeNodeLabelManager));
    logicalSourceVertex.getAfterRequirementList().addAll(buildAfterRequirementList(treeNodeLabelManager));
    getUsedLabelList().forEach(v -> processorSourceFunction.getUsedLabelList().add(treeNodeLabelManager.getLabelIndex(v)));
    logicalQueryPlan.addLogicalVertex(logicalSourceVertex);
    setFinishVertex(logicalQueryPlan.getOutputVertex(), treeNodeLabelManager);
    return logicalQueryPlan;
}
Also used : LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) TreeNodeLabelManager(com.alibaba.maxgraph.compiler.tree.TreeNodeLabelManager) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction) GraphProperty(com.alibaba.maxgraph.compiler.api.schema.GraphProperty) GraphVertex(com.alibaba.maxgraph.compiler.api.schema.GraphVertex) Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) List(java.util.List) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Aggregations

LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)49 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)41 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)34 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)29 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)27 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)18 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)15 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)13 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)11 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)10 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)6 Message (com.alibaba.maxgraph.Message)5 ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)5 CountGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.CountGlobalTreeNode)5 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)5 HasTreeNode (com.alibaba.maxgraph.compiler.tree.HasTreeNode)5 MaxTreeNode (com.alibaba.maxgraph.compiler.tree.MaxTreeNode)5 MinTreeNode (com.alibaba.maxgraph.compiler.tree.MinTreeNode)5 PropertyMapTreeNode (com.alibaba.maxgraph.compiler.tree.PropertyMapTreeNode)5 RangeGlobalTreeNode (com.alibaba.maxgraph.compiler.tree.RangeGlobalTreeNode)5