Skip to content

Commit

Permalink
Merge branch 'main' into semantic-query_inner-hits
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikep86 committed Aug 14, 2024
2 parents 1982eda + fac9b6a commit b0244f1
Show file tree
Hide file tree
Showing 18 changed files with 314 additions and 25 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/111809.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 111809
summary: Add Field caps support for Semantic Text
area: Mapping
type: enhancement
issues: []
6 changes: 6 additions & 0 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ tests:
- class: org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT
method: test {comparison.RangeVersion SYNC}
issue: https://github.com/elastic/elasticsearch/issues/111814
- class: org.elasticsearch.xpack.esql.qa.mixed.EsqlClientYamlIT
method: "test {p0=esql/26_aggs_bucket/friendlier BUCKET interval hourly: #110916}"
issue: https://github.com/elastic/elasticsearch/issues/111901
- class: org.elasticsearch.xpack.esql.qa.mixed.EsqlClientYamlIT
method: "test {p0=esql/26_aggs_bucket/friendlier BUCKET interval: monthly #110916}"
issue: https://github.com/elastic/elasticsearch/issues/111902

# Examples:
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
---
"Took is not orders of magnitude off":
- requires:
cluster_features: ["gte_v8.16.0"]
reason: "Bug reporting wrong took time introduced in 8.15.0, fixed in 8.16.0"
cluster_features: ["gte_v8.15.1"]
reason: "Bug reporting wrong took time introduced in 8.15.0, fixed in 8.15.1"
- do:
bulk:
body:
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ double tau()
"boolean to_boolean(field:boolean|keyword|text|double|long|unsigned_long|integer)"
"cartesian_point to_cartesianpoint(field:cartesian_point|keyword|text)"
"cartesian_shape to_cartesianshape(field:cartesian_point|cartesian_shape|keyword|text)"
"date to_datetime(field:date|keyword|text|double|long|unsigned_long|integer)"
"date to_datetime(field:date|date_nanos|keyword|text|double|long|unsigned_long|integer)"
"double to_dbl(field:boolean|date|keyword|text|double|long|unsigned_long|integer|counter_double|counter_integer|counter_long)"
"double to_degrees(number:double|integer|long|unsigned_long)"
"double to_double(field:boolean|date|keyword|text|double|long|unsigned_long|integer|counter_double|counter_integer|counter_long)"
"date to_dt(field:date|keyword|text|double|long|unsigned_long|integer)"
"date to_dt(field:date|date_nanos|keyword|text|double|long|unsigned_long|integer)"
"geo_point to_geopoint(field:geo_point|keyword|text)"
"geo_shape to_geoshape(field:geo_point|geo_shape|keyword|text)"
"integer to_int(field:boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer)"
"integer to_integer(field:boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer)"
"ip to_ip(field:ip|keyword|text)"
"long to_long(field:boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer|counter_long)"
"long to_long(field:boolean|date|date_nanos|keyword|text|double|long|unsigned_long|integer|counter_integer|counter_long)"
"keyword|text to_lower(str:keyword|text)"
"double to_radians(number:double|integer|long|unsigned_long)"
"keyword to_str(field:boolean|cartesian_point|cartesian_shape|date|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version)"
"keyword to_string(field:boolean|cartesian_point|cartesian_shape|date|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version)"
"keyword to_str(field:boolean|cartesian_point|cartesian_shape|date|date_nanos|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version)"
"keyword to_string(field:boolean|cartesian_point|cartesian_shape|date|date_nanos|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version)"
"unsigned_long to_ul(field:boolean|date|keyword|text|double|long|unsigned_long|integer)"
"unsigned_long to_ulong(field:boolean|date|keyword|text|double|long|unsigned_long|integer)"
"unsigned_long to_unsigned_long(field:boolean|date|keyword|text|double|long|unsigned_long|integer)"
Expand Down Expand Up @@ -215,21 +215,21 @@ to_bool |field |"boolean|keyword|text|double
to_boolean |field |"boolean|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_cartesianpo|field |"cartesian_point|keyword|text" |Input value. The input can be a single- or multi-valued column or an expression.
to_cartesiansh|field |"cartesian_point|cartesian_shape|keyword|text" |Input value. The input can be a single- or multi-valued column or an expression.
to_datetime |field |"date|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_datetime |field |"date|date_nanos|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_dbl |field |"boolean|date|keyword|text|double|long|unsigned_long|integer|counter_double|counter_integer|counter_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_degrees |number |"double|integer|long|unsigned_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_double |field |"boolean|date|keyword|text|double|long|unsigned_long|integer|counter_double|counter_integer|counter_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_dt |field |"date|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_dt |field |"date|date_nanos|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_geopoint |field |"geo_point|keyword|text" |Input value. The input can be a single- or multi-valued column or an expression.
to_geoshape |field |"geo_point|geo_shape|keyword|text" |Input value. The input can be a single- or multi-valued column or an expression.
to_int |field |"boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_integer |field |"boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_ip |field |"ip|keyword|text" |Input value. The input can be a single- or multi-valued column or an expression.
to_long |field |"boolean|date|keyword|text|double|long|unsigned_long|integer|counter_integer|counter_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_long |field |"boolean|date|date_nanos|keyword|text|double|long|unsigned_long|integer|counter_integer|counter_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_lower |str |"keyword|text" |String expression. If `null`, the function returns `null`.
to_radians |number |"double|integer|long|unsigned_long" |Input value. The input can be a single- or multi-valued column or an expression.
to_str |field |"boolean|cartesian_point|cartesian_shape|date|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version" |Input value. The input can be a single- or multi-valued column or an expression.
to_string |field |"boolean|cartesian_point|cartesian_shape|date|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version" |Input value. The input can be a single- or multi-valued column or an expression.
to_str |field |"boolean|cartesian_point|cartesian_shape|date|date_nanos|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version" |Input value. The input can be a single- or multi-valued column or an expression.
to_string |field |"boolean|cartesian_point|cartesian_shape|date|date_nanos|double|geo_point|geo_shape|integer|ip|keyword|long|text|unsigned_long|version" |Input value. The input can be a single- or multi-valued column or an expression.
to_ul |field |"boolean|date|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_ulong |field |"boolean|date|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
to_unsigned_lo|field |"boolean|date|keyword|text|double|long|unsigned_long|integer" |Input value. The input can be a single- or multi-valued column or an expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ public enum Cap {
/**
* Support CIDRMatch in CombineDisjunctions rule.
*/
COMBINE_DISJUNCTIVE_CIDRMATCHES;
COMBINE_DISJUNCTIVE_CIDRMATCHES,

/**
* Consider the upper bound when computing the interval in BUCKET auto mode.
*/
BUCKET_INCLUSIVE_UPPER_BOUND;

private final boolean snapshotOnly;
private final FeatureFlag featureFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.compute.ann.ConvertEvaluator;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
Expand All @@ -24,6 +25,7 @@
import java.util.Map;

import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
Expand All @@ -41,6 +43,7 @@ public class ToDatetime extends AbstractConvertFunction {

private static final Map<DataType, BuildFactory> EVALUATORS = Map.ofEntries(
Map.entry(DATETIME, (field, source) -> field),
Map.entry(DATE_NANOS, ToDatetimeFromDateNanosEvaluator.Factory::new),
Map.entry(LONG, (field, source) -> field),
Map.entry(KEYWORD, ToDatetimeFromStringEvaluator.Factory::new),
Map.entry(TEXT, ToDatetimeFromStringEvaluator.Factory::new),
Expand All @@ -55,6 +58,8 @@ public class ToDatetime extends AbstractConvertFunction {
Converts an input value to a date value.
A string will only be successfully converted if it's respecting the format `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`.
To convert dates in other formats, use <<esql-date_parse>>.""",
note = "Note that when converting from nanosecond resolution to millisecond resolution with this function, the nanosecond date is"
+ "truncated, not rounded.",
examples = {
@Example(file = "date", tag = "to_datetime-str", explanation = """
Note that in this example, the last value in the source multi-valued field has not been converted.
Expand All @@ -81,7 +86,7 @@ public ToDatetime(
Source source,
@Param(
name = "field",
type = { "date", "keyword", "text", "double", "long", "unsigned_long", "integer" },
type = { "date", "date_nanos", "keyword", "text", "double", "long", "unsigned_long", "integer" },
description = "Input value. The input can be a single- or multi-valued column or an expression."
) Expression field
) {
Expand Down Expand Up @@ -121,4 +126,9 @@ protected NodeInfo<? extends Expression> info() {
static long fromKeyword(BytesRef in) {
return dateTimeToLong(in.utf8ToString());
}

@ConvertEvaluator(extraName = "FromDateNanos", warnExceptions = { IllegalArgumentException.class })
static long fromDatenanos(long in) {
return DateUtils.toMilliSeconds(in);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
Expand All @@ -42,6 +43,7 @@ public class ToLong extends AbstractConvertFunction {
private static final Map<DataType, BuildFactory> EVALUATORS = Map.ofEntries(
Map.entry(LONG, (fieldEval, source) -> fieldEval),
Map.entry(DATETIME, (fieldEval, source) -> fieldEval),
Map.entry(DATE_NANOS, (fieldEval, source) -> fieldEval),
Map.entry(BOOLEAN, ToLongFromBooleanEvaluator.Factory::new),
Map.entry(KEYWORD, ToLongFromStringEvaluator.Factory::new),
Map.entry(TEXT, ToLongFromStringEvaluator.Factory::new),
Expand Down Expand Up @@ -76,6 +78,7 @@ public ToLong(
type = {
"boolean",
"date",
"date_nanos",
"keyword",
"text",
"double",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_POINT;
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_SHAPE;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_SHAPE;
Expand All @@ -40,6 +41,7 @@
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.dateTimeToString;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.ipToString;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.nanoTimeToString;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.numericBooleanToString;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.spatialToString;
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.unsignedLongToString;
Expand All @@ -52,6 +54,7 @@ public class ToString extends AbstractConvertFunction implements EvaluatorMapper
Map.entry(KEYWORD, (fieldEval, source) -> fieldEval),
Map.entry(BOOLEAN, ToStringFromBooleanEvaluator.Factory::new),
Map.entry(DATETIME, ToStringFromDatetimeEvaluator.Factory::new),
Map.entry(DATE_NANOS, ToStringFromDateNanosEvaluator.Factory::new),
Map.entry(IP, ToStringFromIPEvaluator.Factory::new),
Map.entry(DOUBLE, ToStringFromDoubleEvaluator.Factory::new),
Map.entry(LONG, ToStringFromLongEvaluator.Factory::new),
Expand Down Expand Up @@ -81,6 +84,7 @@ public ToString(
"cartesian_point",
"cartesian_shape",
"date",
"date_nanos",
"double",
"geo_point",
"geo_shape",
Expand Down Expand Up @@ -141,6 +145,11 @@ static BytesRef fromDatetime(long datetime) {
return new BytesRef(dateTimeToString(datetime));
}

@ConvertEvaluator(extraName = "FromDateNanos")
static BytesRef fromDateNanos(long datetime) {
return new BytesRef(nanoTimeToString(datetime));
}

@ConvertEvaluator(extraName = "FromDouble")
static BytesRef fromDouble(double dbl) {
return numericBooleanToString(dbl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,8 @@ public void testRegexOnInt() {

public void testUnsupportedTypesWithToString() {
// DATE_PERIOD and TIME_DURATION types have been added, but not really patched through the engine; i.e. supported.
final String supportedTypes =
"boolean or cartesian_point or cartesian_shape or datetime or geo_point or geo_shape or ip or numeric or string or version";
final String supportedTypes = "boolean or cartesian_point or cartesian_shape or date_nanos or datetime "
+ "or geo_point or geo_shape or ip or numeric or string or version";
verifyUnsupported(
"row period = 1 year | eval to_string(period)",
"line 1:28: argument of [to_string(period)] must be [" + supportedTypes + "], found value [period] type [date_period]"
Expand Down
Loading

0 comments on commit b0244f1

Please sign in to comment.