Search in sources :

Example 1 with SampleGlobalStep

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;
}
Also used : SampleGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) CustomAggregationListTraversal(com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) SourceDelegateNode(com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) EstimateCountTreeNode(com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode) SourceEdgeTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) SourceCreateGraphTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode) PropertyNode(com.alibaba.maxgraph.compiler.tree.addition.PropertyNode) SampleNode(com.alibaba.maxgraph.compiler.tree.addition.SampleNode)

Aggregations

PropertyNode (com.alibaba.maxgraph.compiler.tree.addition.PropertyNode)1 SampleNode (com.alibaba.maxgraph.compiler.tree.addition.SampleNode)1 EstimateCountTreeNode (com.alibaba.maxgraph.compiler.tree.source.EstimateCountTreeNode)1 SourceCreateGraphTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceCreateGraphTreeNode)1 SourceDelegateNode (com.alibaba.maxgraph.compiler.tree.source.SourceDelegateNode)1 SourceEdgeTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceEdgeTreeNode)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)1 CustomAggregationListTraversal (com.alibaba.maxgraph.sdkcommon.compiler.custom.aggregate.CustomAggregationListTraversal)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 SampleGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1