15
15
import org .apache .lucene .codecs .Codec ;
16
16
import org .apache .lucene .codecs .lucene101 .Lucene101Codec ;
17
17
import org .apache .lucene .document .Document ;
18
+ import org .apache .lucene .document .Field ;
19
+ import org .apache .lucene .document .LongField ;
18
20
import org .apache .lucene .document .SortedNumericDocValuesField ;
19
21
import org .apache .lucene .index .DirectoryReader ;
20
22
import org .apache .lucene .index .IndexWriterConfig ;
44
46
import org .opensearch .index .mapper .MapperService ;
45
47
import org .opensearch .index .mapper .NumberFieldMapper ;
46
48
import org .opensearch .index .query .QueryBuilder ;
49
+ import org .opensearch .index .query .QueryBuilders ;
47
50
import org .opensearch .index .query .QueryShardContext ;
48
51
import org .opensearch .index .query .TermQueryBuilder ;
49
52
import org .opensearch .search .aggregations .AggregationBuilder ;
@@ -130,11 +133,11 @@ public void testStarTreeDocValues() throws IOException {
130
133
Document doc = new Document ();
131
134
if (random .nextBoolean ()) {
132
135
val = random .nextInt (10 ) - 5 ; // Random long between -5 and 4
133
- doc .add (new SortedNumericDocValuesField (SNDV , val ));
136
+ doc .add (new LongField (SNDV , val , Field . Store . YES ));
134
137
}
135
138
if (random .nextBoolean ()) {
136
139
val = random .nextInt (20 ) - 10 ; // Random long between -10 and 9
137
- doc .add (new SortedNumericDocValuesField (DV , val ));
140
+ doc .add (new LongField (DV , val , Field . Store . YES ));
138
141
}
139
142
if (random .nextBoolean ()) {
140
143
val = random .nextInt (50 ); // Random long between 0 and 49
@@ -157,6 +160,18 @@ public void testStarTreeDocValues() throws IOException {
157
160
IndexSearcher indexSearcher = newSearcher (reader , false , false );
158
161
CompositeIndexReader starTreeDocValuesReader = (CompositeIndexReader ) reader .getDocValuesReader ();
159
162
163
+ MapperService mapperService = mapperServiceMock ();
164
+ CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService ();
165
+ when (mapperService .fieldType (SNDV )).thenReturn (new NumberFieldMapper .NumberFieldType (SNDV , NumberFieldMapper .NumberType .LONG ));
166
+ when (mapperService .fieldType (DV )).thenReturn (new NumberFieldMapper .NumberFieldType (DV , NumberFieldMapper .NumberType .LONG ));
167
+ QueryShardContext queryShardContext = queryShardContextMock (
168
+ indexSearcher ,
169
+ mapperService ,
170
+ createIndexSettings (),
171
+ circuitBreakerService ,
172
+ new MockBigArrays (new MockPageCacheRecycler (Settings .EMPTY ), circuitBreakerService ).withCircuitBreaking ()
173
+ );
174
+
160
175
List <CompositeIndexFieldInfo > compositeIndexFields = starTreeDocValuesReader .getCompositeIndexFields ();
161
176
CompositeIndexFieldInfo starTree = compositeIndexFields .get (0 );
162
177
@@ -173,6 +188,7 @@ public void testStarTreeDocValues() throws IOException {
173
188
Query query = new MatchAllDocsQuery ();
174
189
// match-all query
175
190
QueryBuilder queryBuilder = null ; // no predicates
191
+ QueryBuilder rangeQueryBuilder = null ;
176
192
testCase (
177
193
indexSearcher ,
178
194
query ,
@@ -222,75 +238,70 @@ public void testStarTreeDocValues() throws IOException {
222
238
// Numeric-terms query
223
239
for (int cases = 0 ; cases < 100 ; cases ++) {
224
240
String queryField ;
225
- long queryValue ;
241
+ long queryLow , queryHigh ;
226
242
if (randomBoolean ()) {
227
243
queryField = SNDV ;
228
- queryValue = random .nextInt (10 );
244
+ queryLow = random .nextInt (10 );
229
245
} else {
230
246
queryField = DV ;
231
- queryValue = random .nextInt (20 ) - 15 ;
247
+ queryLow = random .nextInt (20 ) - 15 ;
248
+ }
249
+ queryHigh = random .nextInt (10 );
250
+
251
+ query = SortedNumericDocValuesField .newSlowExactQuery (queryField , queryLow );
252
+ queryBuilder = new TermQueryBuilder (queryField , queryLow );
253
+ rangeQueryBuilder = QueryBuilders .rangeQuery (queryField ).gte (queryLow ).lte (queryHigh );
254
+
255
+ for (QueryBuilder qb : new QueryBuilder [] { queryBuilder , rangeQueryBuilder }) {
256
+ query = qb .toQuery (queryShardContext );
257
+ testCase (
258
+ indexSearcher ,
259
+ query ,
260
+ qb ,
261
+ sumAggregationBuilder ,
262
+ starTree ,
263
+ supportedDimensions ,
264
+ verifyAggregation (InternalSum ::getValue )
265
+ );
266
+ testCase (
267
+ indexSearcher ,
268
+ query ,
269
+ qb ,
270
+ maxAggregationBuilder ,
271
+ starTree ,
272
+ supportedDimensions ,
273
+ verifyAggregation (InternalMax ::getValue )
274
+ );
275
+ testCase (
276
+ indexSearcher ,
277
+ query ,
278
+ qb ,
279
+ minAggregationBuilder ,
280
+ starTree ,
281
+ supportedDimensions ,
282
+ verifyAggregation (InternalMin ::getValue )
283
+ );
284
+ testCase (
285
+ indexSearcher ,
286
+ query ,
287
+ qb ,
288
+ valueCountAggregationBuilder ,
289
+ starTree ,
290
+ supportedDimensions ,
291
+ verifyAggregation (InternalValueCount ::getValue )
292
+ );
293
+ testCase (
294
+ indexSearcher ,
295
+ query ,
296
+ qb ,
297
+ avgAggregationBuilder ,
298
+ starTree ,
299
+ supportedDimensions ,
300
+ verifyAggregation (InternalAvg ::getValue )
301
+ );
232
302
}
233
-
234
- query = SortedNumericDocValuesField .newSlowExactQuery (queryField , queryValue );
235
- queryBuilder = new TermQueryBuilder (queryField , queryValue );
236
-
237
- testCase (
238
- indexSearcher ,
239
- query ,
240
- queryBuilder ,
241
- sumAggregationBuilder ,
242
- starTree ,
243
- supportedDimensions ,
244
- verifyAggregation (InternalSum ::getValue )
245
- );
246
- testCase (
247
- indexSearcher ,
248
- query ,
249
- queryBuilder ,
250
- maxAggregationBuilder ,
251
- starTree ,
252
- supportedDimensions ,
253
- verifyAggregation (InternalMax ::getValue )
254
- );
255
- testCase (
256
- indexSearcher ,
257
- query ,
258
- queryBuilder ,
259
- minAggregationBuilder ,
260
- starTree ,
261
- supportedDimensions ,
262
- verifyAggregation (InternalMin ::getValue )
263
- );
264
- testCase (
265
- indexSearcher ,
266
- query ,
267
- queryBuilder ,
268
- valueCountAggregationBuilder ,
269
- starTree ,
270
- supportedDimensions ,
271
- verifyAggregation (InternalValueCount ::getValue )
272
- );
273
- testCase (
274
- indexSearcher ,
275
- query ,
276
- queryBuilder ,
277
- avgAggregationBuilder ,
278
- starTree ,
279
- supportedDimensions ,
280
- verifyAggregation (InternalAvg ::getValue )
281
- );
282
303
}
283
304
284
- CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService ();
285
-
286
- QueryShardContext queryShardContext = queryShardContextMock (
287
- indexSearcher ,
288
- mapperServiceMock (),
289
- createIndexSettings (),
290
- circuitBreakerService ,
291
- new MockBigArrays (new MockPageCacheRecycler (Settings .EMPTY ), circuitBreakerService ).withCircuitBreaking ()
292
- );
293
-
294
305
MetricAggregatorFactory aggregatorFactory = mock (MetricAggregatorFactory .class );
295
306
when (aggregatorFactory .getSubFactories ()).thenReturn (AggregatorFactories .EMPTY );
296
307
when (aggregatorFactory .getField ()).thenReturn (FIELD_NAME );
@@ -300,7 +311,7 @@ public void testStarTreeDocValues() throws IOException {
300
311
testCase (
301
312
indexSearcher ,
302
313
query ,
303
- queryBuilder ,
314
+ rangeQueryBuilder ,
304
315
sumAggregationBuilder ,
305
316
starTree ,
306
317
supportedDimensions ,
@@ -315,7 +326,7 @@ public void testStarTreeDocValues() throws IOException {
315
326
testCase (
316
327
indexSearcher ,
317
328
query ,
318
- queryBuilder ,
329
+ rangeQueryBuilder ,
319
330
invalidFieldSumAggBuilder ,
320
331
starTree ,
321
332
supportedDimensions ,
@@ -329,7 +340,7 @@ public void testStarTreeDocValues() throws IOException {
329
340
testCase (
330
341
indexSearcher ,
331
342
query ,
332
- queryBuilder ,
343
+ rangeQueryBuilder ,
333
344
sumAggregationBuilder ,
334
345
starTree ,
335
346
supportedDimensions ,
@@ -343,7 +354,7 @@ public void testStarTreeDocValues() throws IOException {
343
354
testCase (
344
355
indexSearcher ,
345
356
query ,
346
- queryBuilder ,
357
+ rangeQueryBuilder ,
347
358
sumAggregationBuilder ,
348
359
starTree ,
349
360
supportedDimensions ,
@@ -361,7 +372,7 @@ public void testStarTreeDocValues() throws IOException {
361
372
testCase (
362
373
indexSearcher ,
363
374
query ,
364
- queryBuilder ,
375
+ rangeQueryBuilder ,
365
376
sumAggregationBuilder ,
366
377
starTree ,
367
378
supportedDimensions ,
@@ -375,7 +386,7 @@ public void testStarTreeDocValues() throws IOException {
375
386
testCase (
376
387
indexSearcher ,
377
388
query ,
378
- queryBuilder ,
389
+ rangeQueryBuilder ,
379
390
sumAggregationBuilder ,
380
391
starTree ,
381
392
supportedDimensions ,
@@ -389,6 +400,10 @@ public void testStarTreeDocValues() throws IOException {
389
400
directory .close ();
390
401
}
391
402
403
+ public void testStarTreeDocValues2 () throws IOException {
404
+
405
+ }
406
+
392
407
<T , R extends Number > BiConsumer <T , T > verifyAggregation (Function <T , R > valueExtractor ) {
393
408
return (expectedAggregation , actualAggregation ) -> assertEquals (
394
409
valueExtractor .apply (expectedAggregation ).doubleValue (),
0 commit comments