Skip to content

Commit b9ff56f

Browse files
committed
ESQL: Simplify representable types error message
1 parent e5a0a78 commit b9ff56f

File tree

10 files changed

+37
-47
lines changed

10 files changed

+37
-47
lines changed

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/TypeResolutions.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
2323
import static org.elasticsearch.xpack.esql.core.type.DataType.IP;
2424
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
25+
import static org.elasticsearch.xpack.esql.core.type.DataType.isSpatial;
2526

2627
public final class TypeResolutions {
2728

@@ -71,6 +72,17 @@ public static TypeResolution isDate(Expression e, String operationName, ParamOrd
7172
return isType(e, dt -> dt == DATETIME, operationName, paramOrd, "datetime");
7273
}
7374

75+
/**
76+
* @see DataType#isRepresentable(DataType)
77+
*/
78+
public static TypeResolution isRepresentable(Expression e, String operationName, ParamOrdinal paramOrd) {
79+
return isType(e, DataType::isRepresentable, operationName, paramOrd, "any type except counter types");
80+
}
81+
82+
public static TypeResolution isRepresentableNotSpatial(Expression e, String operationName, ParamOrdinal paramOrd) {
83+
return isType(e, (t) -> isSpatial(t) == false && DataType.isRepresentable(t), operationName, paramOrd, "any type except counter and spatial types");
84+
}
85+
7486
public static TypeResolution isExact(Expression e, String message) {
7587
if (e instanceof FieldAttribute fa) {
7688
EsField.Exact exact = fa.getExactInfo();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4141
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
42+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
4243
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
4344

4445
/**
@@ -137,14 +138,14 @@ protected TypeResolution resolveType() {
137138
return new TypeResolution("Unresolved children");
138139
}
139140

140-
TypeResolution resolution = isType(field1, DataType::isRepresentable, sourceText(), FIRST, "representable");
141+
TypeResolution resolution = isRepresentable(field1, sourceText(), FIRST);
141142
if (resolution.unresolved()) {
142143
return resolution;
143144
}
144145
dataType = field1.dataType().noText();
145146
if (dataType == DataType.NULL) {
146147
dataType = field2.dataType().noText();
147-
return isType(field2, DataType::isRepresentable, sourceText(), SECOND, "representable");
148+
return isRepresentable(field2, sourceText(), SECOND);
148149
}
149150
return isType(field2, t -> t.noText() == dataType, sourceText(), SECOND, dataType.typeName());
150151
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import java.io.IOException;
2525
import java.util.List;
2626

27-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
27+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
28+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
2829

2930
/**
3031
* Reduce a multivalued field to a single valued field containing the count of values.
@@ -74,7 +75,7 @@ public String getWriteableName() {
7475

7576
@Override
7677
protected TypeResolution resolveFieldType() {
77-
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
78+
return isRepresentable(field(), sourceText(), DEFAULT);
7879
}
7980

8081
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.xpack.esql.core.expression.Expression;
1515
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1616
import org.elasticsearch.xpack.esql.core.tree.Source;
17-
import org.elasticsearch.xpack.esql.core.type.DataType;
1817
import org.elasticsearch.xpack.esql.expression.function.Example;
1918
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2019
import org.elasticsearch.xpack.esql.expression.function.Param;
@@ -23,7 +22,8 @@
2322
import java.io.IOException;
2423
import java.util.List;
2524

26-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
25+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
26+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
2727

2828
/**
2929
* Removes duplicate values from a multivalued field.
@@ -89,7 +89,7 @@ public String getWriteableName() {
8989

9090
@Override
9191
protected TypeResolution resolveFieldType() {
92-
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
92+
return isRepresentable(field(), sourceText(), DEFAULT);
9393
}
9494

9595
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.xpack.esql.core.expression.Expression;
2323
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2424
import org.elasticsearch.xpack.esql.core.tree.Source;
25-
import org.elasticsearch.xpack.esql.core.type.DataType;
2625
import org.elasticsearch.xpack.esql.expression.function.Example;
2726
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2827
import org.elasticsearch.xpack.esql.expression.function.Param;
@@ -31,7 +30,8 @@
3130
import java.io.IOException;
3231
import java.util.List;
3332

34-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
33+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
34+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
3535

3636
/**
3737
* Reduce a multivalued field to a single valued field containing the minimum value.
@@ -104,7 +104,7 @@ public String getWriteableName() {
104104

105105
@Override
106106
protected TypeResolution resolveFieldType() {
107-
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
107+
return isRepresentable(field(), sourceText(), DEFAULT);
108108
}
109109

110110
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.xpack.esql.core.expression.Expression;
2323
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
2424
import org.elasticsearch.xpack.esql.core.tree.Source;
25-
import org.elasticsearch.xpack.esql.core.type.DataType;
2625
import org.elasticsearch.xpack.esql.expression.function.Example;
2726
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2827
import org.elasticsearch.xpack.esql.expression.function.Param;
@@ -31,7 +30,8 @@
3130
import java.io.IOException;
3231
import java.util.List;
3332

34-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
33+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
34+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
3535

3636
/**
3737
* Reduce a multivalued field to a single valued field containing the minimum value.
@@ -104,7 +104,7 @@ public String getWriteableName() {
104104

105105
@Override
106106
protected TypeResolution resolveFieldType() {
107-
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
107+
return isRepresentable(field(), sourceText(), DEFAULT);
108108
}
109109

110110
@Override

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
import java.io.IOException;
2626
import java.util.List;
2727

28-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
29-
import static org.elasticsearch.xpack.esql.core.type.DataType.isRepresentable;
30-
import static org.elasticsearch.xpack.esql.core.type.DataType.isSpatial;
28+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
29+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableNotSpatial;
3130

3231
/**
3332
* Reduce a multivalued field to a single valued field containing the maximum value.
@@ -69,18 +68,7 @@ public String getWriteableName() {
6968

7069
@Override
7170
protected TypeResolution resolveFieldType() {
72-
return isType(
73-
field(),
74-
t -> isSpatial(t) == false && isRepresentable(t),
75-
sourceText(),
76-
null,
77-
"boolean",
78-
"date",
79-
"ip",
80-
"string",
81-
"version",
82-
"numeric except counter types"
83-
);
71+
return isRepresentableNotSpatial(field(), sourceText(), DEFAULT);
8472
}
8573

8674
@Override

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
import java.io.IOException;
2626
import java.util.List;
2727

28-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
29-
import static org.elasticsearch.xpack.esql.core.type.DataType.isRepresentable;
30-
import static org.elasticsearch.xpack.esql.core.type.DataType.isSpatial;
28+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT;
29+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentableNotSpatial;
3130

3231
/**
3332
* Reduce a multivalued field to a single valued field containing the minimum value.
@@ -69,18 +68,7 @@ public String getWriteableName() {
6968

7069
@Override
7170
protected TypeResolution resolveFieldType() {
72-
return isType(
73-
field(),
74-
t -> isSpatial(t) == false && isRepresentable(t),
75-
sourceText(),
76-
null,
77-
"boolean",
78-
"date",
79-
"ip",
80-
"string",
81-
"version",
82-
"numeric except counter types"
83-
);
71+
return isRepresentableNotSpatial(field(), sourceText(), DEFAULT);
8472
}
8573

8674
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
4242
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
4343
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.THIRD;
44-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
44+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
4545
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
4646
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.stringToInt;
4747

@@ -161,7 +161,7 @@ protected TypeResolution resolveType() {
161161
return new TypeResolution("Unresolved children");
162162
}
163163

164-
TypeResolution resolution = isType(field, DataType::isRepresentable, sourceText(), FIRST, "representable");
164+
TypeResolution resolution = isRepresentable(field, sourceText(), FIRST);
165165
if (resolution.unresolved()) {
166166
return resolution;
167167
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353

5454
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST;
5555
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
56+
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isRepresentable;
5657
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString;
57-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
5858
import static org.elasticsearch.xpack.esql.expression.Validations.isFoldable;
5959

6060
/**
@@ -128,7 +128,7 @@ protected TypeResolution resolveType() {
128128
return new TypeResolution("Unresolved children");
129129
}
130130

131-
TypeResolution resolution = isType(field, DataType::isRepresentable, sourceText(), FIRST, "representable");
131+
TypeResolution resolution = isRepresentable(field, sourceText(), FIRST);
132132

133133
if (resolution.unresolved()) {
134134
return resolution;

0 commit comments

Comments
 (0)