Search in sources :

Example 11 with SourceDelegateNode

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

the class TreeBuilder method processCaseWhenFunction.

private TreeNode processCaseWhenFunction(TreeNode prev, CustomCaseWhenFunction customCaseWhenFunction) {
    Traversal<?, ?> caseTraversal = customCaseWhenFunction.getCaseTraversal();
    List<CustomWhenThenFunction> whenThenFunctionList = customCaseWhenFunction.getWhenThenFunctionList();
    Traversal<?, ?> elseEndTraversal = customCaseWhenFunction.getElseEndTraversal();
    boolean saveFlag = rootPathFlag;
    this.rootPathFlag = false;
    TreeNode caseTreeNode = travelTraversalAdmin(caseTraversal.asAdmin(), new SourceDelegateNode(prev, schema));
    List<Pair<TreeNode, TreeNode>> whenThenNodeList = Lists.newArrayList();
    for (CustomWhenThenFunction whenThenFunction : whenThenFunctionList) {
        Pair<TreeNode, TreeNode> whenThenPair = Pair.of(travelTraversalAdmin(whenThenFunction.getWhenPredicate().asAdmin(), new SourceDelegateNode(caseTreeNode, schema)), travelTraversalAdmin(whenThenFunction.getThenTraversal().asAdmin(), new SourceDelegateNode(caseTreeNode, schema)));
        whenThenNodeList.add(whenThenPair);
    }
    TreeNode elseEndTreeNode = elseEndTraversal == null ? null : travelTraversalAdmin(elseEndTraversal.asAdmin(), new SourceDelegateNode(caseTreeNode, schema));
    this.rootPathFlag = saveFlag;
    return new CaseWhenTreeNode(prev, schema, caseTreeNode, whenThenNodeList, elseEndTreeNode);
}
Also used : CustomWhenThenFunction(com.alibaba.maxgraph.sdkcommon.compiler.custom.branch.CustomWhenThenFunction) 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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) Pair(org.apache.commons.lang3.tuple.Pair)

Example 12 with SourceDelegateNode

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

the class TreeBuilder method visitTraversalMapStep.

private TreeNode visitTraversalMapStep(TraversalMapStep step, TreeNode prev) {
    TreeNode mapTreeNode = travelTraversalAdmin(ReflectionUtils.getFieldValue(TraversalMapStep.class, step, "mapTraversal"), new SourceDelegateNode(prev, schema));
    List<TreeNode> mapTreeNodeList = TreeNodeUtils.buildTreeNodeListFromLeaf(mapTreeNode);
    for (TreeNode treeNode : mapTreeNodeList) {
        if (treeNode.getNodeType() == NodeType.AGGREGATE || treeNode instanceof DedupGlobalTreeNode) {
            throw new UnsupportedOperationException("Not support traversal in map");
        }
    }
    return new TraversalMapTreeNode(prev, schema, mapTreeNode);
}
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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Example 13 with SourceDelegateNode

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

the class TreeBuilder method visitPathStep.

private TreeNode visitPathStep(PathStep step, TreeNode prev) {
    String from = ReflectionUtils.getFieldValue(PathStep.class, step, "fromLabel");
    String to = ReflectionUtils.getFieldValue(PathStep.class, step, "toLabel");
    Set<String> keepLabels = ReflectionUtils.getFieldValue(PathStep.class, step, "keepLabels");
    if (StringUtils.isNotEmpty(from) || StringUtils.isNotEmpty(to) || (null != keepLabels && keepLabels.size() > 0)) {
        throw new UnsupportedOperationException("Not support from/to/keepLabels in path step");
    }
    PathTreeNode pathTreeNode = new PathTreeNode(prev, schema);
    pathTreeNode.addPathRequirement();
    pathTreeNode.getUsedLabelList().addAll(treeNodeLabelManager.getUserLabelList());
    boolean savePathFlag = this.rootPathFlag;
    this.rootPathFlag = false;
    Set<SourceDelegateNode> ringSourceNodeList = Sets.newHashSet();
    List<Traversal.Admin<?, ?>> traversalRingList = step.getLocalChildren();
    List<TreeNode> ringTreeNodeList = Lists.newArrayList();
    for (Traversal.Admin<?, ?> traversalAdmin : traversalRingList) {
        SourceDelegateNode sourceDelegateNode = new SourceDelegateNode(pathTreeNode, schema);
        ringSourceNodeList.add(sourceDelegateNode);
        ringTreeNodeList.add(travelTraversalAdmin(traversalAdmin, sourceDelegateNode));
    }
    pathTreeNode.setRingTreeNodeList(ringTreeNodeList);
    Set<String> propKeyList = pathTreeNode.getOutputPropList();
    Set<ValueType> pathValueList = Sets.newHashSet();
    processPathRequirement(pathTreeNode, propKeyList, pathValueList);
    pathTreeNode.setPathValueList(pathValueList);
    ringSourceNodeList.forEach(v -> {
        if (pathValueList.size() > 1) {
            v.setDelegateOutputValueType(new VarietyValueType(pathValueList));
        } else {
            v.setDelegateOutputValueType(pathValueList.iterator().next());
        }
    });
    if (!propKeyList.isEmpty()) {
        if (pathTreeNode.getInputNode() instanceof PropFillTreeNode) {
            PropFillTreeNode propFillTreeNode = PropFillTreeNode.class.cast(pathTreeNode.getInputNode());
            propFillTreeNode.getPropKeyList().addAll(propKeyList);
        } else {
            PropFillTreeNode propFillTreeNode = new PropFillTreeNode(prev, propKeyList, schema);
            pathTreeNode.setInputNode(propFillTreeNode);
        }
    }
    this.rootPathFlag = savePathFlag;
    return pathTreeNode;
}
Also used : VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) ListValueType(com.alibaba.maxgraph.compiler.tree.value.ListValueType) ValueValueType(com.alibaba.maxgraph.compiler.tree.value.ValueValueType) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) VarietyValueType(com.alibaba.maxgraph.compiler.tree.value.VarietyValueType) 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 14 with SourceDelegateNode

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

the class TreeBuilder method visitMathStep.

private TreeNode visitMathStep(MathStep step, TreeNode prev) {
    MathStep.TinkerExpression tinkerExpression = ReflectionUtils.getFieldValue(MathStep.class, step, "expression");
    TraversalRing<?, Number> traversalRing = ReflectionUtils.getFieldValue(MathStep.class, step, "traversalRing");
    List<TreeNode> ringTreeNodeList = Lists.newArrayList();
    traversalRing.getTraversals().forEach(v -> ringTreeNodeList.add(travelTraversalAdmin(v, new SourceDelegateNode(prev, schema))));
    return new MathTreeNode(prev, schema, ringTreeNodeList, tinkerExpression);
}
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) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Example 15 with SourceDelegateNode

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

the class TreeBuilder method visitSelectOneStep.

private TreeNode visitSelectOneStep(SelectOneStep step, TreeNode prev) {
    Pop pop = step.getPop();
    String selectLabel = (String) Lists.newArrayList(step.getScopeKeys()).get(0);
    Traversal.Admin<?, ?> selectTraversal = ReflectionUtils.getFieldValue(SelectOneStep.class, step, "selectTraversal");
    SelectOneTreeNode selectOneTreeNode = new SelectOneTreeNode(prev, selectLabel, pop, treeNodeLabelManager.getLabelTreeNodeList(selectLabel), schema);
    boolean saveFlag = rootPathFlag;
    rootPathFlag = false;
    if (null != selectTraversal) {
        selectOneTreeNode.setTraversalTreeNode(travelTraversalAdmin(selectTraversal, new SourceDelegateNode(selectOneTreeNode, schema)));
    }
    rootPathFlag = saveFlag;
    return selectOneTreeNode;
}
Also used : Pop(org.apache.tinkerpop.gremlin.process.traversal.Pop) 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)

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