use of org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep 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