77
88package org .elasticsearch .xpack .esql .core .util ;
99
10+ import org .elasticsearch .common .lucene .BytesRefs ;
1011import org .elasticsearch .xpack .esql .core .expression .FieldAttribute ;
1112import org .elasticsearch .xpack .esql .core .expression .Literal ;
1213import org .elasticsearch .xpack .esql .core .tree .Source ;
2223import static org .elasticsearch .test .ESTestCase .randomFrom ;
2324import static org .elasticsearch .xpack .esql .core .tree .Source .EMPTY ;
2425import static org .elasticsearch .xpack .esql .core .type .DataType .INTEGER ;
26+ import static org .elasticsearch .xpack .esql .core .type .DataType .KEYWORD ;
27+ import static org .elasticsearch .xpack .esql .core .type .DataType .TEXT ;
2528
2629public final class TestUtils {
2730 private TestUtils () {}
@@ -39,6 +42,10 @@ public static Literal of(Source source, Object value) {
3942 if (value instanceof Literal ) {
4043 return (Literal ) value ;
4144 }
45+ DataType type = DataType .fromJava (value );
46+ if (value instanceof String && (type == TEXT || type == KEYWORD )) {
47+ value = BytesRefs .toBytesRef (value );
48+ }
4249 return new Literal (source , value , DataType .fromJava (value ));
4350 }
4451
@@ -58,12 +65,16 @@ public static FieldAttribute getFieldAttribute(String name, DataType dataType) {
5865 return new FieldAttribute (EMPTY , name , new EsField (name + "f" , dataType , emptyMap (), true ));
5966 }
6067
61- /** Similar to {@link String#strip()}, but removes the WS throughout the entire string. */
68+ /**
69+ * Similar to {@link String#strip()}, but removes the WS throughout the entire string.
70+ */
6271 public static String stripThrough (String input ) {
6372 return WS_PATTERN .matcher (input ).replaceAll (StringUtils .EMPTY );
6473 }
6574
66- /** Returns the input string, but with parts of it having the letter casing changed. */
75+ /**
76+ * Returns the input string, but with parts of it having the letter casing changed.
77+ */
6778 public static String randomCasing (String input ) {
6879 StringBuilder sb = new StringBuilder (input .length ());
6980 for (int i = 0 , inputLen = input .length (), step = (int ) Math .sqrt (inputLen ); i < inputLen ; i += step ) {
0 commit comments