Skip to content

Commit 9633d6c

Browse files
authored
ESQL: TO_LOWER process all values (#124676) (#127772)
Make `TO_LOWER` and `TO_UPPER` process all values it received. This is quite large because it borrows a lot of code from the regular evaluator generator to generate conversions so we can use the Locale. That change propagates to the order of some parameters and to the `toString` and a few more places. Closes #124002
1 parent f19ba6a commit 9633d6c

File tree

21 files changed

+255
-197
lines changed

21 files changed

+255
-197
lines changed

docs/changelog/124676.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 124676
2+
summary: TO_LOWER processes all values
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 124002

docs/reference/esql/functions/examples/to_lower.asciidoc

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/definition/to_lower.json

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/definition/to_upper.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/parameters/to_lower.asciidoc

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/parameters/to_upper.asciidoc

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/string.csv-spec

+28
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,20 @@ emp_no:integer | first_name:keyword | name_lower:keyword
13991399
;
14001400

14011401

1402+
toLowerMv
1403+
required_capability: to_lower_mv
1404+
// tag::to_lower_mv[]
1405+
ROW v = TO_LOWER(["Some", "Text"])
1406+
// end::to_lower_mv[]
1407+
;
1408+
1409+
// tag::to_lower_mv-result[]
1410+
v:keyword
1411+
["some", "text"]
1412+
// end::to_lower_mv-result[]
1413+
;
1414+
1415+
14021416
toUpperRow#[skip:-8.12.99]
14031417
// tag::to_upper[]
14041418
ROW message = "Some Text"
@@ -1421,6 +1435,20 @@ emp_no:integer | first_name:keyword | name_upper:keyword
14211435
;
14221436

14231437

1438+
toUpperMv
1439+
required_capability: to_lower_mv
1440+
// tag::to_upper_mv[]
1441+
ROW v = TO_UPPER(["Some", "Text"])
1442+
// end::to_upper_mv[]
1443+
;
1444+
1445+
// tag::to_upper_mv-result[]
1446+
v:keyword
1447+
["SOME", "TEXT"]
1448+
// end::to_upper_mv-result[]
1449+
;
1450+
1451+
14241452
toUpperLowerUnicode#[skip:-8.12.99]
14251453
row a = "π/2 + a + B + Λ ºC" | eval lower = to_lower(a), upper = to_upper(a) | keep a, upper, lower;
14261454

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/string/ChangeCaseEvaluator.java

+55-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

+5
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ public enum Cap {
840840
*/
841841
FIX_JOIN_MASKING_EVAL,
842842

843+
/**
844+
* Do {@code TO_LOWER} and {@code TO_UPPER} process all field values?
845+
*/
846+
TO_LOWER_MV,
847+
843848
/**
844849
* Resolve groupings before resolving references to groupings in the aggregations.
845850
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToStringFromAggregateMetricDoubleEvaluator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.compute.data.Vector;
1515
import org.elasticsearch.compute.operator.DriverContext;
1616
import org.elasticsearch.compute.operator.EvalOperator;
17+
import org.elasticsearch.core.Releasables;
1718
import org.elasticsearch.xpack.esql.core.tree.Source;
1819

1920
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.aggregateMetricDoubleBlockToString;
@@ -63,7 +64,7 @@ public Block evalBlock(Block b) {
6364

6465
@Override
6566
public void close() {
66-
field.close();
67+
Releasables.closeExpectNoException(field);
6768
}
6869

6970
public static class Factory implements EvalOperator.ExpressionEvaluator.Factory {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ChangeCase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import org.apache.lucene.util.BytesRef;
1111
import org.elasticsearch.common.lucene.BytesRefs;
12-
import org.elasticsearch.compute.ann.Evaluator;
12+
import org.elasticsearch.compute.ann.ConvertEvaluator;
1313
import org.elasticsearch.compute.ann.Fixed;
1414
import org.elasticsearch.compute.operator.EvalOperator;
1515
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -99,7 +99,7 @@ public Expression replaceChildren(List<Expression> newChildren) {
9999
return replaceChild(newChildren.get(0));
100100
}
101101

102-
@Evaluator
102+
@ConvertEvaluator
103103
static BytesRef process(BytesRef val, @Fixed Locale locale, @Fixed Case caseType) {
104104
return BytesRefs.toBytesRef(caseType.process(val.utf8ToString(), locale));
105105
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToLower.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@ public class ToLower extends ChangeCase {
2727
@FunctionInfo(
2828
returnType = { "keyword" },
2929
description = "Returns a new string representing the input string converted to lower case.",
30-
examples = @Example(file = "string", tag = "to_lower")
30+
examples = { @Example(file = "string", tag = "to_lower"), @Example(file = "string", tag = "to_lower_mv"), }
3131
)
32-
public ToLower(
33-
Source source,
34-
@Param(
35-
name = "str",
36-
type = { "keyword", "text" },
37-
description = "String expression. If `null`, the function returns `null`."
38-
) Expression field,
39-
Configuration configuration
40-
) {
32+
public ToLower(Source source, @Param(name = "str", type = { "keyword", "text" }, description = """
33+
String expression. If `null`, the function returns `null`.
34+
The input can be a single- or multi-valued column or an expression.""") Expression field, Configuration configuration) {
4135
super(source, field, configuration, Case.LOWER);
4236
}
4337

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/ToUpper.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@ public class ToUpper extends ChangeCase {
2929
description = "Returns a new string representing the input string converted to upper case.",
3030
examples = @Example(file = "string", tag = "to_upper")
3131
)
32-
public ToUpper(
33-
Source source,
34-
@Param(
35-
name = "str",
36-
type = { "keyword", "text" },
37-
description = "String expression. If `null`, the function returns `null`."
38-
) Expression field,
39-
Configuration configuration
40-
) {
32+
public ToUpper(Source source, @Param(name = "str", type = { "keyword", "text" }, description = """
33+
String expression. If `null`, the function returns `null`.
34+
The input can be a single- or multi-valued column or an expression.""") Expression field, Configuration configuration) {
4135
super(source, field, configuration, Case.UPPER);
4236
}
4337

0 commit comments

Comments
 (0)