Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ public static boolean isString(DataType t) {
return t == KEYWORD || t == TEXT;
}

public static boolean isPrimitiveAndSupported(DataType t) {
return isPrimitive(t) && t != UNSUPPORTED;
}

public static boolean isPrimitive(DataType t) {
return t != OBJECT && t != NESTED && t != UNSUPPORTED;
return t != OBJECT && t != NESTED;
}

public static boolean isNull(DataType t) {
Expand All @@ -233,6 +237,65 @@ public static boolean isDateTime(DataType type) {
return type == DATETIME;
}

public static boolean isNullOrTimeDuration(DataType t) {
return t == TIME_DURATION || isNull(t);
}

public static boolean isNullOrDatePeriod(DataType t) {
return t == DATE_PERIOD || isNull(t);
}

public static boolean isTemporalAmount(DataType t) {
return t == DATE_PERIOD || t == TIME_DURATION;
}

public static boolean isNullOrTemporalAmount(DataType t) {
return isTemporalAmount(t) || isNull(t);
}

public static boolean isDateTimeOrTemporal(DataType t) {
return isDateTime(t) || isTemporalAmount(t);
}

public static boolean areCompatible(DataType left, DataType right) {
if (left == right) {
return true;
} else {
return (left == NULL || right == NULL) || (isString(left) && isString(right)) || (left.isNumeric() && right.isNumeric());
}
}

/**
* Supported types that can be contained in a block.
*/
public static boolean isRepresentable(DataType t) {
return t != OBJECT
&& t != NESTED
&& t != UNSUPPORTED
&& t != DATE_PERIOD
&& t != TIME_DURATION
&& t != BYTE
&& t != SHORT
&& t != FLOAT
&& t != SCALED_FLOAT
&& t != SOURCE
&& t != HALF_FLOAT
&& t != PARTIAL_AGG
&& t.isCounter() == false;
}

public static boolean isSpatialPoint(DataType t) {
return t == GEO_POINT || t == CARTESIAN_POINT;
}

public static boolean isSpatialGeo(DataType t) {
return t == GEO_POINT || t == GEO_SHAPE;
}

public static boolean isSpatial(DataType t) {
return t == GEO_POINT || t == CARTESIAN_POINT || t == GEO_SHAPE || t == CARTESIAN_SHAPE;
}

public String nameUpper() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
import static org.elasticsearch.xpack.esql.core.type.DataType.isDateTime;
import static org.elasticsearch.xpack.esql.core.type.DataType.isPrimitive;
import static org.elasticsearch.xpack.esql.core.type.DataType.isPrimitiveAndSupported;
import static org.elasticsearch.xpack.esql.core.type.DataType.isString;
import static org.elasticsearch.xpack.esql.core.util.NumericUtils.UNSIGNED_LONG_MAX;
import static org.elasticsearch.xpack.esql.core.util.NumericUtils.inUnsignedLongRange;
Expand Down Expand Up @@ -126,7 +126,7 @@ public static boolean canConvert(DataType from, DataType to) {
return true;
}
// only primitives are supported so far
return isPrimitive(from) && isPrimitive(to) && converterFor(from, to) != null;
return isPrimitiveAndSupported(from) && isPrimitiveAndSupported(to) && converterFor(from, to) != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testDottedField() {

assertThat(mapping.size(), is(2));
EsField field = mapping.get("manager");
assertThat(DataType.isPrimitive(field.getDataType()), is(false));
assertThat(DataType.isPrimitiveAndSupported(field.getDataType()), is(false));
assertThat(field.getDataType(), is(OBJECT));
Map<String, EsField> children = field.getProperties();
assertThat(children.size(), is(2));
Expand All @@ -133,7 +133,7 @@ public void testMultiField() {

assertThat(mapping.size(), is(1));
EsField field = mapping.get("text");
assertThat(DataType.isPrimitive(field.getDataType()), is(true));
assertThat(DataType.isPrimitiveAndSupported(field.getDataType()), is(true));
assertThat(field.getDataType(), is(TEXT));
Map<String, EsField> fields = field.getProperties();
assertThat(fields.size(), is(4));
Expand All @@ -147,7 +147,7 @@ public void testMultiFieldTooManyOptions() {

assertThat(mapping.size(), is(1));
EsField field = mapping.get("text");
assertThat(DataType.isPrimitive(field.getDataType()), is(true));
assertThat(DataType.isPrimitiveAndSupported(field.getDataType()), is(true));
assertThat(field, instanceOf(TextEsField.class));
Map<String, EsField> fields = field.getProperties();
assertThat(fields.size(), is(4));
Expand All @@ -161,7 +161,7 @@ public void testNestedDoc() {

assertThat(mapping.size(), is(1));
EsField field = mapping.get("dep");
assertThat(DataType.isPrimitive(field.getDataType()), is(false));
assertThat(DataType.isPrimitiveAndSupported(field.getDataType()), is(false));
assertThat(field.getDataType(), is(NESTED));
Map<String, EsField> children = field.getProperties();
assertThat(children.size(), is(4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected void encodeChunk(int sizeHint, RecyclerBytesStreamOutput out) throws I
*/
static final Map<String, BlockConverter> ESQL_CONVERTERS = Map.ofEntries(
// For reference:
// - EsqlDataTypes: list of ESQL data types (not all are present in outputs)
// - DataType: list of ESQL data types (not all are present in outputs)
// - PositionToXContent: conversions for ESQL JSON output
// - EsqlDataTypeConverter: conversions to ESQL datatypes
// Missing: multi-valued values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier;
import org.elasticsearch.xpack.esql.stats.FeatureMetric;
import org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;
import org.elasticsearch.xpack.esql.type.MultiTypeEsField;

import java.util.ArrayList;
Expand Down Expand Up @@ -116,8 +115,8 @@
import static org.elasticsearch.xpack.esql.core.type.DataType.NESTED;
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
import static org.elasticsearch.xpack.esql.core.type.DataType.isTemporalAmount;
import static org.elasticsearch.xpack.esql.stats.FeatureMetric.LIMIT;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.isTemporalAmount;

/**
* This class is part of the planner. Resolves references (such as variable and index names) and performs implicit casting.
Expand Down Expand Up @@ -242,7 +241,7 @@ private static void mappingAsAttributes(List<Attribute> list, Source source, Fie
? new UnsupportedAttribute(source, name, uef)
: new FieldAttribute(source, parent, name, t);
// primitive branch
if (EsqlDataTypes.isPrimitive(type)) {
if (DataType.isPrimitive(type)) {
list.add(attribute);
}
// allow compound object even if they are unknown (but not NESTED)
Expand Down Expand Up @@ -863,7 +862,7 @@ private static List<Attribute> potentialCandidatesIfNoMatchesFound(
Set<String> names = new HashSet<>(attrList.size());
for (var a : attrList) {
String nameCandidate = a.name();
if (EsqlDataTypes.isPrimitive(a.dataType())) {
if (DataType.isPrimitive(a.dataType())) {
names.add(nameCandidate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.elasticsearch.xpack.esql.plan.logical.UnaryPlan;
import org.elasticsearch.xpack.esql.stats.FeatureMetric;
import org.elasticsearch.xpack.esql.stats.Metrics;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.util.ArrayList;
import java.util.BitSet;
Expand Down Expand Up @@ -364,7 +363,7 @@ private static void checkRegexExtractOnlyOnStrings(LogicalPlan p, Set<Failure> f
private static void checkRow(LogicalPlan p, Set<Failure> failures) {
if (p instanceof Row row) {
row.fields().forEach(a -> {
if (EsqlDataTypes.isRepresentable(a.dataType()) == false) {
if (DataType.isRepresentable(a.dataType()) == false) {
failures.add(fail(a, "cannot use [{}] directly in a row assignment", a.child().sourceText()));
}
});
Expand All @@ -376,7 +375,7 @@ private static void checkEvalFields(LogicalPlan p, Set<Failure> failures) {
eval.fields().forEach(field -> {
// check supported types
DataType dataType = field.dataType();
if (EsqlDataTypes.isRepresentable(dataType) == false) {
if (DataType.isRepresentable(dataType) == false) {
failures.add(
fail(field, "EVAL does not support type [{}] in expression [{}]", dataType.typeName(), field.child().sourceText())
);
Expand Down Expand Up @@ -528,7 +527,7 @@ private static void checkForSortOnSpatialTypes(LogicalPlan p, Set<Failure> local
if (p instanceof OrderBy ob) {
ob.forEachExpression(Attribute.class, attr -> {
DataType dataType = attr.dataType();
if (EsqlDataTypes.isSpatial(dataType)) {
if (DataType.isSpatial(dataType)) {
localFailures.add(fail(attr, "cannot sort on " + dataType.typeName()));
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.core.type.EsField;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.util.Locale;

Expand Down Expand Up @@ -66,21 +65,21 @@ public static Expression.TypeResolution isExact(Expression e, String operationNa
private static final String[] POINT_TYPE_NAMES = new String[] { GEO_POINT.typeName(), CARTESIAN_POINT.typeName() };
private static final String[] NON_SPATIAL_TYPE_NAMES = DataType.types()
.stream()
.filter(EsqlDataTypes::isRepresentable)
.filter(t -> EsqlDataTypes.isSpatial(t) == false)
.filter(DataType::isRepresentable)
.filter(t -> DataType.isSpatial(t) == false)
.map(DataType::esType)
.toArray(String[]::new);

public static Expression.TypeResolution isSpatialPoint(Expression e, String operationName, TypeResolutions.ParamOrdinal paramOrd) {
return isType(e, EsqlDataTypes::isSpatialPoint, operationName, paramOrd, POINT_TYPE_NAMES);
return isType(e, DataType::isSpatialPoint, operationName, paramOrd, POINT_TYPE_NAMES);
}

public static Expression.TypeResolution isSpatial(Expression e, String operationName, TypeResolutions.ParamOrdinal paramOrd) {
return isType(e, EsqlDataTypes::isSpatial, operationName, paramOrd, SPATIAL_TYPE_NAMES);
return isType(e, DataType::isSpatial, operationName, paramOrd, SPATIAL_TYPE_NAMES);
}

public static Expression.TypeResolution isNotSpatial(Expression e, String operationName, TypeResolutions.ParamOrdinal paramOrd) {
return isType(e, t -> EsqlDataTypes.isSpatial(t) == false, operationName, paramOrd, NON_SPATIAL_TYPE_NAMES);
return isType(e, t -> DataType.isSpatial(t) == false, operationName, paramOrd, NON_SPATIAL_TYPE_NAMES);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
import org.elasticsearch.xpack.esql.planner.ToAggregator;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.time.Duration;
Expand Down Expand Up @@ -125,7 +124,7 @@ protected TypeResolution resolveType() {
);
if (unit != null) {
resolution = resolution.and(
isType(unit, dt -> dt.isWholeNumber() || EsqlDataTypes.isTemporalAmount(dt), sourceText(), SECOND, "time_duration")
isType(unit, dt -> dt.isWholeNumber() || DataType.isTemporalAmount(dt), sourceText(), SECOND, "time_duration")
);
}
return resolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Div;
import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Mul;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.time.ZoneId;
Expand Down Expand Up @@ -239,7 +238,7 @@ public ExpressionEvaluator.Factory toEvaluator(Function<Expression, ExpressionEv
long t = foldToLong(to);
preparedRounding = new DateRoundingPicker(b, f, t).pickRounding().prepareForUnknown();
} else {
assert EsqlDataTypes.isTemporalAmount(buckets.dataType()) : "Unexpected span data type [" + buckets.dataType() + "]";
assert DataType.isTemporalAmount(buckets.dataType()) : "Unexpected span data type [" + buckets.dataType() + "]";
preparedRounding = DateTrunc.createRounding(buckets.fold(), DEFAULT_TZ);
}
return DateTrunc.evaluator(source(), toEvaluator.apply(field), preparedRounding);
Expand Down Expand Up @@ -323,7 +322,7 @@ protected TypeResolution resolveType() {
if (fieldType == DataType.DATETIME) {
TypeResolution resolution = isType(
buckets,
dt -> dt.isWholeNumber() || EsqlDataTypes.isTemporalAmount(dt),
dt -> dt.isWholeNumber() || DataType.isTemporalAmount(dt),
sourceText(),
SECOND,
"integral",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.time.Duration;
Expand Down Expand Up @@ -110,7 +109,7 @@ protected TypeResolution resolveType() {
return new TypeResolution("Unresolved children");
}

return isType(interval, EsqlDataTypes::isTemporalAmount, sourceText(), FIRST, "dateperiod", "timeduration").and(
return isType(interval, DataType::isTemporalAmount, sourceText(), FIRST, "dateperiod", "timeduration").and(
isDate(timestampField, sourceText(), SECOND)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
import org.elasticsearch.xpack.esql.planner.PlannerUtils;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -132,14 +131,14 @@ protected TypeResolution resolveType() {
return new TypeResolution("Unresolved children");
}

TypeResolution resolution = isType(field1, EsqlDataTypes::isRepresentable, sourceText(), FIRST, "representable");
TypeResolution resolution = isType(field1, DataType::isRepresentable, sourceText(), FIRST, "representable");
if (resolution.unresolved()) {
return resolution;
}
dataType = field1.dataType();
if (dataType == DataType.NULL) {
dataType = field2.dataType();
return isType(field2, EsqlDataTypes::isRepresentable, sourceText(), SECOND, "representable");
return isType(field2, DataType::isRepresentable, sourceText(), SECOND, "representable");
}
return isType(field2, t -> t == dataType, sourceText(), SECOND, dataType.typeName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.List;

import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
import static org.elasticsearch.xpack.esql.core.type.DataType.isRepresentable;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.unsignedLongToDouble;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypes.isRepresentable;

/**
* Reduce a multivalued field to a single valued field containing the average value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.xpack.esql.expression.function.Example;
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -74,7 +73,7 @@ public String getWriteableName() {

@Override
protected TypeResolution resolveFieldType() {
return isType(field(), EsqlDataTypes::isRepresentable, sourceText(), null, "representable");
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.Example;
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
import org.elasticsearch.xpack.esql.expression.function.Param;
import org.elasticsearch.xpack.esql.planner.PlannerUtils;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -86,7 +86,7 @@ public String getWriteableName() {

@Override
protected TypeResolution resolveFieldType() {
return isType(field(), EsqlDataTypes::isRepresentable, sourceText(), null, "representable");
return isType(field(), DataType::isRepresentable, sourceText(), null, "representable");
}

@Override
Expand Down
Loading