1313import org .apache .lucene .document .Field ;
1414import org .apache .lucene .document .KeywordField ;
1515import org .apache .lucene .document .LongField ;
16+ import org .apache .lucene .document .SortedNumericDocValuesField ;
17+ import org .apache .lucene .document .SortedSetDocValuesField ;
1618import org .apache .lucene .index .IndexReader ;
1719import org .apache .lucene .index .IndexableField ;
1820import org .apache .lucene .search .IndexSearcher ;
1921import org .apache .lucene .search .MatchAllDocsQuery ;
2022import org .apache .lucene .search .Query ;
2123import org .apache .lucene .store .Directory ;
2224import org .apache .lucene .tests .index .RandomIndexWriter ;
25+ import org .apache .lucene .util .BytesRef ;
26+ import org .apache .lucene .util .NumericUtils ;
2327import org .elasticsearch .compute .operator .DriverContext ;
2428import org .elasticsearch .compute .operator .Warnings ;
2529import org .elasticsearch .compute .querydsl .query .SingleValueMatchQuery ;
@@ -55,7 +59,9 @@ public static List<Object[]> params() {
5559 params .add (new Object [] { new SneakyTwo (fieldType ) });
5660 for (boolean multivaluedField : new boolean [] { true , false }) {
5761 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+ }
5965 }
6066 }
6167 }
@@ -122,10 +128,16 @@ private void runCase(List<List<Object>> fieldValues, int count) {
122128 }
123129 }
124130
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 {
126134 @ Override
127135 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+ }
129141 }
130142
131143 @ Override
@@ -134,7 +146,7 @@ public List<List<Object>> build(RandomIndexWriter iw) throws IOException {
134146 for (int i = 0 ; i < count ; i ++) {
135147 List <Object > values = values (i );
136148 docs .add (values );
137- iw .addDocument (docFor (values ));
149+ iw .addDocument (docFor (values , docValuesOnly ));
138150 }
139151 return docs ;
140152 }
@@ -187,8 +199,8 @@ public List<List<Object>> build(RandomIndexWriter iw) throws IOException {
187199 Object second = randomValue (fieldType );
188200 List <Object > justFirst = List .of (first );
189201 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 ));
192204 return List .of (justFirst , both );
193205 }
194206
@@ -212,16 +224,26 @@ private static Object randomValue(String fieldType) {
212224 };
213225 }
214226
215- private static List <IndexableField > docFor (Iterable <Object > values ) {
227+ private static List <IndexableField > docFor (Iterable <Object > values , boolean docValuesOnly ) {
216228 List <IndexableField > fields = new ArrayList <>();
217229 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+ }
225247 }
226248 return fields ;
227249 }
0 commit comments