Search in sources :

Example 1 with JoinZeroNode

use of com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode in project GraphScope by alibaba.

the class WherePredicateTreeNode method processComplexNode.

private int processComplexNode(ContextManager contextManager, VertexIdManager vertexIdManager, TreeNodeLabelManager labelManager, LogicalSubQueryPlan logicalSubQueryPlan, LogicalVertex sourceVertex, TreeNode ringNode) {
    if (ringNode instanceof JoinZeroNode) {
        ((JoinZeroNode) ringNode).disableJoinZero();
    }
    LogicalSubQueryPlan subQueryPlan = TreeNodeUtils.buildSubQueryPlan(ringNode, sourceVertex, contextManager);
    LogicalVertex secondValueVertex = subQueryPlan.getOutputVertex();
    logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    String secondValueLabel = labelManager.createSysLabelStart("val");
    int labelId = labelManager.getLabelIndex(secondValueLabel);
    QueryFlowOuterClass.OperatorType joinType = CompilerUtils.parseJoinOperatorType(ringNode);
    LogicalBinaryVertex joinVertex = new LogicalBinaryVertex(vertexIdManager.getId(), new ProcessorFunction(joinType, Message.Value.newBuilder().setIntValue(labelId)), false, sourceVertex, secondValueVertex);
    logicalSubQueryPlan.addLogicalVertex(joinVertex);
    logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinVertex, new LogicalEdge());
    logicalSubQueryPlan.addLogicalEdge(secondValueVertex, joinVertex, new LogicalEdge());
    return labelId;
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 2 with JoinZeroNode

use of com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode in project GraphScope by alibaba.

the class BranchTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    int optionLabelId = 0;
    boolean optionJoinFlag = true;
    UnaryTreeNode branchUnaryNode = UnaryTreeNode.class.cast(branchTreeNode);
    if (branchUnaryNode.getInputNode() instanceof SourceTreeNode) {
        if (branchUnaryNode instanceof PropertyNode) {
            String prop = PropertyNode.class.cast(branchUnaryNode).getPropKeyList().iterator().next();
            optionLabelId = SchemaUtils.getPropId(prop, schema);
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof SelectOneTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(SelectOneTreeNode.class.cast(branchUnaryNode).getSelectLabel());
            optionJoinFlag = false;
        } else if (branchUnaryNode instanceof TokenTreeNode) {
            optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(TokenTreeNode.class.cast(branchUnaryNode).getToken().getAccessor());
            optionJoinFlag = false;
        }
    }
    if (optionJoinFlag) {
        // join the value stream to get value and set it to label
        if (branchUnaryNode instanceof JoinZeroNode) {
            ((JoinZeroNode) branchUnaryNode).disableJoinZero();
        }
        TreeNode currentBranchTreeNode = TreeNodeUtils.buildSingleOutputNode(branchTreeNode, schema);
        LogicalQueryPlan branchValuePlan = TreeNodeUtils.buildSubQueryPlan(currentBranchTreeNode, sourceVertex, contextManager);
        TreeNode branchSourceNode = TreeNodeUtils.getSourceTreeNode(currentBranchTreeNode);
        sourceVertex = branchSourceNode.getOutputVertex();
        LogicalVertex branchValueVertex = branchValuePlan.getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(branchValuePlan);
        String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
        optionLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
        QueryFlowOuterClass.OperatorType joinOperatorType = CompilerUtils.parseJoinOperatorType(branchTreeNode);
        ProcessorFunction joinFunction = new ProcessorFunction(joinOperatorType, Message.Value.newBuilder().setIntValue(optionLabelId));
        LogicalBinaryVertex joinVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), joinFunction, false, sourceVertex, branchValueVertex);
        logicalSubQueryPlan.addLogicalVertex(joinVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, joinVertex, new LogicalEdge());
        logicalSubQueryPlan.addLogicalEdge(branchValueVertex, joinVertex, new LogicalEdge());
    }
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    if (optionLabelId > 0) {
        ProcessorFunction fillFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addIntValueList(optionLabelId));
        LogicalVertex fillPropVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), fillFunction, true, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(fillPropVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, fillPropVertex, outputVertex.isPropLocalFlag() ? new LogicalEdge(EdgeShuffleType.FORWARD) : new LogicalEdge());
        outputVertex = fillPropVertex;
    }
    Map<Object, Message.LogicalCompare> pickCompareList = Maps.newHashMap();
    List<Message.LogicalCompare> noneCompareList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> pickEntry : optionPickList.entrySet()) {
        Object pick = pickEntry.getKey();
        Object pickValue = pick;
        if (optionLabelId == TreeConstants.LABEL_INDEX) {
            final String pickString = pick.toString();
            pickValue = schema.getElement(pickString).getLabelId();
        } else if (optionLabelId == TreeConstants.ID_INDEX) {
            pickValue = Long.parseLong(pick.toString());
        }
        Message.VariantType variantType = CompilerUtils.parseVariantType(pickValue.getClass(), pickValue);
        Message.Value.Builder valueBuilder = Message.Value.newBuilder().setValueType(variantType);
        switch(variantType) {
            case VT_INT:
                {
                    if (pickValue instanceof Integer) {
                        valueBuilder.setIntValue((Integer) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setIntValue((int) number);
                    }
                    break;
                }
            case VT_LONG:
                {
                    if (pickValue instanceof Long) {
                        valueBuilder.setLongValue((Long) pickValue);
                    } else {
                        Class<?> pickTokenKeyClazz = BranchStep.class.getDeclaredClasses()[0];
                        Number number = ReflectionUtils.getFieldValue(pickTokenKeyClazz, pickValue, "number");
                        valueBuilder.setLongValue((long) number);
                    }
                    break;
                }
            case VT_STRING:
                {
                    valueBuilder.setStrValue((String) pickValue).build();
                    break;
                }
            default:
                {
                    throw new UnsupportedOperationException(pickValue + " for branch option operator");
                }
        }
        Message.Value value = valueBuilder.build();
        pickCompareList.put(pick, Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.EQ).setValue(value).setType(variantType).build());
        noneCompareList.add(Message.LogicalCompare.newBuilder().setPropId(optionLabelId).setCompare(Message.CompareType.NEQ).setValue(value).setType(variantType).build());
    }
    List<LogicalVertex> unionVertexList = Lists.newArrayList();
    for (Map.Entry<Object, List<TreeNode>> optionEntry : this.optionPickList.entrySet()) {
        List<TreeNode> optionTreeNodeList = optionEntry.getValue();
        Message.LogicalCompare logicalCompare = checkNotNull(pickCompareList.get(optionEntry.getKey()));
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().add(logicalCompare);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        for (TreeNode treeNode : optionTreeNodeList) {
            LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(treeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
            unionVertexList.add(subQueryPlan.getOutputVertex());
            logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
        }
    }
    if (null != noneTreeNode) {
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.FILTER, createArgumentBuilder().setBoolValue(true));
        filterFunction.getLogicalCompareList().addAll(noneCompareList);
        LogicalVertex filterVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), filterFunction, outputVertex);
        logicalSubQueryPlan.addLogicalVertex(filterVertex);
        logicalSubQueryPlan.addLogicalEdge(outputVertex, filterVertex, LogicalEdge.forwardEdge());
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(noneTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), filterVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    if (null != anyTreeNode) {
        LogicalQueryPlan subQueryPlan = TreeNodeUtils.buildQueryPlanWithSource(anyTreeNode, contextManager.getTreeNodeLabelManager(), contextManager, contextManager.getVertexIdManager(), outputVertex);
        unionVertexList.add(subQueryPlan.getOutputVertex());
        logicalSubQueryPlan.mergeLogicalQueryPlan(subQueryPlan);
    }
    LogicalVertex currentUnionVertex = unionVertexList.remove(0);
    for (LogicalVertex logicalVertex : unionVertexList) {
        LogicalVertex unionVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(QueryFlowOuterClass.OperatorType.UNION), false, currentUnionVertex, logicalVertex);
        logicalSubQueryPlan.addLogicalVertex(unionVertex);
        logicalSubQueryPlan.addLogicalEdge(currentUnionVertex, unionVertex, LogicalEdge.forwardEdge());
        logicalSubQueryPlan.addLogicalEdge(logicalVertex, unionVertex, LogicalEdge.forwardEdge());
        currentUnionVertex = unionVertex;
    }
    addUsedLabelAndRequirement(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    setFinishVertex(currentUnionVertex, contextManager.getTreeNodeLabelManager());
    return logicalSubQueryPlan;
}
Also used : LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) Message(com.alibaba.maxgraph.Message) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) List(java.util.List) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) Map(java.util.Map)

Example 3 with JoinZeroNode

use of com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode in project GraphScope by alibaba.

the class GroupCountTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex sourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(sourceVertex);
    LogicalVertex outputVertex;
    if (null == keyTreeNode || keyTreeNode instanceof SourceDelegateNode) {
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT);
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, sourceVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(sourceVertex, outputVertex, new LogicalEdge());
    } else {
        TreeNode currentKeyNode = TreeNodeUtils.buildSingleOutputNode(keyTreeNode, schema);
        if (currentKeyNode instanceof JoinZeroNode) {
            ((JoinZeroNode) currentKeyNode).disableJoinZero();
        }
        LogicalSubQueryPlan keyValuePlan = TreeNodeUtils.buildSubQueryPlan(currentKeyNode, sourceVertex, contextManager);
        LogicalVertex groupValueVertex = keyValuePlan.getOutputVertex();
        LogicalVertex enterKeyVertex = TreeNodeUtils.getSourceTreeNode(currentKeyNode).getOutputVertex();
        logicalSubQueryPlan.mergeLogicalQueryPlan(keyValuePlan);
        if (TreeNodeUtils.checkJoinSourceFlag(currentKeyNode)) {
            String valueLabel = contextManager.getTreeNodeLabelManager().createSysLabelStart("val");
            getUsedLabelList().add(valueLabel);
            int valueLabelId = contextManager.getTreeNodeLabelManager().getLabelIndex(valueLabel);
            LogicalBinaryVertex logicalBinaryVertex = new LogicalBinaryVertex(contextManager.getVertexIdManager().getId(), new ProcessorFunction(CompilerUtils.parseJoinOperatorType(currentKeyNode), Message.Value.newBuilder().setIntValue(valueLabelId)), false, enterKeyVertex, groupValueVertex);
            logicalSubQueryPlan.addLogicalVertex(logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalEdge(enterKeyVertex, logicalBinaryVertex, new LogicalEdge());
            logicalSubQueryPlan.addLogicalEdge(groupValueVertex, logicalBinaryVertex, new LogicalEdge());
            ProcessorFunction selectValueFunction = TreeNodeUtils.createSelectOneFunction(valueLabel, Pop.first, contextManager.getTreeNodeLabelManager().getLabelIndexList());
            LogicalVertex selectLabelVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), selectValueFunction, false, logicalBinaryVertex);
            logicalSubQueryPlan.addLogicalVertex(selectLabelVertex);
            logicalSubQueryPlan.addLogicalEdge(logicalBinaryVertex, selectLabelVertex, LogicalEdge.forwardEdge());
        }
        groupValueVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.GROUP_COUNT, Message.Value.newBuilder());
        outputVertex = new LogicalUnaryVertex(contextManager.getVertexIdManager().getId(), processorFunction, false, groupValueVertex);
        logicalSubQueryPlan.addLogicalVertex(outputVertex);
        logicalSubQueryPlan.addLogicalEdge(groupValueVertex, outputVertex, new LogicalEdge());
    }
    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) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) LogicalBinaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)

Example 4 with JoinZeroNode

use of com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode in project GraphScope by alibaba.

the class TreeBuilder method visitIsStep.

private TreeNode visitIsStep(IsStep step, TreeNode prev) {
    P predicate = step.getPredicate();
    Object value = predicate.getValue();
    if (prev instanceof JoinZeroNode) {
        if (Double.parseDouble(value.toString()) > 0.0 && predicate.getBiPredicate() == Compare.gte) {
            ((JoinZeroNode) prev).disableJoinZero();
        } else if (Double.parseDouble(value.toString()) >= 0.0 && predicate.getBiPredicate() == Compare.gt) {
            ((JoinZeroNode) prev).disableJoinZero();
        }
    }
    HasContainer hasContainer = convertHasContainer("", predicate, prev.getOutputValueType());
    return new HasTreeNode(prev, Lists.newArrayList(hasContainer), schema);
}
Also used : P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) JoinZeroNode(com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Aggregations

JoinZeroNode (com.alibaba.maxgraph.compiler.tree.addition.JoinZeroNode)4 LogicalBinaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalBinaryVertex)3 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)3 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)3 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)3 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)3 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)2 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)2 Message (com.alibaba.maxgraph.Message)1 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)1 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)1 PropertyNode (com.alibaba.maxgraph.compiler.tree.addition.PropertyNode)1 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1 List (java.util.List)1 Map (java.util.Map)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)1