Esql Enable Date Nanos (#117080)

This enables date nanos support as tech preview. Basic operations, like reading values, binary comparisons, and functions that don't care about type should work, but some functions are not yet supported. Most notably, Bucket is not yet supported, although Date_Trunc is and can be used for grouping. See the docs for the full list of limitations.

relates to #109352
This commit is contained in:
Mark Tozzi 2024-11-20 09:31:01 -05:00 committed by GitHub
parent 0e641793cb
commit c3f73d0319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
77 changed files with 716 additions and 40 deletions

View File

@ -0,0 +1,5 @@
pr: 117080
summary: Esql Enable Date Nanos (tech preview)
area: ES|QL
type: enhancement
issues: []

View File

@ -25,6 +25,9 @@ include::processing-commands/limit.asciidoc[tag=limitation]
* `alias`
* `boolean`
* `date`
* `date_nanos` (Tech Preview)
** The following functions don't yet support date nanos: `bucket`, `date_format`, `date_parse`, `date_diff`, `date_extract`
** You can use `to_datetime` to cast to millisecond dates to use unsupported functions
* `double` (`float`, `half_float`, `scaled_float` are represented as `double`)
* `ip`
* `keyword` family including `keyword`, `constant_keyword`, and `wildcard`
@ -50,7 +53,6 @@ include::processing-commands/limit.asciidoc[tag=limitation]
** `position`
** `aggregate_metric_double`
* Date/time
** `date_nanos`
** `date_range`
* Other types
** `binary`

View File

@ -172,6 +172,48 @@
"variadic" : true,
"returnType" : "date"
},
{
"params" : [
{
"name" : "condition",
"type" : "boolean",
"optional" : false,
"description" : "A condition."
},
{
"name" : "trueValue",
"type" : "date_nanos",
"optional" : false,
"description" : "The value that's returned when the corresponding condition is the first to evaluate to `true`. The default value is returned when no condition matches."
}
],
"variadic" : true,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "condition",
"type" : "boolean",
"optional" : false,
"description" : "A condition."
},
{
"name" : "trueValue",
"type" : "date_nanos",
"optional" : false,
"description" : "The value that's returned when the corresponding condition is the first to evaluate to `true`. The default value is returned when no condition matches."
},
{
"name" : "elseValue",
"type" : "date_nanos",
"optional" : true,
"description" : "The value that's returned when no condition evaluates to `true`."
}
],
"variadic" : true,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -88,6 +88,24 @@
"variadic" : true,
"returnType" : "date"
},
{
"params" : [
{
"name" : "first",
"type" : "date_nanos",
"optional" : false,
"description" : "Expression to evaluate."
},
{
"name" : "rest",
"type" : "date_nanos",
"optional" : true,
"description" : "Other expression to evaluate."
}
],
"variadic" : true,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -151,7 +151,7 @@
],
"examples" : [
"FROM employees\n| STATS COUNT(height)",
"FROM employees \n| STATS count = COUNT(*) BY languages \n| SORT languages DESC",
"FROM employees\n| STATS count = COUNT(*) BY languages\n| SORT languages DESC",
"ROW words=\"foo;bar;baz;qux;quux;foo\"\n| STATS word_count = COUNT(SPLIT(words, \";\"))",
"ROW n=1\n| WHERE n < 0\n| STATS COUNT(n)",
"ROW n=1\n| STATS COUNT(n > 0 OR NULL), COUNT(n < 0 OR NULL)"

View File

@ -136,6 +136,72 @@
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Column or literal for which to count the number of distinct values."
}
],
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Column or literal for which to count the number of distinct values."
},
{
"name" : "precision",
"type" : "integer",
"optional" : true,
"description" : "Precision threshold. Refer to <<esql-agg-count-distinct-approximate>>. The maximum supported value is 40000. Thresholds above this number will have the same effect as a threshold of 40000. The default value is 3000."
}
],
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Column or literal for which to count the number of distinct values."
},
{
"name" : "precision",
"type" : "long",
"optional" : true,
"description" : "Precision threshold. Refer to <<esql-agg-count-distinct-approximate>>. The maximum supported value is 40000. Thresholds above this number will have the same effect as a threshold of 40000. The default value is 3000."
}
],
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Column or literal for which to count the number of distinct values."
},
{
"name" : "precision",
"type" : "unsigned_long",
"optional" : true,
"description" : "Precision threshold. Refer to <<esql-agg-count-distinct-approximate>>. The maximum supported value is 40000. Thresholds above this number will have the same effect as a threshold of 40000. The default value is 3000."
}
],
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{

View File

@ -22,6 +22,24 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "interval",
"type" : "date_period",
"optional" : false,
"description" : "Interval; expressed using the timespan literal syntax."
},
{
"name" : "date",
"type" : "date_nanos",
"optional" : false,
"description" : "Date expression"
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
@ -39,6 +57,24 @@
],
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "interval",
"type" : "time_duration",
"optional" : false,
"description" : "Interval; expressed using the timespan literal syntax."
},
{
"name" : "date",
"type" : "date_nanos",
"optional" : false,
"description" : "Date expression"
}
],
"variadic" : false,
"returnType" : "date_nanos"
}
],
"examples" : [

View File

@ -77,6 +77,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -23,6 +23,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -23,6 +23,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -53,6 +53,24 @@
"variadic" : true,
"returnType" : "date"
},
{
"params" : [
{
"name" : "first",
"type" : "date_nanos",
"optional" : false,
"description" : "First of the columns to evaluate."
},
{
"name" : "rest",
"type" : "date_nanos",
"optional" : true,
"description" : "The rest of the columns to evaluate."
}
],
"variadic" : true,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -52,6 +52,24 @@
"variadic" : true,
"returnType" : "date"
},
{
"params" : [
{
"name" : "first",
"type" : "date_nanos",
"optional" : false,
"description" : "First of the columns to evaluate."
},
{
"name" : "rest",
"type" : "date_nanos",
"optional" : true,
"description" : "The rest of the columns to evaluate."
}
],
"variadic" : true,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -23,6 +23,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -23,6 +23,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -78,7 +78,7 @@
}
],
"examples" : [
"from books \n| where match(author, \"Faulkner\")\n| keep book_no, author \n| sort book_no \n| limit 5;"
"FROM books \n| WHERE MATCH(author, \"Faulkner\")\n| KEEP book_no, author \n| SORT book_no \n| LIMIT 5;"
],
"preview" : true,
"snapshot_only" : false

View File

@ -28,6 +28,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : ""
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -28,6 +28,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : ""
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -52,6 +52,18 @@
"variadic" : false,
"returnType" : "integer"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "integer"
},
{
"params" : [
{

View File

@ -53,6 +53,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -52,6 +52,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -52,6 +52,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -28,6 +28,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -28,6 +28,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -100,6 +100,30 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression. If `null`, the function returns `null`."
},
{
"name" : "start",
"type" : "integer",
"optional" : false,
"description" : "Start position. If `null`, the function returns `null`. The start argument can be negative. An index of -1 is used to specify the last value in the list."
},
{
"name" : "end",
"type" : "integer",
"optional" : true,
"description" : "End position(included). Optional; if omitted, the position at `start` is returned. The end argument can be negative. An index of -1 is used to specify the last value in the list."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -40,6 +40,24 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Multivalue expression. If `null`, the function returns `null`."
},
{
"name" : "order",
"type" : "keyword",
"optional" : true,
"description" : "Sort order. The valid options are ASC and DESC, the default is ASC."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -77,6 +77,24 @@
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{
"name" : "lhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
},
{
"name" : "rhs",
"type" : "date_nanos",
"optional" : false,
"description" : "An expression."
}
],
"variadic" : false,
"returnType" : "boolean"
},
{
"params" : [
{

View File

@ -30,7 +30,7 @@
}
],
"examples" : [
"from books \n| where qstr(\"author: Faulkner\")\n| keep book_no, author \n| sort book_no \n| limit 5;"
"FROM books \n| WHERE QSTR(\"author: Faulkner\")\n| KEEP book_no, author \n| SORT book_no \n| LIMIT 5;"
],
"preview" : true,
"snapshot_only" : false

View File

@ -4,7 +4,92 @@
"name" : "to_date_nanos",
"description" : "Converts an input to a nanosecond-resolution date value (aka date_nanos).",
"note" : "The range for date nanos is 1970-01-01T00:00:00.000000000Z to 2262-04-11T23:47:16.854775807Z. Additionally, integers cannot be converted into date nanos, as the range of integer nanoseconds only covers about 2 seconds after epoch.",
"signatures" : [ ],
"signatures" : [
{
"params" : [
{
"name" : "field",
"type" : "date",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "double",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "keyword",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "long",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "text",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{
"name" : "field",
"type" : "unsigned_long",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date_nanos"
}
],
"preview" : true,
"snapshot_only" : false
}

View File

@ -17,6 +17,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{

View File

@ -52,6 +52,18 @@
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "long"
},
{
"params" : [
{

View File

@ -52,6 +52,18 @@
"variadic" : false,
"returnType" : "keyword"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : "Input value. The input can be a single- or multi-valued column or an expression."
}
],
"variadic" : false,
"returnType" : "keyword"
},
{
"params" : [
{

View File

@ -28,6 +28,18 @@
"variadic" : false,
"returnType" : "date"
},
{
"params" : [
{
"name" : "field",
"type" : "date_nanos",
"optional" : false,
"description" : ""
}
],
"variadic" : false,
"returnType" : "date_nanos"
},
{
"params" : [
{

View File

@ -6,9 +6,9 @@ This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../READ
Performs a match query on the specified field. Returns true if the provided query matches the row.
```
from books
| where match(author, "Faulkner")
| keep book_no, author
| sort book_no
| limit 5;
FROM books
| WHERE MATCH(author, "Faulkner")
| KEEP book_no, author
| SORT book_no
| LIMIT 5;
```

View File

@ -6,9 +6,9 @@ This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../READ
Performs a query string query. Returns true if the provided query string matches the row.
```
from books
| where qstr("author: Faulkner")
| keep book_no, author
| sort book_no
| limit 5;
FROM books
| WHERE QSTR("author: Faulkner")
| KEEP book_no, author
| SORT book_no
| LIMIT 5;
```

View File

@ -13,6 +13,8 @@ boolean | cartesian_shape | cartesian_shape | cartesian_shape
boolean | cartesian_shape | | cartesian_shape
boolean | date | date | date
boolean | date | | date
boolean | date_nanos | date_nanos | date_nanos
boolean | date_nanos | | date_nanos
boolean | double | double | double
boolean | double | | double
boolean | geo_point | geo_point | geo_point

View File

@ -10,6 +10,7 @@ boolean | | boolean
cartesian_point | cartesian_point | cartesian_point
cartesian_shape | cartesian_shape | cartesian_shape
date | date | date
date_nanos | date_nanos | date_nanos
geo_point | geo_point | geo_point
geo_shape | geo_shape | geo_shape
integer | integer | integer

View File

@ -13,6 +13,10 @@ date | integer | long
date | long | long
date | unsigned_long | long
date | | long
date_nanos | integer | long
date_nanos | long | long
date_nanos | unsigned_long | long
date_nanos | | long
double | integer | long
double | long | long
double | unsigned_long | long

View File

@ -6,5 +6,7 @@
|===
interval | date | result
date_period | date | date
date_period | date_nanos | date_nanos
time_duration | date | date
time_duration | date_nanos | date_nanos
|===

View File

@ -9,6 +9,7 @@ boolean | boolean | boolean
cartesian_point | cartesian_point | boolean
cartesian_shape | cartesian_shape | boolean
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -6,6 +6,7 @@
|===
lhs | rhs | result
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -6,6 +6,7 @@
|===
lhs | rhs | result
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -8,6 +8,7 @@ first | rest | result
boolean | boolean | boolean
boolean | | boolean
date | date | date
date_nanos | date_nanos | date_nanos
double | double | double
integer | integer | integer
integer | | integer

View File

@ -8,6 +8,7 @@ first | rest | result
boolean | boolean | boolean
boolean | | boolean
date | date | date
date_nanos | date_nanos | date_nanos
double | double | double
integer | integer | integer
integer | | integer

View File

@ -6,6 +6,7 @@
|===
lhs | rhs | result
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -6,6 +6,7 @@
|===
lhs | rhs | result
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -7,6 +7,7 @@
field | result
boolean | boolean
date | date
date_nanos | date_nanos
double | double
integer | integer
ip | ip

View File

@ -7,6 +7,7 @@
field | result
boolean | boolean
date | date
date_nanos | date_nanos
double | double
integer | integer
ip | ip

View File

@ -9,6 +9,7 @@ boolean | integer
cartesian_point | integer
cartesian_shape | integer
date | integer
date_nanos | integer
double | integer
geo_point | integer
geo_shape | integer

View File

@ -9,6 +9,7 @@ boolean | boolean
cartesian_point | cartesian_point
cartesian_shape | cartesian_shape
date | date
date_nanos | date_nanos
double | double
geo_point | geo_point
geo_shape | geo_shape

View File

@ -9,6 +9,7 @@ boolean | boolean
cartesian_point | cartesian_point
cartesian_shape | cartesian_shape
date | date
date_nanos | date_nanos
double | double
geo_point | geo_point
geo_shape | geo_shape

View File

@ -9,6 +9,7 @@ boolean | boolean
cartesian_point | cartesian_point
cartesian_shape | cartesian_shape
date | date
date_nanos | date_nanos
double | double
geo_point | geo_point
geo_shape | geo_shape

View File

@ -7,6 +7,7 @@
field | result
boolean | boolean
date | date
date_nanos | date_nanos
double | double
integer | integer
ip | ip

View File

@ -7,6 +7,7 @@
field | result
boolean | boolean
date | date
date_nanos | date_nanos
double | double
integer | integer
ip | ip

View File

@ -9,6 +9,7 @@ boolean | integer | integer | boolean
cartesian_point | integer | integer | cartesian_point
cartesian_shape | integer | integer | cartesian_shape
date | integer | integer | date
date_nanos | integer | integer | date_nanos
double | integer | integer | double
geo_point | integer | integer | geo_point
geo_shape | integer | integer | geo_shape

View File

@ -7,6 +7,7 @@
field | order | result
boolean | keyword | boolean
date | keyword | date
date_nanos | keyword | date_nanos
double | keyword | double
integer | keyword | integer
ip | keyword | ip

View File

@ -9,6 +9,7 @@ boolean | boolean | boolean
cartesian_point | cartesian_point | boolean
cartesian_shape | cartesian_shape | boolean
date | date | boolean
date_nanos | date_nanos | boolean
double | double | boolean
double | integer | boolean
double | long | boolean

View File

@ -5,5 +5,11 @@
[%header.monospaced.styled,format=dsv,separator=|]
|===
field | result
date_nanos
date | date_nanos
date_nanos | date_nanos
double | date_nanos
keyword | date_nanos
long | date_nanos
text | date_nanos
unsigned_long | date_nanos
|===

View File

@ -6,6 +6,7 @@
|===
field | result
date | date
date_nanos | date
double | date
integer | date
keyword | date

View File

@ -9,6 +9,7 @@ boolean | long
counter_integer | long
counter_long | long
date | long
date_nanos | long
double | long
integer | long
keyword | long

View File

@ -9,6 +9,7 @@ boolean | keyword
cartesian_point | keyword
cartesian_shape | keyword
date | keyword
date_nanos | keyword
double | keyword
geo_point | keyword
geo_shape | keyword

View File

@ -7,6 +7,7 @@
field | result
boolean | boolean
date | date
date_nanos | date_nanos
double | double
integer | integer
ip | ip

View File

@ -12,7 +12,6 @@ import org.elasticsearch.plugins.ExtensiblePlugin;
import org.elasticsearch.plugins.Plugin;
public class EsqlCorePlugin extends Plugin implements ExtensiblePlugin {
public static final FeatureFlag DATE_NANOS_FEATURE_FLAG = new FeatureFlag("esql_date_nanos");
public static final FeatureFlag SEMANTIC_TEXT_FEATURE_FLAG = new FeatureFlag("esql_semantic_text");
}

View File

@ -209,7 +209,6 @@ 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(DATE_NANOS, EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
Map.entry(SEMANTIC_TEXT, EsqlCorePlugin.SEMANTIC_TEXT_FEATURE_FLAG)
);

View File

@ -322,32 +322,32 @@ public class EsqlCapabilities {
/**
* Support for nanosecond dates as a data type
*/
DATE_NANOS_TYPE(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
DATE_NANOS_TYPE(),
/**
* Support for to_date_nanos function
*/
TO_DATE_NANOS(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
TO_DATE_NANOS(),
/**
* Support for date nanos type in binary comparisons
*/
DATE_NANOS_BINARY_COMPARISON(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
DATE_NANOS_BINARY_COMPARISON(),
/**
* Support Least and Greatest functions on Date Nanos type
*/
LEAST_GREATEST_FOR_DATENANOS(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
LEAST_GREATEST_FOR_DATENANOS(),
/**
* Support for date_trunc function on date nanos type
*/
DATE_TRUNC_DATE_NANOS(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
DATE_TRUNC_DATE_NANOS(),
/**
* support aggregations on date nanos
*/
DATE_NANOS_AGGREGATIONS(EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
DATE_NANOS_AGGREGATIONS(),
/**
* Support for datetime in least and greatest functions

View File

@ -501,7 +501,9 @@ public class EsqlFunctionRegistry {
types.add(type);
}
}
return types.stream()
.filter(DATA_TYPE_CASTING_PRIORITY::containsKey)
.min((dt1, dt2) -> DATA_TYPE_CASTING_PRIORITY.get(dt1).compareTo(DATA_TYPE_CASTING_PRIORITY.get(dt2)))
.orElse(UNSUPPORTED);
}

View File

@ -55,7 +55,7 @@ public class Max extends AggregateFunction implements ToAggregator, SurrogateExp
);
@FunctionInfo(
returnType = { "boolean", "double", "integer", "long", "date", "ip", "keyword", "long", "version" },
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "long", "version" },
description = "The maximum value of a field.",
isAggregation = true,
examples = {
@ -72,7 +72,7 @@ public class Max extends AggregateFunction implements ToAggregator, SurrogateExp
Source source,
@Param(
name = "field",
type = { "boolean", "double", "integer", "long", "date", "ip", "keyword", "text", "long", "version" }
type = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "text", "long", "version" }
) Expression field
) {
this(source, field, Literal.TRUE);

View File

@ -55,7 +55,7 @@ public class Min extends AggregateFunction implements ToAggregator, SurrogateExp
);
@FunctionInfo(
returnType = { "boolean", "double", "integer", "long", "date", "ip", "keyword", "long", "version" },
returnType = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "long", "version" },
description = "The minimum value of a field.",
isAggregation = true,
examples = {
@ -72,7 +72,7 @@ public class Min extends AggregateFunction implements ToAggregator, SurrogateExp
Source source,
@Param(
name = "field",
type = { "boolean", "double", "integer", "long", "date", "ip", "keyword", "text", "long", "version" }
type = { "boolean", "double", "integer", "long", "date", "date_nanos", "ip", "keyword", "text", "long", "version" }
) Expression field
) {
this(source, field, Literal.TRUE);

View File

@ -52,7 +52,7 @@ public class Values extends AggregateFunction implements ToAggregator {
);
@FunctionInfo(
returnType = { "boolean", "date", "double", "integer", "ip", "keyword", "long", "version" },
returnType = { "boolean", "date", "date_nanos", "double", "integer", "ip", "keyword", "long", "version" },
preview = true,
description = "Returns all values in a group as a multivalued field. The order of the returned values isn't guaranteed. "
+ "If you need the values returned in order use <<esql-mv_sort>>.",
@ -70,7 +70,10 @@ public class Values extends AggregateFunction implements ToAggregator {
)
public Values(
Source source,
@Param(name = "field", type = { "boolean", "date", "double", "integer", "ip", "keyword", "long", "text", "version" }) Expression v
@Param(
name = "field",
type = { "boolean", "date", "date_nanos", "double", "integer", "ip", "keyword", "long", "text", "version" }
) Expression v
) {
this(source, v, Literal.TRUE);
}

View File

@ -62,7 +62,7 @@ public class DateTrunc extends EsqlScalarFunction {
protected static final ZoneId DEFAULT_TZ = ZoneOffset.UTC;
@FunctionInfo(
returnType = "date",
returnType = { "date", "date_nanos" },
description = "Rounds down a date to the closest interval.",
examples = {
@Example(file = "date", tag = "docsDateTrunc"),
@ -83,7 +83,7 @@ public class DateTrunc extends EsqlScalarFunction {
type = { "date_period", "time_duration" },
description = "Interval; expressed using the timespan literal syntax."
) Expression interval,
@Param(name = "date", type = { "date" }, description = "Date expression") Expression field
@Param(name = "date", type = { "date", "date_nanos" }, description = "Date expression") Expression field
) {
super(source, List.of(interval, field));
this.interval = interval;

View File

@ -53,12 +53,12 @@ public class LessThan extends EsqlBinaryComparison implements Negatable<EsqlBina
Source source,
@Param(
name = "lhs",
type = { "boolean", "date", "double", "integer", "ip", "keyword", "long", "text", "unsigned_long", "version" },
type = { "boolean", "date_nanos", "date", "double", "integer", "ip", "keyword", "long", "text", "unsigned_long", "version" },
description = "An expression."
) Expression left,
@Param(
name = "rhs",
type = { "boolean", "date", "double", "integer", "ip", "keyword", "long", "text", "unsigned_long", "version" },
type = { "boolean", "date_nanos", "date", "double", "integer", "ip", "keyword", "long", "text", "unsigned_long", "version" },
description = "An expression."
) Expression right
) {

View File

@ -262,6 +262,42 @@ public final class MultiRowTestCaseSupplier {
return cases;
}
/**
*
* Generate cases for {@link DataType#DATE_NANOS}.
*
*/
public static List<TypedDataSupplier> dateNanosCases(int minRows, int maxRows) {
List<TypedDataSupplier> cases = new ArrayList<>();
addSuppliers(cases, minRows, maxRows, "<1970-01-01T00:00:00.000000000Z>", DataType.DATE_NANOS, () -> 0L);
addSuppliers(
cases,
minRows,
maxRows,
"<date nanos>",
DataType.DATE_NANOS,
() -> ESTestCase.randomLongBetween(0, 10 * (long) 10e11)
);
addSuppliers(
cases,
minRows,
maxRows,
"<far future date nanos>",
DataType.DATE_NANOS,
() -> ESTestCase.randomLongBetween(10 * (long) 10e11, Long.MAX_VALUE)
);
addSuppliers(
cases,
minRows,
maxRows,
"<nanos near the end of time>",
DataType.DATE_NANOS,
() -> ESTestCase.randomLongBetween(Long.MAX_VALUE / 100 * 99, Long.MAX_VALUE)
);
return cases;
}
public static List<TypedDataSupplier> booleanCases(int minRows, int maxRows) {
List<TypedDataSupplier> cases = new ArrayList<>();

View File

@ -52,6 +52,7 @@ public class CountDistinctTests extends AbstractAggregationTestCase {
MultiRowTestCaseSupplier.longCases(1, 1000, Long.MIN_VALUE, Long.MAX_VALUE, true),
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true),
MultiRowTestCaseSupplier.dateCases(1, 1000),
MultiRowTestCaseSupplier.dateNanosCases(1, 1000),
MultiRowTestCaseSupplier.booleanCases(1, 1000),
MultiRowTestCaseSupplier.ipCases(1, 1000),
MultiRowTestCaseSupplier.versionCases(1, 1000),

View File

@ -90,6 +90,15 @@ public class MaxTests extends AbstractAggregationTestCase {
equalTo(200L)
)
),
new TestCaseSupplier(
List.of(DataType.DATE_NANOS),
() -> new TestCaseSupplier.TestCase(
List.of(TestCaseSupplier.TypedData.multiRow(List.of(200L), DataType.DATE_NANOS, "field")),
"Max[field=Attribute[channel=0]]",
DataType.DATE_NANOS,
equalTo(200L)
)
),
new TestCaseSupplier(
List.of(DataType.BOOLEAN),
() -> new TestCaseSupplier.TestCase(

View File

@ -90,6 +90,15 @@ public class MinTests extends AbstractAggregationTestCase {
equalTo(200L)
)
),
new TestCaseSupplier(
List.of(DataType.DATE_NANOS),
() -> new TestCaseSupplier.TestCase(
List.of(TestCaseSupplier.TypedData.multiRow(List.of(200L), DataType.DATE_NANOS, "field")),
"Min[field=Attribute[channel=0]]",
DataType.DATE_NANOS,
equalTo(200L)
)
),
new TestCaseSupplier(
List.of(DataType.BOOLEAN),
() -> new TestCaseSupplier.TestCase(

View File

@ -45,6 +45,7 @@ public class ValuesTests extends AbstractAggregationTestCase {
MultiRowTestCaseSupplier.longCases(1, 1000, Long.MIN_VALUE, Long.MAX_VALUE, true),
MultiRowTestCaseSupplier.doubleCases(1, 1000, -Double.MAX_VALUE, Double.MAX_VALUE, true),
MultiRowTestCaseSupplier.dateCases(1, 1000),
MultiRowTestCaseSupplier.dateNanosCases(1, 1000),
MultiRowTestCaseSupplier.booleanCases(1, 1000),
MultiRowTestCaseSupplier.ipCases(1, 1000),
MultiRowTestCaseSupplier.versionCases(1, 1000),

View File

@ -14,7 +14,6 @@ import org.elasticsearch.geo.ShapeTestUtils;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.plugin.EsqlCorePlugin;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.core.util.NumericUtils;
@ -397,9 +396,6 @@ public abstract class AbstractMultivalueFunctionTestCase extends AbstractScalarF
DataType expectedDataType,
BiFunction<Integer, LongStream, Matcher<Object>> matcher
) {
if (EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG.isEnabled() == false) {
return;
}
cases.add(
new TestCaseSupplier(
name + "(epoch nanos)",

View File

@ -113,8 +113,8 @@ public class LessThanTests extends AbstractScalarFunctionTestCase {
"rhs",
(l, r) -> ((Number) l).longValue() < ((Number) r).longValue(),
DataType.BOOLEAN,
TestCaseSupplier.dateCases(),
TestCaseSupplier.dateCases(),
TestCaseSupplier.dateNanosCases(),
TestCaseSupplier.dateNanosCases(),
List.of(),
false
)