use of com.alibaba.maxgraph.compiler.logical.VertexIdManager 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();
}
}
use of com.alibaba.maxgraph.compiler.logical.VertexIdManager 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;
}
use of com.alibaba.maxgraph.compiler.logical.VertexIdManager in project GraphScope by alibaba.
the class OutputTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
Builder odpsConfigBuilder = buildArg();
for (String propName : properties) {
odpsConfigBuilder.addPropId(SchemaUtils.getPropId(propName, schema));
}
Message.Value.Builder argumentBuilder = Message.Value.newBuilder().setPayload(odpsConfigBuilder.build().toByteString());
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.WRITE_ODPS, argumentBuilder);
LogicalSubQueryPlan logicalSubQueryPlan = parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
LogicalVertex outputVertex = logicalSubQueryPlan.getOutputVertex();
ProcessorFunction sumFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.SUM, Message.Value.newBuilder().setValueType(Message.VariantType.VT_LONG));
LogicalVertex sumVertex = new LogicalUnaryVertex(vertexIdManager.getId(), sumFunction, true, outputVertex);
logicalSubQueryPlan.addLogicalVertex(sumVertex);
logicalSubQueryPlan.addLogicalEdge(outputVertex, sumVertex, new LogicalEdge(EdgeShuffleType.SHUFFLE_BY_CONST));
addUsedLabelAndRequirement(sumVertex, labelManager);
setFinishVertex(sumVertex, labelManager);
return logicalSubQueryPlan;
}
use of com.alibaba.maxgraph.compiler.logical.VertexIdManager in project GraphScope by alibaba.
the class PeerPressureVertexProgramTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROGRAM_GRAPH_PEERPRESSURE, createOperatorArgument());
return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
}
use of com.alibaba.maxgraph.compiler.logical.VertexIdManager in project GraphScope by alibaba.
the class PropFillTreeNode method buildLogicalQueryPlan.
@Override
public LogicalSubQueryPlan buildLogicalQueryPlan(ContextManager contextManager) {
TreeNodeLabelManager labelManager = contextManager.getTreeNodeLabelManager();
VertexIdManager vertexIdManager = contextManager.getVertexIdManager();
Message.Value.Builder argumentBuilder = Message.Value.newBuilder();
propKeyList.forEach(v -> argumentBuilder.addIntValueList(SchemaUtils.getPropId(v, schema)));
ProcessorFunction processorFunction = new ProcessorFunction(QueryFlowOuterClass.OperatorType.PROP_FILL, argumentBuilder);
if (getInputNode() instanceof SourceVertexTreeNode) {
return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager, new LogicalEdge(EdgeShuffleType.FORWARD));
} else {
return parseSingleUnaryVertex(vertexIdManager, labelManager, processorFunction, contextManager);
}
}
Aggregations