|
@@ -18,17 +18,15 @@ import org.elasticsearch.compute.operator.DriverContext;
|
|
|
import org.elasticsearch.compute.operator.EvalOperator;
|
|
|
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
|
|
|
import org.elasticsearch.xpack.esql.expression.function.scalar.AbstractScalarFunctionTestCase;
|
|
|
+import org.elasticsearch.xpack.ql.InvalidArgumentException;
|
|
|
import org.elasticsearch.xpack.ql.expression.Expression;
|
|
|
import org.elasticsearch.xpack.ql.expression.Literal;
|
|
|
import org.elasticsearch.xpack.ql.tree.Source;
|
|
|
import org.elasticsearch.xpack.ql.type.DataType;
|
|
|
import org.elasticsearch.xpack.ql.type.DataTypes;
|
|
|
-import org.hamcrest.Matcher;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Supplier;
|
|
|
-import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
@@ -67,13 +65,6 @@ public class SplitTests extends AbstractScalarFunctionTestCase {
|
|
|
return DataTypes.KEYWORD;
|
|
|
}
|
|
|
|
|
|
- private Matcher<Object> resultsMatcher(List<TestCaseSupplier.TypedData> typedData) {
|
|
|
- String str = ((BytesRef) typedData.get(0).data()).utf8ToString();
|
|
|
- String delim = ((BytesRef) typedData.get(1).data()).utf8ToString();
|
|
|
- List<BytesRef> split = Arrays.stream(str.split(Pattern.quote(delim))).map(BytesRef::new).toList();
|
|
|
- return equalTo(split.size() == 1 ? split.get(0) : split);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
protected List<ArgumentSpec> argSpec() {
|
|
|
return List.of(required(strings()), required(strings()));
|
|
@@ -107,4 +98,20 @@ public class SplitTests extends AbstractScalarFunctionTestCase {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testTooLongConstantDelimiter() {
|
|
|
+ String delimiter = randomAlphaOfLength(2);
|
|
|
+ DriverContext driverContext = driverContext();
|
|
|
+ InvalidArgumentException e = expectThrows(
|
|
|
+ InvalidArgumentException.class,
|
|
|
+ () -> evaluator(
|
|
|
+ new Split(
|
|
|
+ Source.EMPTY,
|
|
|
+ field("str", DataTypes.KEYWORD),
|
|
|
+ new Literal(Source.EMPTY, new BytesRef(delimiter), DataTypes.KEYWORD)
|
|
|
+ )
|
|
|
+ ).get(driverContext)
|
|
|
+ );
|
|
|
+ assertThat(e.getMessage(), equalTo("delimiter must be single byte for now"));
|
|
|
+ }
|
|
|
}
|