13
13
import org .apache .lucene .document .Field ;
14
14
import org .apache .lucene .document .KeywordField ;
15
15
import org .apache .lucene .document .LongField ;
16
+ import org .apache .lucene .document .SortedNumericDocValuesField ;
17
+ import org .apache .lucene .document .SortedSetDocValuesField ;
16
18
import org .apache .lucene .index .IndexReader ;
17
19
import org .apache .lucene .index .IndexableField ;
18
20
import org .apache .lucene .search .IndexSearcher ;
19
21
import org .apache .lucene .search .MatchAllDocsQuery ;
20
22
import org .apache .lucene .search .Query ;
21
23
import org .apache .lucene .store .Directory ;
22
24
import org .apache .lucene .tests .index .RandomIndexWriter ;
25
+ import org .apache .lucene .util .BytesRef ;
26
+ import org .apache .lucene .util .NumericUtils ;
23
27
import org .elasticsearch .compute .operator .DriverContext ;
24
28
import org .elasticsearch .compute .operator .Warnings ;
25
29
import org .elasticsearch .compute .querydsl .query .SingleValueMatchQuery ;
@@ -55,7 +59,9 @@ public static List<Object[]> params() {
55
59
params .add (new Object [] { new SneakyTwo (fieldType ) });
56
60
for (boolean multivaluedField : new boolean [] { true , false }) {
57
61
for (boolean allowEmpty : new boolean [] { true , false }) {
58
- params .add (new Object [] { new StandardSetup (fieldType , multivaluedField , allowEmpty , 100 ) });
62
+ for (boolean docValuesOnly : new boolean [] { true , false }) {
63
+ params .add (new Object [] { new StandardSetup (fieldType , multivaluedField , docValuesOnly , allowEmpty , 100 ) });
64
+ }
59
65
}
60
66
}
61
67
}
@@ -122,10 +128,16 @@ private void runCase(List<List<Object>> fieldValues, int count) {
122
128
}
123
129
}
124
130
125
- private record StandardSetup (String fieldType , boolean multivaluedField , boolean empty , int count ) implements Setup {
131
+ private record StandardSetup (String fieldType , boolean multivaluedField , boolean docValuesOnly , boolean empty , int count )
132
+ implements
133
+ Setup {
126
134
@ Override
127
135
public XContentBuilder mapping (XContentBuilder builder ) throws IOException {
128
- return builder .startObject ("foo" ).field ("type" , fieldType ).endObject ();
136
+ if (docValuesOnly ) {
137
+ return builder .startObject ("foo" ).field ("type" , fieldType ).field ("index" , false ).endObject ();
138
+ } else {
139
+ return builder .startObject ("foo" ).field ("type" , fieldType ).endObject ();
140
+ }
129
141
}
130
142
131
143
@ Override
@@ -134,7 +146,7 @@ public List<List<Object>> build(RandomIndexWriter iw) throws IOException {
134
146
for (int i = 0 ; i < count ; i ++) {
135
147
List <Object > values = values (i );
136
148
docs .add (values );
137
- iw .addDocument (docFor (values ));
149
+ iw .addDocument (docFor (values , docValuesOnly ));
138
150
}
139
151
return docs ;
140
152
}
@@ -187,8 +199,8 @@ public List<List<Object>> build(RandomIndexWriter iw) throws IOException {
187
199
Object second = randomValue (fieldType );
188
200
List <Object > justFirst = List .of (first );
189
201
List <Object > both = List .of (first , second );
190
- iw .addDocument (docFor (justFirst ));
191
- iw .addDocument (docFor (both ));
202
+ iw .addDocument (docFor (justFirst , false ));
203
+ iw .addDocument (docFor (both , false ));
192
204
return List .of (justFirst , both );
193
205
}
194
206
@@ -212,16 +224,26 @@ private static Object randomValue(String fieldType) {
212
224
};
213
225
}
214
226
215
- private static List <IndexableField > docFor (Iterable <Object > values ) {
227
+ private static List <IndexableField > docFor (Iterable <Object > values , boolean docValuesOnly ) {
216
228
List <IndexableField > fields = new ArrayList <>();
217
229
for (Object v : values ) {
218
- fields .add (switch (v ) {
219
- case Double n -> new DoubleField ("foo" , n , Field .Store .NO );
220
- case Float n -> new DoubleField ("foo" , n , Field .Store .NO );
221
- case Number n -> new LongField ("foo" , n .longValue (), Field .Store .NO );
222
- case String s -> new KeywordField ("foo" , s , Field .Store .NO );
223
- default -> throw new UnsupportedOperationException ();
224
- });
230
+ if (docValuesOnly ) {
231
+ fields .add (switch (v ) {
232
+ case Double n -> new SortedNumericDocValuesField ("foo" , NumericUtils .doubleToSortableLong (n ));
233
+ case Float n -> new SortedNumericDocValuesField ("foo" , NumericUtils .doubleToSortableLong (n ));
234
+ case Number n -> new SortedNumericDocValuesField ("foo" , n .longValue ());
235
+ case String s -> new SortedSetDocValuesField ("foo" , new BytesRef (s ));
236
+ default -> throw new UnsupportedOperationException ();
237
+ });
238
+ } else {
239
+ fields .add (switch (v ) {
240
+ case Double n -> new DoubleField ("foo" , n , Field .Store .NO );
241
+ case Float n -> new DoubleField ("foo" , n , Field .Store .NO );
242
+ case Number n -> new LongField ("foo" , n .longValue (), Field .Store .NO );
243
+ case String s -> new KeywordField ("foo" , s , Field .Store .NO );
244
+ default -> throw new UnsupportedOperationException ();
245
+ });
246
+ }
225
247
}
226
248
return fields ;
227
249
}
0 commit comments