2424import org .elasticsearch .compute .data .DoubleVector ;
2525import org .elasticsearch .compute .data .LongBlock ;
2626import org .elasticsearch .compute .data .LongVector ;
27+ import org .elasticsearch .compute .data .OrdinalBytesRefVector ;
2728import org .elasticsearch .compute .data .Page ;
2829import org .elasticsearch .compute .operator .DriverContext ;
2930import org .elasticsearch .compute .operator .EvalOperator ;
@@ -127,7 +128,9 @@ static void selfTest() {
127128 "mv_min_ascending" ,
128129 "rlike" ,
129130 "to_lower" ,
130- "to_upper" }
131+ "to_lower_ords" ,
132+ "to_upper" ,
133+ "to_upper_ords" }
131134 )
132135 public String operation ;
133136
@@ -235,12 +238,12 @@ private static EvalOperator.ExpressionEvaluator evaluator(String operation) {
235238 RLike rlike = new RLike (Source .EMPTY , keywordField , new RLikePattern (".ar" ));
236239 yield EvalMapper .toEvaluator (FOLD_CONTEXT , rlike , layout (keywordField )).get (driverContext );
237240 }
238- case "to_lower" -> {
241+ case "to_lower" , "to_lower_ords" -> {
239242 FieldAttribute keywordField = keywordField ();
240243 ToLower toLower = new ToLower (Source .EMPTY , keywordField , configuration ());
241244 yield EvalMapper .toEvaluator (FOLD_CONTEXT , toLower , layout (keywordField )).get (driverContext );
242245 }
243- case "to_upper" -> {
246+ case "to_upper" , "to_upper_ords" -> {
244247 FieldAttribute keywordField = keywordField ();
245248 ToUpper toUpper = new ToUpper (Source .EMPTY , keywordField , configuration ());
246249 yield EvalMapper .toEvaluator (FOLD_CONTEXT , toUpper , layout (keywordField )).get (driverContext );
@@ -414,13 +417,15 @@ private static void checkExpected(String operation, Page actual) {
414417 }
415418 }
416419 }
417- case "to_lower" -> checkBytes (operation , actual , new BytesRef [] { new BytesRef ("foo" ), new BytesRef ("bar" ) });
418- case "to_upper" -> checkBytes (operation , actual , new BytesRef [] { new BytesRef ("FOO" ), new BytesRef ("BAR" ) });
420+ case "to_lower" -> checkBytes (operation , actual , false , new BytesRef [] { new BytesRef ("foo" ), new BytesRef ("bar" ) });
421+ case "to_lower_ords" -> checkBytes (operation , actual , true , new BytesRef [] { new BytesRef ("foo" ), new BytesRef ("bar" ) });
422+ case "to_upper" -> checkBytes (operation , actual , false , new BytesRef [] { new BytesRef ("FOO" ), new BytesRef ("BAR" ) });
423+ case "to_upper_ords" -> checkBytes (operation , actual , true , new BytesRef [] { new BytesRef ("FOO" ), new BytesRef ("BAR" ) });
419424 default -> throw new UnsupportedOperationException (operation );
420425 }
421426 }
422427
423- private static void checkBytes (String operation , Page actual , BytesRef [] expectedVals ) {
428+ private static void checkBytes (String operation , Page actual , boolean expectOrds , BytesRef [] expectedVals ) {
424429 BytesRef scratch = new BytesRef ();
425430 BytesRefVector v = actual .<BytesRefBlock >getBlock (1 ).asVector ();
426431 for (int i = 0 ; i < BLOCK_LENGTH ; i ++) {
@@ -430,6 +435,15 @@ private static void checkBytes(String operation, Page actual, BytesRef[] expecte
430435 throw new AssertionError ("[" + operation + "] expected [" + expected + "] but was [" + b + "]" );
431436 }
432437 }
438+ if (expectOrds ) {
439+ if (v .asOrdinals () == null ) {
440+ throw new IllegalArgumentException ("expected ords but got " + v );
441+ }
442+ } else {
443+ if (v .asOrdinals () != null ) {
444+ throw new IllegalArgumentException ("expected non-ords but got " + v );
445+ }
446+ }
433447 }
434448
435449 private static Page page (String operation ) {
@@ -510,6 +524,16 @@ private static Page page(String operation) {
510524 }
511525 yield new Page (builder .build ().asBlock ());
512526 }
527+ case "to_lower_ords" , "to_upper_ords" -> {
528+ var bytes = blockFactory .newBytesRefVectorBuilder (BLOCK_LENGTH );
529+ bytes .appendBytesRef (new BytesRef ("foo" ));
530+ bytes .appendBytesRef (new BytesRef ("bar" ));
531+ var ordinals = blockFactory .newIntVectorFixedBuilder (BLOCK_LENGTH );
532+ for (int i = 0 ; i < BLOCK_LENGTH ; i ++) {
533+ ordinals .appendInt (i % 2 );
534+ }
535+ yield new Page (new OrdinalBytesRefVector (ordinals .build (), bytes .build ()).asBlock ());
536+ }
513537 default -> throw new UnsupportedOperationException ();
514538 };
515539 }
0 commit comments