use of com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode in project GraphScope by alibaba.
the class NodeLabelList method buildNodeLabel.
/**
* Build label list of current node from parent node, tree node and schema
*
* @param parentNodeLabel The given parent node
* @param treeNode The given tree node
* @param graphSchema The given graph schema
* @return The result node label list
*/
public static NodeLabelList buildNodeLabel(NodeLabelList parentNodeLabel, TreeNode treeNode, GraphSchema graphSchema) {
NodeLabelList nodeLabelList = new NodeLabelList();
if (null == parentNodeLabel) {
BaseTreeNode baseTreeNode = (BaseTreeNode) treeNode;
final Set<String> labelList = Sets.newHashSet();
baseTreeNode.getHasContainerList().forEach(v -> {
if (StringUtils.equals(v.getKey(), T.label.getAccessor())) {
if (v.getBiPredicate() instanceof Compare && v.getBiPredicate() == Compare.eq) {
labelList.add(v.getValue().toString());
} else if (v.getBiPredicate() instanceof Contains && v.getBiPredicate() == Contains.within) {
List<String> labelValueList = (List<String>) v.getValue();
labelList.addAll(labelValueList);
} else {
throw new IllegalArgumentException("Not support label compare " + v.toString());
}
}
});
if (treeNode instanceof SourceVertexTreeNode) {
List<String> vertexLabelList = graphSchema.getVertexList().stream().map(GraphElement::getLabel).collect(Collectors.toList());
Set<String> resultLabelList;
if (labelList.isEmpty()) {
resultLabelList = Sets.newHashSet(vertexLabelList);
} else {
resultLabelList = labelList.stream().filter(vertexLabelList::contains).collect(Collectors.toSet());
}
nodeLabelList.addVertexLabel(resultLabelList);
} else if (treeNode instanceof SourceEdgeTreeNode) {
List<String> edgeLabelList = graphSchema.getEdgeList().stream().map(GraphElement::getLabel).collect(Collectors.toList());
Set<String> resultLabelList;
if (labelList.isEmpty()) {
resultLabelList = Sets.newHashSet(edgeLabelList);
} else {
resultLabelList = labelList.stream().filter(edgeLabelList::contains).collect(Collectors.toSet());
}
nodeLabelList.addEdgeLabel(resultLabelList);
} else {
nodeLabelList.enableUnknown();
}
} else {
Set<String> parentVertexLabelList = Sets.newHashSet();
Set<String> parentEdgeLabelList = Sets.newHashSet();
if (parentNodeLabel.isUnknownFlag()) {
parentVertexLabelList.addAll(graphSchema.getVertexList().stream().map(GraphElement::getLabel).collect(Collectors.toList()));
parentEdgeLabelList.addAll(graphSchema.getEdgeList().stream().map(GraphElement::getLabel).collect(Collectors.toList()));
} else {
parentVertexLabelList.addAll(parentNodeLabel.getVertexLabelList());
parentEdgeLabelList.addAll(parentNodeLabel.getEdgeLabelList());
}
if (treeNode instanceof VertexTreeNode) {
VertexTreeNode vertexTreeNode = (VertexTreeNode) treeNode;
Direction direction = vertexTreeNode.getDirection();
nodeLabelList.addVertexLabel(computeVertexLabelList(parentVertexLabelList, direction, vertexTreeNode.getEdgeLabels(), graphSchema));
} else if (treeNode instanceof EdgeTreeNode) {
EdgeTreeNode edgeTreeNode = (EdgeTreeNode) treeNode;
Direction direction = edgeTreeNode.getDirection();
nodeLabelList.addEdgeLabel(computeEdgeLabelList(parentVertexLabelList, direction, edgeTreeNode.getEdgeLabels(), graphSchema));
} else if (treeNode instanceof EdgeVertexTreeNode) {
EdgeVertexTreeNode edgeVertexTreeNode = (EdgeVertexTreeNode) treeNode;
Map<String, Pair<Set<String>, Set<String>>> edgeSourceTargetPairList = getEdgeSourceTargetPairList(parentEdgeLabelList.toArray(new String[0]), graphSchema);
Direction direction = edgeVertexTreeNode.getDirection();
edgeSourceTargetPairList.forEach((key, value) -> {
switch(direction) {
case OUT:
{
nodeLabelList.addVertexLabel(value.getLeft());
break;
}
case IN:
{
nodeLabelList.addVertexLabel(value.getRight());
break;
}
case BOTH:
{
nodeLabelList.addVertexLabel(value.getLeft());
nodeLabelList.addVertexLabel(value.getRight());
break;
}
}
});
} else if (treeNode instanceof EdgeOtherVertexTreeNode) {
Map<String, Pair<Set<String>, Set<String>>> edgeSourceTargetPairList = getEdgeSourceTargetPairList(parentEdgeLabelList.toArray(new String[0]), graphSchema);
edgeSourceTargetPairList.forEach((key, value) -> {
nodeLabelList.addVertexLabel(value.getLeft());
nodeLabelList.addVertexLabel(value.getRight());
});
} else {
nodeLabelList.enableUnknown();
}
}
return nodeLabelList;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode 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);
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode in project GraphScope by alibaba.
the class TreeBuilder method visitAndStep.
private TreeNode visitAndStep(AndStep step, TreeNode prev) {
List<Traversal.Admin<?, ?>> traversals = ReflectionUtils.getFieldValue(ConnectiveStep.class, step, "traversals");
List<TreeNode> andTreeNodeList = Lists.newArrayList();
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
traversals.forEach(v -> {
TreeNode treeNode = travelTraversalAdmin(v, new SourceDelegateNode(prev, schema));
if (treeNode instanceof HasTreeNode) {
TreeNode hasInputNode = ((HasTreeNode) treeNode).getInputNode();
if (hasInputNode instanceof SourceVertexTreeNode || hasInputNode instanceof SourceEdgeTreeNode || hasInputNode instanceof EdgeTreeNode) {
prev.addHasContainerList(((HasTreeNode) treeNode).getHasContainerList());
} else {
andTreeNodeList.add(treeNode);
}
} else {
andTreeNodeList.add(treeNode);
}
});
rootPathFlag = saveFlag;
if (andTreeNodeList.isEmpty()) {
return prev;
} else {
AndTreeNode andTreeNode = new AndTreeNode(prev, schema);
andTreeNode.getAndTreeNodeList().addAll(andTreeNodeList);
return andTreeNode;
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode in project GraphScope by alibaba.
the class TreeBuilder method visitLambdaFilterStep.
private TreeNode visitLambdaFilterStep(LambdaFilterStep step, TreeNode prev) {
if (step.getPredicate() instanceof P) {
Predicate predicate = step.getPredicate();
List<HasContainer> hasContainerList = Lists.newArrayList();
hasContainerList.add(convertPredicateToHasContainer(predicate, prev.getOutputValueType()));
if (prev instanceof SourceVertexTreeNode || prev instanceof SourceEdgeTreeNode || prev instanceof EdgeTreeNode) {
prev.addHasContainerList(hasContainerList);
return prev;
} else {
return new HasTreeNode(prev, hasContainerList, schema);
}
} else {
if (this.lambdaEnableFlag) {
return new LambdaFilterTreeNode(prev, schema, buildLambdaIndex(step));
} else {
throw new UnsupportedOperationException("Not support lambda filter yet");
}
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode in project GraphScope by alibaba.
the class TreeBuilder method visitRangeGlobalStep.
private TreeNode visitRangeGlobalStep(RangeGlobalStep step, TreeNode prev) {
long low = ReflectionUtils.getFieldValue(RangeGlobalStep.class, step, "low");
long high = ReflectionUtils.getFieldValue(RangeGlobalStep.class, step, "high");
boolean bypass = ReflectionUtils.getFieldValue(RangeGlobalStep.class, step, "bypass");
if (bypass) {
return prev;
}
TreeNode lastRangeNode = prev;
while (lastRangeNode.getNodeType() == NodeType.MAP) {
lastRangeNode = UnaryTreeNode.class.cast(lastRangeNode).getInputNode();
}
if (lastRangeNode instanceof OrderGlobalTreeNode) {
lastRangeNode.setRangeLimit(low, high, rootPathFlag);
return prev;
} else if (lastRangeNode.getNodeType() == NodeType.FLATMAP || lastRangeNode instanceof SourceVertexTreeNode || lastRangeNode instanceof SourceEdgeTreeNode) {
lastRangeNode.setRangeLimit(0, high - low, rootPathFlag);
long tmplow = low;
low = 0;
high = high - tmplow;
}
TreeNode outputNode = lastRangeNode.getOutputNode();
RangeGlobalTreeNode rangeGlobalTreeNode = new RangeGlobalTreeNode(lastRangeNode, schema, low, high);
if (null == outputNode) {
return rangeGlobalTreeNode;
} else {
UnaryTreeNode.class.cast(outputNode).setInputNode(rangeGlobalTreeNode);
return prev;
}
}
Aggregations