Search in sources :

Example 1 with MapPropFillFunction

use of com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction in project GraphScope by alibaba.

the class LambdaMapTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    if (this.mapFunction instanceof RangeSumFunction) {
        RangeSumFunction rangeSumFunction = RangeSumFunction.class.cast(this.mapFunction);
        int propId = SchemaUtils.getPropId(rangeSumFunction.getPropName(), schema);
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.RANGE_SUM, Message.Value.newBuilder().setIntValue(propId).addIntValueList(rangeSumFunction.getStart()).addIntValueList(rangeSumFunction.getCount()));
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
    } else if (this.mapFunction instanceof MapPropFillFunction) {
        MapPropFillFunction mapPropFillFunction = MapPropFillFunction.class.cast(this.mapFunction);
        setPropLocalFlag(true);
        List<String> propNameList = mapPropFillFunction.getPropNameList();
        List<Integer> propIdList = propNameList.stream().map(v -> CompilerUtils.getPropertyId(schema, v)).collect(Collectors.toList());
        LogicalVertex logicalVertex = getInputNode().getOutputVertex();
        if (logicalVertex.getProcessorFunction().getOperatorType() == QueryFlowOuterClass.OperatorType.PROP_FILL) {
            logicalVertex.getProcessorFunction().getArgumentBuilder().addAllIntValueList(propIdList);
            LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
            logicalSubQueryPlan.addLogicalVertex(new LogicalSourceDelegateVertex(logicalVertex));
            return logicalSubQueryPlan;
        } else {
            ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addAllIntValueList(propIdList));
            return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
        }
    } else {
        Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setStrValue(this.lambdaIndex);
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.LAMBDA_MAP, argumentBuilder);
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
    }
}
Also used : ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalSourceDelegateVertex(com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex) Message(com.alibaba.maxgraph.Message) List(java.util.List) RangeSumFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction) MapPropFillFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 2 with MapPropFillFunction

use of com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction in project GraphScope by alibaba.

the class TreeBuilder method visitLambdaMapStep.

private TreeNode visitLambdaMapStep(LambdaMapStep step, TreeNode prev) {
    Function functionObj = step.getMapFunction();
    Function mapFunction;
    if (functionObj instanceof FunctionTraverser) {
        mapFunction = ReflectionUtils.getFieldValue(FunctionTraverser.class, functionObj, "function");
    } else {
        mapFunction = functionObj;
    }
    if (mapFunction instanceof CustomCaseWhenFunction) {
        CustomCaseWhenFunction customCaseWhenFunction = CustomCaseWhenFunction.class.cast(mapFunction);
        return processCaseWhenFunction(prev, customCaseWhenFunction);
    } else if (mapFunction instanceof CustomAggregationListTraversal) {
        CustomAggregationListTraversal customAggregationListTraversal = CustomAggregationListTraversal.class.cast(mapFunction);
        List<Traversal<?, ?>> aggregateTraversalList = customAggregationListTraversal.getTraversalList();
        List<TreeNode> aggregateNodeList = Lists.newArrayList();
        boolean saveFlag = rootPathFlag;
        this.rootPathFlag = false;
        for (Traversal<?, ?> traversal : aggregateTraversalList) {
            aggregateNodeList.add(travelTraversalAdmin(traversal.asAdmin(), new SourceDelegateNode(prev, schema)));
        }
        this.rootPathFlag = saveFlag;
        return new AggregationListTreeNode(prev, schema, customAggregationListTraversal.getNameList(), aggregateNodeList);
    } else if (mapFunction instanceof MapPropFillFunction || mapFunction instanceof RangeSumFunction) {
        return new LambdaMapTreeNode(prev, schema, mapFunction, null);
    } else {
        if (this.lambdaEnableFlag) {
            return new LambdaMapTreeNode(prev, schema, mapFunction, buildLambdaIndex(step));
        } else {
            throw new UnsupportedOperationException("Not support lambda map yet");
        }
    }
}
Also used : CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) CustomCaseWhenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomCaseWhenFunction) RangeSumFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction) MapPropFillFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction) CustomWhenThenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomWhenThenFunction) Function(java.util.function.Function) CustomCaseWhenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomCaseWhenFunction) 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) RangeSumFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction) MapPropFillFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction)

Aggregations

MapPropFillFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction)2 RangeSumFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction)2 Message (com.alibaba.maxgraph.Message)1 LogicalSourceDelegateVertex (com.alibaba.maxgraph.compiler.logical.LogicalSourceDelegateVertex)1 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)1 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)1 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)1 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)1 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)1 CustomCaseWhenFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomCaseWhenFunction)1 CustomWhenThenFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomWhenThenFunction)1 List (java.util.List)1 Function (java.util.function.Function)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1