Search in sources :

Example 1 with CustomAggregationListTraversal

use of com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal in project GraphScope by alibaba.

the class TreeBuilder method travelTraversalDirectly.

private <S, E> TreeNode travelTraversalDirectly(Traversal.Admin<S, E> admin, TreeNode parent) {
    if (admin instanceof TokenTraversal) {
        return new TokenTreeNode(parent, schema, TokenTraversal.class.cast(admin).getToken());
    } else if (admin instanceof ValueTraversal) {
        ValueTraversal elementValueTraversal = ValueTraversal.class.cast(admin);
        String propKey = elementValueTraversal.getPropertyKey();
        TreeNode bypassTreeNode = null;
        Traversal.Admin<?, ?> bypassTraversal = ReflectionUtils.getFieldValue(AbstractLambdaTraversal.class, elementValueTraversal, "bypassTraversal");
        if (null != bypassTraversal) {
            bypassTreeNode = travelTraversalAdmin(bypassTraversal, new SourceDelegateNode(parent, schema));
        }
        return new ElementValueTreeNode(parent, propKey, bypassTreeNode, schema);
    } else if (admin instanceof ColumnTraversal) {
        ColumnTraversal columnTraversal = ColumnTraversal.class.cast(admin);
        return new ColumnTreeNode(parent, schema, columnTraversal.getColumn());
    } else if (admin instanceof IdentityTraversal) {
        return parent;
    } else if (admin instanceof TrueTraversal) {
        return parent;
    } else if (admin instanceof ConstantTraversal) {
        return new ConstantTreeNode(parent, schema, admin.next());
    } else if (admin instanceof CustomAggregationListTraversal) {
        CustomAggregationListTraversal customAggregationListTraversal = CustomAggregationListTraversal.class.cast(admin);
        List<TreeNode> aggNodeList = Lists.newArrayList();
        boolean saveFlag = this.rootPathFlag;
        this.rootPathFlag = false;
        List<Traversal<?, ?>> traversalList = customAggregationListTraversal.getTraversalList();
        for (Traversal<?, ?> aggTraversal : traversalList) {
            aggNodeList.add(travelTraversalAdmin(aggTraversal.asAdmin(), new SourceDelegateNode(parent, schema)));
        }
        this.rootPathFlag = saveFlag;
        return new AggregationListTreeNode(parent, schema, customAggregationListTraversal.getNameList(), aggNodeList);
    } else {
        throw new IllegalArgumentException("Not deal with direct traversal => " + admin);
    }
}
Also used : CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) 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) 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 2 with CustomAggregationListTraversal

use of com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal 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

SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)2 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)2 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)1 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)1 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)1 CustomCaseWhenFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomCaseWhenFunction)1 CustomWhenThenFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomWhenThenFunction)1 MapPropFillFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.map.MapPropFillFunction)1 RangeSumFunction (com.alibaba.maxgraph.sdkcommon.compiler.custom.map.RangeSumFunction)1 Function (java.util.function.Function)1