Skip to content

Commit ac41e9c

Browse files
committed
comments
1 parent a5ef3bd commit ac41e9c

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/SampleOperator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public String describe() {
4141
}
4242

4343
private final Deque<Page> outputPages;
44+
45+
/**
46+
* At any time this iterator will point to be next document that still
47+
* needs to be sampled. If this document is on the current page, it's
48+
* added to the output and the iterator is advanced. It the document is
49+
* not on the current page, the current page is finished and the index
50+
* is used for the next page.
51+
*/
4452
private final RandomSamplingQuery.RandomSamplingIterator randomSamplingIterator;
4553
private boolean finished;
4654

@@ -55,6 +63,7 @@ private SampleOperator(double probability, int seed) {
5563
outputPages = new LinkedList<>();
5664
SplittableRandom random = new SplittableRandom(seed);
5765
randomSamplingIterator = new RandomSamplingQuery.RandomSamplingIterator(Integer.MAX_VALUE, probability, random::nextInt);
66+
// Initialize the iterator to the next document that needs to be sampled.
5867
randomSamplingIterator.nextDoc();
5968
}
6069

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/RestSampleTestCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ protected boolean matchesSafely(List<List<Integer>> lists) {
7575
}
7676
};
7777

78+
/**
79+
* This tests sampling in the Lucene query.
80+
*/
7881
public void testSample_withFrom() throws IOException {
7982
createTestIndex();
8083
test("FROM sample-test-index | SAMPLE 0.5 | LIMIT 1000");
8184
deleteTestIndex();
8285
}
8386

87+
/**
88+
* This tests sampling in the ES|QL operator.
89+
*/
8490
public void testSample_withRow() throws IOException {
8591
List<Integer> numbers = IntStream.range(0, 999).boxed().toList();
8692
test("ROW value = " + numbers + " | MV_EXPAND value | SAMPLE 0.5 | LIMIT 1000");

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Count.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ private Count(Source source, Expression field, Expression filter, boolean isSamp
108108

109109
private Count(StreamInput in) throws IOException {
110110
super(in);
111+
// isSampleCorrected is only used during query optimization to mark
112+
// whether this function has been processed. Hence there's no need to
113+
// serialize it.
111114
this.isSampleCorrected = false;
112115
}
113116

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Sum.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ private Sum(Source source, Expression field, Expression filter, boolean isSample
7979

8080
private Sum(StreamInput in) throws IOException {
8181
super(in);
82+
// isSampleCorrected is only used during query optimization to mark
83+
// whether this function has been processed. Hence there's no need to
84+
// serialize it.
8285
this.isSampleCorrected = false;
8386
}
8487

0 commit comments

Comments
 (0)