use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode 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;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitChooseStep.
private TreeNode visitChooseStep(ChooseStep step, TreeNode prev) {
List<org.javatuples.Pair<Traversal.Admin, Traversal.Admin<?, ?>>> traversalOptions = ReflectionUtils.getFieldValue(BranchStep.class, step, "traversalOptions");
Traversal.Admin<?, ?> trueOptionTraversal, falseOptionTraversal;
if (traversalOptions.size() == 2 && (trueOptionTraversal = getTraversalOption(true, traversalOptions)) != null && (falseOptionTraversal = getTraversalOption(false, traversalOptions)) != null) {
boolean saveFlag = this.rootPathFlag;
this.rootPathFlag = false;
Traversal.Admin<?, ?> branchTraversal = ReflectionUtils.getFieldValue(BranchStep.class, step, "branchTraversal");
TreeNode branchNode = branchTraversal == null ? null : travelTraversalAdmin(branchTraversal, new SourceDelegateNode(prev, schema));
this.rootPathFlag = saveFlag;
TreeNode trueOptionNode = travelTraversalAdmin(trueOptionTraversal, new SourceDelegateNode(prev, schema));
TreeNode falseOptionNode = travelTraversalAdmin(falseOptionTraversal, new SourceDelegateNode(prev, schema));
return new OptionalTreeNode(prev, schema, branchNode, trueOptionNode, falseOptionNode);
} else {
throw new UnsupportedOperationException("Not support choose yet.");
}
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitNotStep.
private TreeNode visitNotStep(NotStep step, TreeNode prev) {
Traversal.Admin<?, ?> notTraversal = ReflectionUtils.getFieldValue(NotStep.class, step, "notTraversal");
TreeNode notTreeNode;
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
notTreeNode = travelTraversalAdmin(notTraversal, new SourceDelegateNode(prev, schema));
rootPathFlag = saveFlag;
return new NotTreeNode(prev, schema, notTreeNode);
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitWherePredicateStep.
private TreeNode visitWherePredicateStep(WherePredicateStep step, TreeNode prev) {
Optional<String> startKeyOptional = step.getStartKey();
Optional<P<?>> predicateOptional = step.getPredicate();
List<String> selectKeys = ReflectionUtils.getFieldValue(WherePredicateStep.class, step, "selectKeys");
List<Traversal.Admin<?, ?>> ringTraversalList = step.getLocalChildren();
String sourceKey = startKeyOptional.isPresent() ? startKeyOptional.get() : null;
String targetKey = selectKeys.iterator().next();
WherePredicateTreeNode wherePredicateTreeNode = new WherePredicateTreeNode(prev, schema, predicateOptional.get(), sourceKey, ringTraversalList.isEmpty());
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
if (!ringTraversalList.isEmpty()) {
Traversal.Admin<?, ?> sourceAdmin = ringTraversalList.get(0);
Traversal.Admin<?, ?> targetAdmin = ringTraversalList.get(1 % ringTraversalList.size());
TreeNode sourceNode = travelTraversalAdmin(sourceAdmin, null == sourceKey ? new SourceDelegateNode(prev, schema) : new SelectOneTreeNode(new SourceDelegateNode(prev, schema), sourceKey, Pop.last, treeNodeLabelManager.getTreeNodeList(sourceKey), schema));
TreeNode targetNode = travelTraversalAdmin(targetAdmin, new SelectOneTreeNode(new SourceDelegateNode(prev, schema), targetKey, Pop.last, treeNodeLabelManager.getTreeNodeList(targetKey), schema));
wherePredicateTreeNode.setSourceTargetNode(sourceNode, targetNode);
}
rootPathFlag = saveFlag;
return wherePredicateTreeNode;
}
use of com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode in project GraphScope by alibaba.
the class TreeBuilder method visitVertexByModulatingStep.
private TreeNode visitVertexByModulatingStep(VertexByModulatingStep step, TreeNode prev) {
checkNotNull(prev);
Direction direction = step.getDirection();
String[] edgeLabels = step.getEdgeLabels();
SampleGlobalStep sampleGlobalStep = step.getSampleGlobalStep();
SampleNode sampleNode;
if (step.returnsVertex()) {
sampleNode = new VertexTreeNode(prev, direction, edgeLabels, schema);
} else {
sampleNode = new EdgeTreeNode(prev, direction, edgeLabels, schema);
}
if (null != sampleGlobalStep) {
int amountToSample = ReflectionUtils.getFieldValue(SampleGlobalStep.class, sampleGlobalStep, "amountToSample");
Traversal.Admin<?, ?> probabilityTraversal = ReflectionUtils.getFieldValue(SampleGlobalStep.class, sampleGlobalStep, "probabilityTraversal");
boolean saveFlag = rootPathFlag;
rootPathFlag = false;
String probabilityProperty = null;
TreeNode probabilityTreeNode = travelTraversalAdmin(probabilityTraversal, new SourceDelegateNode((TreeNode) sampleNode, schema));
if (probabilityTreeNode instanceof SourceTreeNode) {
probabilityProperty = "";
} else if ((UnaryTreeNode.class.cast(probabilityTreeNode).getInputNode() instanceof SourceTreeNode && (probabilityTreeNode instanceof PropertyNode))) {
probabilityProperty = PropertyNode.class.cast(probabilityTreeNode).getPropKeyList().iterator().next();
} else {
throw new IllegalArgumentException("Only support sample by property here.");
}
rootPathFlag = saveFlag;
sampleNode.setSample(amountToSample, probabilityProperty);
}
return (TreeNode) sampleNode;
}
Aggregations