Search in sources :

Example 6 with ProcessorSourceFunction

use of com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction 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 7 with ProcessorSourceFunction

use of com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction 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)

Example 8 with ProcessorSourceFunction

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

the class LogicalQueryPlan method optimizeGraphVertex.

private void optimizeGraphVertex() {
    List<LogicalVertex> logicalVertexList = this.getLogicalVertexList();
    LogicalVertex graphVertex = null;
    for (LogicalVertex logicalVertex : logicalVertexList) {
        if (logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.SUBGRAPH) {
            graphVertex = logicalVertex;
            break;
        }
    }
    if (null != graphVertex) {
        List<Pair<LogicalEdge, LogicalVertex>> graphSourceVertexList = this.getSourceEdgeVertexList(graphVertex);
        List<Pair<LogicalEdge, LogicalVertex>> graphTargetVertexList = this.getTargetEdgeVertexList(graphVertex);
        if (graphTargetVertexList != null && graphTargetVertexList.size() == 1) {
            LogicalVertex targetVertex = graphTargetVertexList.get(0).getRight();
            if (targetVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.OUTPUT_VINEYARD_VERTEX) {
                return;
            }
        }
        if (graphSourceVertexList.size() == 1) {
            LogicalVertex graphSourceVertex = graphSourceVertexList.get(0).getRight();
            if (graphSourceVertex.getProcessorFunction() instanceof ProcessorSourceFunction) {
                ProcessorSourceFunction processorSourceFunction = ProcessorSourceFunction.class.cast(graphSourceVertex.getProcessorFunction());
                processorSourceFunction.resetOperatorType(QueryFlowOuterClass.OperatorType.SUBGRAPH_SOURCE);
                if (graphVertex.getProcessorFunction().getArgumentBuilder() != null) {
                    processorSourceFunction.getArgumentBuilder().mergeFrom(graphVertex.getProcessorFunction().getArgumentBuilder().build());
                }
                this.removeVertex(graphVertex);
            }
        }
    }
}
Also used : Pair(org.apache.commons.lang3.tuple.Pair) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 9 with ProcessorSourceFunction

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

the class SourceCreateGraphTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    String graphType = configuration.getString(QUERY_CREATE_GRAPH_TYPE, null);
    if (StringUtils.isEmpty(graphType)) {
        throw new IllegalArgumentException("Graph type must be setted by g.createGraph(graphName).with('graphType'," + " '...')");
    }
    QueryFlowOuterClass.CreateGraphTypeProto createGraphType = QueryFlowOuterClass.CreateGraphTypeProto.valueOf(StringUtils.upperCase(graphType));
    if (createGraphType == QueryFlowOuterClass.CreateGraphTypeProto.VINEYARD) {
        QueryFlowOuterClass.RuntimeGraphSchemaProto schemaProto = CompilerUtils.buildRuntimeGraphSchema(schema);
        ProcessorSourceFunction createGraphFunction = new ProcessorSourceFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_BUILDER, Message.Value.newBuilder().setStrValue(graphName).setPayload(schemaProto.toByteString()), null);
        LogicalSourceVertex logicalSourceVertex = new LogicalSourceVertex(contextManager.getVertexIdManager().getId(), createGraphFunction);
        logicalQueryPlan.addLogicalVertex(logicalSourceVertex);
        ProcessorFunction streamFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GRAPH_VINEYARD_STREAM, Message.Value.newBuilder().setStrValue(graphName));
        LogicalUnaryVertex vineyardStreamVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), streamFunction, logicalSourceVertex);
        logicalQueryPlan.addLogicalVertex(vineyardStreamVertex);
        logicalQueryPlan.addLogicalEdge(logicalSourceVertex, vineyardStreamVertex, LogicalEdge.shuffleConstant());
        setFinishVertex(logicalQueryPlan.getOutputVertex(), contextManager.getTreeNodeLabelManager());
        return logicalQueryPlan;
    } else {
        throw new IllegalArgumentException("Only support create vineyard graph yet");
    }
}
Also used : LogicalSourceVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 10 with ProcessorSourceFunction

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

the class SourceEdgeTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalQueryPlan = new LogicalSubQueryPlan(contextManager);
    logicalQueryPlan.setDelegateSourceFlag(false);
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setBoolValue(true);
    processLabelArgument(argumentBuilder, false);
    processIdArgument(argumentBuilder, false);
    ProcessorSourceFunction processorSourceFunction = new ProcessorSourceFunction(getCountOperator(QueryFlowOuterClass.OperatorType.E), argumentBuilder, rangeLimit);
    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)

Aggregations

ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)10 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)5 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)4 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)3 LogicalSourceVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceVertex)3 List (java.util.List)3 Message (com.alibaba.maxgraph.Message)2 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)2 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)2 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)2 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)2 LogicalChainSourceVertex (com.alibaba.maxgraph.compiler.logical.chain.LogicalChainSourceVertex)2 Pair (org.apache.commons.lang3.tuple.Pair)2 GraphProperty (com.alibaba.maxgraph.compiler.api.schema.GraphProperty)1 GraphVertex (com.alibaba.maxgraph.compiler.api.schema.GraphVertex)1 ExecuteParam (com.alibaba.maxgraph.compiler.executor.ExecuteParam)1 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)1 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)1 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)1 LogicalChainUnaryVertex (com.alibaba.maxgraph.compiler.logical.chain.LogicalChainUnaryVertex)1