Search in sources :

Example 1 with VertexValueType

use of com.alibaba.maxgraph.compiler.tree.value.VertexValueType in project GraphScope by alibaba.

the class CostEstimate method estimateNetworkCost.

public double estimateNetworkCost(TreeNode node) {
    if (node instanceof FoldTreeNode) {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * NET_FOLD_RATIO;
    } else if (node.getNodeType() == NodeType.AGGREGATE) {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO;
    } else if (node instanceof PropertyNode) {
        PropertyNode propertyNode = (PropertyNode) node;
        Set<String> propNameList = propertyNode.getPropKeyList();
        if (propNameList.size() <= 0) {
            return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * PROP_DEFAULT_COUNT;
        } else {
            return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO * propNameList.size();
        }
    } else if (node.getOutputValueType() instanceof VertexValueType) {
        return NET_DEFAULT_COST;
    } else {
        return NET_DEFAULT_COST * NET_DEFAULT_SCALE_RATIO;
    }
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) FoldTreeNode(com.alibaba.maxgraph.compiler.tree.FoldTreeNode)

Example 2 with VertexValueType

use of com.alibaba.maxgraph.compiler.tree.value.VertexValueType in project GraphScope by alibaba.

the class OrTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Message.LogicalCompare.Builder logicalCompareBuilder = Message.LogicalCompare.newBuilder().setCompare(Message.CompareType.OR_RELATION);
    List<TreeNode> otherTreeNodeList = Lists.newArrayList();
    boolean vertexFlag = getInputNode().getOutputValueType() instanceof VertexValueType;
    orTreeNodeList.forEach(v -> {
        if (v instanceof HasTreeNode && ((HasTreeNode) v).getInputNode() instanceof SourceTreeNode) {
            HasTreeNode hasTreeNode = HasTreeNode.class.cast(v);
            List<Message.LogicalCompare> logicalCompareList = Lists.newArrayList();
            for (HasContainer hasContainer : hasTreeNode.getHasContainerList()) {
                logicalCompareList.add(CompilerUtils.parseLogicalCompare(hasContainer, schema, labelManager.getLabelIndexList(), vertexFlag));
            }
            if (logicalCompareList.size() == 1) {
                logicalCompareBuilder.addChildCompareList(logicalCompareList.get(0));
            } else {
                Message.LogicalCompare andLogicalCompare = Message.LogicalCompare.newBuilder().setCompare(Message.CompareType.AND_RELATION).addAllChildCompareList(logicalCompareList).build();
                logicalCompareBuilder.addChildCompareList(andLogicalCompare);
            }
        } else {
            otherTreeNodeList.add(v);
        }
    });
    if (otherTreeNodeList.isEmpty()) {
        ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(QueryFlowOuterClass.OperatorType.HAS);
        filterFunction.getLogicalCompareList().addAll(Lists.newArrayList(logicalCompareBuilder.build()));
        return parseSingleUnaryVertex(vertexIdManager, labelManager, filterFunction, contextManager);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) Message(com.alibaba.maxgraph.Message) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager)

Example 3 with VertexValueType

use of com.alibaba.maxgraph.compiler.tree.value.VertexValueType in project GraphScope by alibaba.

the class OrderGlobalTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalSubQueryPlan logicalSubQueryPlan = new LogicalSubQueryPlan(contextManager);
    LogicalVertex delegateSourceVertex = getInputNode().getOutputVertex();
    logicalSubQueryPlan.addLogicalVertex(delegateSourceVertex);
    TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
    VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
    Message.OrderComparatorList.Builder comparatorList = Message.OrderComparatorList.newBuilder();
    Set<String> propFillList = Sets.newHashSet();
    Set<Integer> usedLabelIdList = Sets.newHashSet();
    LogicalVertex lastJoinVertex = null;
    LogicalVertex inputVertex = delegateSourceVertex;
    for (int i = 0; i < treeNodeOrderList.size(); i++) {
        Pair<TreeNode, Order> orderPair = treeNodeOrderList.get(i);
        if (orderPair.getLeft() instanceof SourceDelegateNode) {
            comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(0).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
        } else {
            UnaryTreeNode unaryTreeNode = UnaryTreeNode.class.cast(orderPair.getLeft());
            if (unaryTreeNode.getInputNode() instanceof SourceDelegateNode && ((unaryTreeNode instanceof SelectOneTreeNode && SelectOneTreeNode.class.cast(unaryTreeNode).getTraversalTreeNode() == null) || (unaryTreeNode instanceof ElementValueTreeNode && ElementValueTreeNode.class.cast(unaryTreeNode).getByPassTraversal() == null) || unaryTreeNode instanceof TokenTreeNode || (unaryTreeNode instanceof TraversalMapTreeNode && ((TraversalMapTreeNode) unaryTreeNode).getTraversalNode() instanceof ColumnTreeNode && ((ColumnTreeNode) ((TraversalMapTreeNode) unaryTreeNode).getTraversalNode()).getInputNode() instanceof SourceDelegateNode))) {
                if (unaryTreeNode instanceof SelectOneTreeNode) {
                    int labelId = labelManager.getLabelIndex(SelectOneTreeNode.class.cast(unaryTreeNode).getSelectLabel());
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelId).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                    usedLabelIdList.add(labelId);
                } else if (unaryTreeNode instanceof TokenTreeNode) {
                    int labelId = labelManager.getLabelIndex(TokenTreeNode.class.cast(unaryTreeNode).getToken().getAccessor());
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelId).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                } else if (unaryTreeNode instanceof ElementValueTreeNode) {
                    String propKey = ElementValueTreeNode.class.cast(unaryTreeNode).getPropKeyList().iterator().next();
                    propFillList.add(propKey);
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(CompilerUtils.getPropertyId(schema, propKey)).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                } else {
                    TraversalMapTreeNode traversalMapTreeNode = TraversalMapTreeNode.class.cast(unaryTreeNode);
                    ColumnTreeNode columnTreeNode = (ColumnTreeNode) traversalMapTreeNode.getTraversalNode();
                    comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(labelManager.getLabelIndex(columnTreeNode.getColumn().name())).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                }
            } else {
                TreeNode compareTreeNode = TreeNodeUtils.buildSingleOutputNode(orderPair.getLeft(), schema);
                Pair<LogicalQueryPlan, Integer> planLabelPair = TreeNodeUtils.buildSubQueryWithLabel(compareTreeNode, inputVertex, contextManager);
                inputVertex = planLabelPair.getLeft().getOutputVertex();
                logicalSubQueryPlan.mergeLogicalQueryPlan(planLabelPair.getLeft());
                comparatorList.addOrderComparator(Message.OrderComparator.newBuilder().setPropId(planLabelPair.getRight()).setOrderType(Message.OrderType.valueOf(StringUtils.upperCase(orderPair.getRight().name()))).build());
                usedLabelIdList.add(planLabelPair.getRight());
            }
        }
    }
    if (!propFillList.isEmpty() && getInputNode().getOutputValueType() instanceof VertexValueType) {
        LogicalVertex propFillInputVertex = logicalSubQueryPlan.getOutputVertex();
        ProcessorFunction propFillFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, Message.Value.newBuilder().addAllIntValueList(propFillList.stream().map(v -> CompilerUtils.getPropertyId(schema, v)).collect(Collectors.toSet())));
        LogicalVertex propFillVertex = new LogicalUnaryVertex(vertexIdManager.getId(), propFillFunction, true, propFillInputVertex);
        LogicalEdge logicalEdge;
        if (propFillInputVertex.isPropLocalFlag()) {
            logicalEdge = new LogicalEdge(EdgeShuffleType.FORWARD);
        } else {
            logicalEdge = new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_KEY);
        }
        logicalSubQueryPlan.addLogicalVertex(propFillVertex);
        logicalSubQueryPlan.addLogicalEdge(propFillInputVertex, propFillVertex, logicalEdge);
    }
    Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setPayload(comparatorList.build().toByteString());
    if (orderFlag) {
        argumentBuilder.setBoolValue(true).setIntValue(labelManager.getLabelIndex(orderFlagLabel));
    }
    argumentBuilder.setBoolFlag(partitionIdFlag).setLongValue(SHUFFLE_THRESHOLD).setOrderFlag(orderKeyFlag);
    ProcessorFunction orderFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.ORDER, argumentBuilder, rangeLimit);
    orderFunction.getUsedLabelList().addAll(usedLabelIdList);
    LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
    LogicalVertex orderVertex = new LogicalUnaryVertex(vertexIdManager.getId(), orderFunction, false, outputVertex);
    logicalSubQueryPlan.addLogicalVertex(orderVertex);
    logicalSubQueryPlan.addLogicalEdge(outputVertex, orderVertex, new LogicalEdge());
    addUsedLabelAndRequirement(orderVertex, labelManager);
    setFinishVertex(orderVertex, labelManager);
    return logicalSubQueryPlan;
}
Also used : GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) EdgeShuffleType(com.alibaba.maxgraph.compiler.logical.edge.EdgeShuffleType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) TreeNodeUtils(com.alibaba.maxgraph.compiler.utils.TreeNodeUtils) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) StringUtils(org.apache.commons.lang3.StringUtils) QueryFlowOuterClass(com.alibaba.maxgraph.QueryFlowOuterClass) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) Pair(org.apache.commons.lang3.tuple.Pair) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) CompilerUtils(com.alibaba.maxgraph.compiler.utils.CompilerUtils) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Set(java.util.Set) ContextManager(com.alibaba.maxgraph.compiler.optimizer.ContextManager) Message(com.alibaba.maxgraph.Message) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ValueType(com.alibaba.maxgraph.compiler.tree.value.ValueType) AbstractUseKeyNode(com.alibaba.maxgraph.compiler.tree.addition.AbstractUseKeyNode) LogicalUnaryVertex(com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) VertexIdManager(com.alibaba.maxgraph.compiler.logical.VertexIdManager) LogicalSubQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)

Example 4 with VertexValueType

use of com.alibaba.maxgraph.compiler.tree.value.VertexValueType in project GraphScope by alibaba.

the class DfsRepeatGraphTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    LogicalQueryPlan sourceSubPlan = sourceTreeNode.buildLogicalQueryPlan(contextManager);
    LogicalVertex sourceVertex = sourceSubPlan.getOutputVertex();
    ProcessorSourceFunction processorSourceFunction = ProcessorSourceFunction.class.cast(sourceVertex.getProcessorFunction());
    Message.Value.Builder argument = Message.Value.newBuilder().mergeFrom(processorSourceFunction.getArgumentBuilder().build()).setBoolValue(sourceTreeNode.getOutputValueType() instanceof VertexValueType);
    ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.DFS_REPEAT_GRAPH, argument);
    processorFunction.getLogicalCompareList().addAll(processorSourceFunction.getLogicalCompareList());
    return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), processorFunction, contextManager);
}
Also used : LogicalVertex(com.alibaba.maxgraph.compiler.logical.LogicalVertex) ProcessorFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction) VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) LogicalQueryPlan(com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan) ProcessorSourceFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)

Example 5 with VertexValueType

use of com.alibaba.maxgraph.compiler.tree.value.VertexValueType in project GraphScope by alibaba.

the class HasTreeNode method buildLogicalQueryPlan.

@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
    List<Message.LogicalCompare> logicalCompareList = Lists.newArrayList();
    hasContainerList.forEach(v -> logicalCompareList.add(CompilerUtils.parseLogicalCompare(v, schema, contextManager.getTreeNodeLabelManager().getLabelIndexList(), getInputNode().getOutputValueType() instanceof VertexValueType)));
    ProcessorFilterFunction filterFunction = new ProcessorFilterFunction(logicalCompareList.size() == 1 && logicalCompareList.get(0).getPropId() == 0 ? QueryFlowOuterClass.OperatorType.FILTER : QueryFlowOuterClass.OperatorType.HAS);
    filterFunction.getLogicalCompareList().addAll(logicalCompareList);
    boolean filterExchangeFlag = false;
    for (HasContainer hasContainer : this.hasContainerList) {
        if (SchemaUtils.checkPropExist(hasContainer.getKey(), schema)) {
            filterExchangeFlag = true;
            break;
        }
    }
    if (filterExchangeFlag) {
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), filterFunction, contextManager);
    } else {
        return parseSingleUnaryVertex(contextManager.getVertexIdManager(), contextManager.getTreeNodeLabelManager(), filterFunction, contextManager, new LogicalEdge(EdgeShuffleType.FORWARD));
    }
}
Also used : VertexValueType(com.alibaba.maxgraph.compiler.tree.value.VertexValueType) LogicalEdge(com.alibaba.maxgraph.compiler.logical.LogicalEdge) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ProcessorFilterFunction(com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)

Aggregations

VertexValueType (com.alibaba.maxgraph.compiler.tree.value.VertexValueType)6 Message (com.alibaba.maxgraph.Message)2 LogicalEdge (com.alibaba.maxgraph.compiler.logical.LogicalEdge)2 LogicalQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalQueryPlan)2 LogicalVertex (com.alibaba.maxgraph.compiler.logical.LogicalVertex)2 VertexIdManager (com.alibaba.maxgraph.compiler.logical.VertexIdManager)2 ProcessorFilterFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFilterFunction)2 ProcessorFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorFunction)2 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)2 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)2 ValueType (com.alibaba.maxgraph.compiler.tree.value.ValueType)2 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 QueryFlowOuterClass (com.alibaba.maxgraph.QueryFlowOuterClass)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 LogicalSubQueryPlan (com.alibaba.maxgraph.compiler.logical.LogicalSubQueryPlan)1 LogicalUnaryVertex (com.alibaba.maxgraph.compiler.logical.LogicalUnaryVertex)1 EdgeShuffleType (com.alibaba.maxgraph.compiler.logical.edge.EdgeShuffleType)1 ProcessorSourceFunction (com.alibaba.maxgraph.compiler.logical.function.ProcessorSourceFunction)1 ContextManager (com.alibaba.maxgraph.compiler.optimizer.ContextManager)1 FoldTreeNode (com.alibaba.maxgraph.compiler.tree.FoldTreeNode)1