Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -14,4 +14,5 @@
public class EsqlCorePlugin extends Plugin implements ExtensiblePlugin {

public static final FeatureFlag SEMANTIC_TEXT_FEATURE_FLAG = new FeatureFlag("esql_semantic_text");
public static final FeatureFlag AGGREGATE_METRIC_DOUBLE_FEATURE_FLAG = new FeatureFlag("esql_aggregate_metric_double");
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ public enum DataType {
* loaded from the index and ESQL will load these fields as strings without their attached
* chunks or embeddings.
*/
SEMANTIC_TEXT(builder().esType("semantic_text").unknownSize());
SEMANTIC_TEXT(builder().esType("semantic_text").unknownSize()),

AGGREGATE_METRIC_DOUBLE(builder().esType("aggregate_metric_double").unknownSize());

/**
* Types that are actively being built. These types are not returned
Expand All @@ -316,7 +318,8 @@ public enum DataType {
* check that sending them to a function produces a sane error message.
*/
public static final Map<DataType, FeatureFlag> UNDER_CONSTRUCTION = Map.ofEntries(
Map.entry(SEMANTIC_TEXT, EsqlCorePlugin.SEMANTIC_TEXT_FEATURE_FLAG)
Map.entry(SEMANTIC_TEXT, EsqlCorePlugin.SEMANTIC_TEXT_FEATURE_FLAG),
Map.entry(AGGREGATE_METRIC_DOUBLE, EsqlCorePlugin.AGGREGATE_METRIC_DOUBLE_FEATURE_FLAG)
);

private final String typeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ private static void assertMetadata(
|| expectedType == UNSIGNED_LONG)) {
continue;
}
if (blockType == Type.DOUBLE && expectedType == Type.AGGREGATE_METRIC_DOUBLE) {
continue;
}
if (blockType == Type.KEYWORD
&& (expectedType == Type.IP
|| expectedType == Type.VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ public enum Type {
GEO_POINT(x -> x == null ? null : GEO.wktToWkb(x), BytesRef.class),
CARTESIAN_POINT(x -> x == null ? null : CARTESIAN.wktToWkb(x), BytesRef.class),
GEO_SHAPE(x -> x == null ? null : GEO.wktToWkb(x), BytesRef.class),
CARTESIAN_SHAPE(x -> x == null ? null : CARTESIAN.wktToWkb(x), BytesRef.class);
CARTESIAN_SHAPE(x -> x == null ? null : CARTESIAN.wktToWkb(x), BytesRef.class),
AGGREGATE_METRIC_DOUBLE(Double::parseDouble, Double.class);

private static final Map<String, Type> LOOKUP = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class CsvTestsDataLoader {
private static final TestsDataset ADDRESSES = new TestsDataset("addresses");
private static final TestsDataset BOOKS = new TestsDataset("books").withSetting("books-settings.json");
private static final TestsDataset SEMANTIC_TEXT = new TestsDataset("semantic_text").withInferenceEndpoint(true);
private static final TestsDataset AGGREGATE_METRIC_DOUBLE = new TestsDataset("aggregate_metric_double");

public static final Map<String, TestsDataset> CSV_DATASET_MAP = Map.ofEntries(
Map.entry(EMPLOYEES.indexName, EMPLOYEES),
Expand Down Expand Up @@ -155,7 +156,8 @@ public class CsvTestsDataLoader {
Map.entry(DISTANCES.indexName, DISTANCES),
Map.entry(ADDRESSES.indexName, ADDRESSES),
Map.entry(BOOKS.indexName, BOOKS),
Map.entry(SEMANTIC_TEXT.indexName, SEMANTIC_TEXT)
Map.entry(SEMANTIC_TEXT.indexName, SEMANTIC_TEXT),
Map.entry(AGGREGATE_METRIC_DOUBLE.indexName, AGGREGATE_METRIC_DOUBLE)
);

private static final EnrichConfig LANGUAGES_ENRICH = new EnrichConfig("languages_policy", "enrich-policy-languages.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import static org.elasticsearch.test.ESTestCase.randomShort;
import static org.elasticsearch.test.ESTestCase.randomZone;
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
import static org.elasticsearch.xpack.esql.core.type.DataType.AGGREGATE_METRIC_DOUBLE;
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
import static org.elasticsearch.xpack.esql.core.type.DataType.NULL;
import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.CARTESIAN;
Expand Down Expand Up @@ -749,6 +750,7 @@ public static Literal randomLiteral(DataType type) {
case CARTESIAN_POINT -> CARTESIAN.asWkb(ShapeTestUtils.randomPoint());
case GEO_SHAPE -> GEO.asWkb(GeometryTestUtils.randomGeometry(randomBoolean()));
case CARTESIAN_SHAPE -> CARTESIAN.asWkb(ShapeTestUtils.randomGeometry(randomBoolean()));
case AGGREGATE_METRIC_DOUBLE -> randomDouble();
case NULL -> null;
case SOURCE -> {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
some_field:aggregate_metric_double
Copy link
Contributor Author

@limotova limotova Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this here as a placeholder but I'm not quite sure how we would want to format the csv tests for this type (it might not be possible?)


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"properties": {
"some_field": {
"type": "aggregate_metric_double",
"metrics": [ "min", "max", "sum", "value_count" ],
"default_metric": "max"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Pa
return builder.value(((IntBlock) block).getInt(valueIndex));
}
};
case DOUBLE, COUNTER_DOUBLE -> new PositionToXContent(block) {
case DOUBLE, COUNTER_DOUBLE, AGGREGATE_METRIC_DOUBLE -> new PositionToXContent(block) {
@Override
protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Params params, int valueIndex)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static Object valueAt(DataType dataType, Block block, int offset, BytesR
case UNSIGNED_LONG -> unsignedLongAsNumber(((LongBlock) block).getLong(offset));
case LONG, COUNTER_LONG -> ((LongBlock) block).getLong(offset);
case INTEGER, COUNTER_INTEGER -> ((IntBlock) block).getInt(offset);
case DOUBLE, COUNTER_DOUBLE -> ((DoubleBlock) block).getDouble(offset);
case DOUBLE, COUNTER_DOUBLE, AGGREGATE_METRIC_DOUBLE -> ((DoubleBlock) block).getDouble(offset);
case KEYWORD, SEMANTIC_TEXT, TEXT -> ((BytesRefBlock) block).getBytesRef(offset, scratch).utf8ToString();
case IP -> {
BytesRef val = ((BytesRefBlock) block).getBytesRef(offset, scratch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private static String dataTypeToString(DataType type, Class<?> aggClass) {
case GEO_SHAPE -> "GeoShape";
case CARTESIAN_SHAPE -> "CartesianShape";
case UNSUPPORTED, NULL, UNSIGNED_LONG, SHORT, BYTE, FLOAT, HALF_FLOAT, SCALED_FLOAT, OBJECT, SOURCE, DATE_PERIOD, TIME_DURATION,
DOC_DATA_TYPE, TSID_DATA_TYPE, PARTIAL_AGG -> throw new EsqlIllegalArgumentException(
DOC_DATA_TYPE, TSID_DATA_TYPE, PARTIAL_AGG, AGGREGATE_METRIC_DOUBLE -> throw new EsqlIllegalArgumentException(
"illegal agg type: " + type.typeName()
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ private PhysicalOperation planTopN(TopNExec topNExec, LocalExecutionPlannerConte
case VERSION -> TopNEncoder.VERSION;
case BOOLEAN, NULL, BYTE, SHORT, INTEGER, LONG, DOUBLE, FLOAT, HALF_FLOAT, DATETIME, DATE_NANOS, DATE_PERIOD, TIME_DURATION,
OBJECT, SCALED_FLOAT, UNSIGNED_LONG, DOC_DATA_TYPE, TSID_DATA_TYPE -> TopNEncoder.DEFAULT_SORTABLE;
case GEO_POINT, CARTESIAN_POINT, GEO_SHAPE, CARTESIAN_SHAPE, COUNTER_LONG, COUNTER_INTEGER, COUNTER_DOUBLE, SOURCE ->
TopNEncoder.DEFAULT_UNSORTABLE;
case GEO_POINT, CARTESIAN_POINT, GEO_SHAPE, CARTESIAN_SHAPE, COUNTER_LONG, COUNTER_INTEGER, COUNTER_DOUBLE, SOURCE,
AGGREGATE_METRIC_DOUBLE -> TopNEncoder.DEFAULT_UNSORTABLE;
// unsupported fields are encoded as BytesRef, we'll use the same encoder; all values should be null at this point
case PARTIAL_AGG, UNSUPPORTED -> TopNEncoder.UNSUPPORTED;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static ElementType toElementType(DataType dataType, MappedFieldType.Field
return switch (dataType) {
case LONG, DATETIME, DATE_NANOS, UNSIGNED_LONG, COUNTER_LONG -> ElementType.LONG;
case INTEGER, COUNTER_INTEGER -> ElementType.INT;
case DOUBLE, COUNTER_DOUBLE -> ElementType.DOUBLE;
case DOUBLE, COUNTER_DOUBLE, AGGREGATE_METRIC_DOUBLE -> ElementType.DOUBLE;
// unsupported fields are passed through as a BytesRef
case KEYWORD, TEXT, IP, SOURCE, VERSION, SEMANTIC_TEXT, UNSUPPORTED -> ElementType.BYTES_REF;
case NULL -> ElementType.NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Page randomPage(List<ColumnInfoImpl> columns) {
switch (c.type()) {
case UNSIGNED_LONG, LONG, COUNTER_LONG -> ((LongBlock.Builder) builder).appendLong(randomLong());
case INTEGER, COUNTER_INTEGER -> ((IntBlock.Builder) builder).appendInt(randomInt());
case DOUBLE, COUNTER_DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble(randomDouble());
case DOUBLE, COUNTER_DOUBLE, AGGREGATE_METRIC_DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble(randomDouble());
case KEYWORD -> ((BytesRefBlock.Builder) builder).appendBytesRef(new BytesRef(randomAlphaOfLength(10)));
case TEXT, SEMANTIC_TEXT -> ((BytesRefBlock.Builder) builder).appendBytesRef(new BytesRef(randomAlphaOfLength(10000)));
case IP -> ((BytesRefBlock.Builder) builder).appendBytesRef(
Expand Down Expand Up @@ -869,7 +869,9 @@ static Page valuesToPage(BlockFactory blockFactory, List<ColumnInfoImpl> columns
case UNSIGNED_LONG -> ((LongBlock.Builder) builder).appendLong(longToUnsignedLong(((Number) value).longValue(), true));
case LONG, COUNTER_LONG -> ((LongBlock.Builder) builder).appendLong(((Number) value).longValue());
case INTEGER, COUNTER_INTEGER -> ((IntBlock.Builder) builder).appendInt(((Number) value).intValue());
case DOUBLE, COUNTER_DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble(((Number) value).doubleValue());
case DOUBLE, COUNTER_DOUBLE, AGGREGATE_METRIC_DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble(
((Number) value).doubleValue()
);
case KEYWORD, TEXT, SEMANTIC_TEXT -> ((BytesRefBlock.Builder) builder).appendBytesRef(new BytesRef(value.toString()));
case UNSUPPORTED -> ((BytesRefBlock.Builder) builder).appendNull();
case IP -> ((BytesRefBlock.Builder) builder).appendBytesRef(stringToIP(value.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.index.fielddata.ScriptDocValues.DoublesSupplier;
import org.elasticsearch.index.fielddata.SortedBinaryDocValues;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
import org.elasticsearch.index.mapper.BlockLoader;
import org.elasticsearch.index.mapper.CompositeSyntheticFieldLoader;
import org.elasticsearch.index.mapper.DocumentParserContext;
import org.elasticsearch.index.mapper.FieldMapper;
Expand Down Expand Up @@ -508,6 +509,12 @@ public ValueFetcher valueFetcher(SearchExecutionContext context, String format)
return SourceValueFetcher.identity(name(), context, format);
}

@Override
public BlockLoader blockLoader(BlockLoaderContext blContext) {
// TODO: load other fields besides the default one
return delegateFieldType().blockLoader(blContext);
}

/**
* If field is a time series metric field, returns its metric type
* @return the metric type or null
Expand Down