mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
ES|QL: Support ::date
in inline cast (#123460)
* Inline cast to date * Update docs/changelog/123460.yaml * New capability for `::date` casting * More tests * Update tests --------- Co-authored-by: Fang Xing <155562079+fang-xing-esql@users.noreply.github.com>
This commit is contained in:
parent
74ccd4dba2
commit
deff3df9f0
5 changed files with 113 additions and 0 deletions
6
docs/changelog/123460.yaml
Normal file
6
docs/changelog/123460.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
pr: 123460
|
||||
summary: "ES|QL: Support `::date` in inline cast"
|
||||
area: ES|QL
|
||||
type: enhancement
|
||||
issues:
|
||||
- 116746
|
|
@ -3,6 +3,7 @@
|
|||
"boolean" : "to_boolean",
|
||||
"cartesian_point" : "to_cartesianpoint",
|
||||
"cartesian_shape" : "to_cartesianshape",
|
||||
"date" : "to_datetime",
|
||||
"date_nanos" : "to_date_nanos",
|
||||
"date_period" : "to_dateperiod",
|
||||
"datetime" : "to_datetime",
|
||||
|
|
|
@ -407,6 +407,7 @@ public enum DataType {
|
|||
map.put("bool", BOOLEAN);
|
||||
map.put("int", INTEGER);
|
||||
map.put("string", KEYWORD);
|
||||
map.put("date", DataType.DATETIME);
|
||||
NAME_OR_ALIAS_TO_TYPE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,15 @@ ROW date="1985-01-01T00:00:00Z"::datetime, zero=0::datetime
|
|||
1985-01-01T00:00:00.000Z|1970-01-01T00:00:00.000Z
|
||||
;
|
||||
|
||||
convertToDate
|
||||
required_capability: casting_operator_for_date
|
||||
ROW date="1985-01-01T00:00:00Z"::date, zero=0::date
|
||||
;
|
||||
|
||||
date:datetime | zero:datetime
|
||||
1985-01-01T00:00:00.000Z|1970-01-01T00:00:00.000Z
|
||||
;
|
||||
|
||||
convertToVersion
|
||||
required_capability: casting_operator
|
||||
ROW ver="1.2.3"::version
|
||||
|
@ -351,3 +360,94 @@ z = birth_date + 3 hours + 3 minutes::time_duration, w = birth_date + (3 hours +
|
|||
birth_date:datetime |x:datetime |y:datetime |z:datetime |w:datetime
|
||||
1953-09-02T00:00:00Z |1953-09-02T03:00:00Z |1953-09-01T21:00:00Z |1953-09-02T03:03:00Z |1953-09-02T03:03:00Z
|
||||
;
|
||||
|
||||
convertToDatePeriodWithDateCasting
|
||||
required_capability: cast_string_literal_to_temporal_amount
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "2024-01-01"::date
|
||||
| eval y = x + "3 DAYS"::date_period
|
||||
;
|
||||
|
||||
x:datetime |y:datetime
|
||||
2024-01-01 |2024-01-04
|
||||
;
|
||||
|
||||
convertToTimeDurationWithDateCasting
|
||||
required_capability: cast_string_literal_to_temporal_amount
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "2024-01-01"::date
|
||||
| eval y = x + "3 hours"::time_duration
|
||||
;
|
||||
|
||||
x:datetime |y:datetime
|
||||
2024-01-01 |2024-01-01T03:00:00.000Z
|
||||
;
|
||||
|
||||
convertToDatePeriodTimeDurationWithDateCasting
|
||||
required_capability: cast_string_literal_to_temporal_amount
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "2024-01-01"::date + "3 hours"::time_duration, y = "2024-01-01"::date - to_timeduration("3 hours"),
|
||||
z = "2024-01-01"::date + "3 DAYS"::date_period, w = "2024-01-01"::date - to_dateperiod("3 days")
|
||||
| keep x, y, z, w;
|
||||
|
||||
x:datetime |y:datetime |z:datetime |w:datetime
|
||||
2024-01-01T03:00:00.000Z |2023-12-31T21:00:00.000Z |2024-01-04T00:00:00.000Z |2023-12-29T00:00:00.000Z
|
||||
;
|
||||
|
||||
convertToDatePeriodNestedWithDateCasting
|
||||
required_capability: cast_string_literal_to_temporal_amount
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "2024-01-01"::date
|
||||
| eval y = x + to_dateperiod("3 days"::date_period)
|
||||
;
|
||||
|
||||
x:datetime |y:datetime
|
||||
2024-01-01 |2024-01-04
|
||||
;
|
||||
|
||||
convertToTimeDurationNestedWithDateCasting
|
||||
required_capability: cast_string_literal_to_temporal_amount
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "2024-01-01"::date
|
||||
| eval y = x + to_timeduration("3 hours"::time_duration)
|
||||
;
|
||||
|
||||
x:datetime |y:datetime
|
||||
2024-01-01 |2024-01-01T03:00:00.000Z
|
||||
;
|
||||
|
||||
testEvalWithDateCasting
|
||||
required_capability: casting_operator_for_date
|
||||
row x = "1986-06-26T00:00:00.000Z"
|
||||
| eval y = x::date, z = y + 10 years
|
||||
;
|
||||
|
||||
x:keyword | y:datetime | z:datetime
|
||||
1986-06-26T00:00:00.000Z | 1986-06-26T00:00:00.000Z | 1996-06-26T00:00:00.000Z
|
||||
;
|
||||
|
||||
|
||||
filteringWithDateCasting
|
||||
required_capability: casting_operator_for_date
|
||||
from employees
|
||||
| where birth_date < "2023-08-25T11:25:41.052Z"::date - 70 years
|
||||
| sort emp_no
|
||||
| keep emp_no, birth_date;
|
||||
|
||||
emp_no:integer | birth_date:datetime
|
||||
10006 | 1953-04-20T00:00:00.000Z
|
||||
10009 | 1952-04-19T00:00:00.000Z
|
||||
10019 | 1953-01-23T00:00:00.000Z
|
||||
10020 | 1952-12-24T00:00:00.000Z
|
||||
10022 | 1952-07-08T00:00:00.000Z
|
||||
10026 | 1953-04-03T00:00:00.000Z
|
||||
10035 | 1953-02-08T00:00:00.000Z
|
||||
10051 | 1953-07-28T00:00:00.000Z
|
||||
10063 | 1952-08-06T00:00:00.000Z
|
||||
10066 | 1952-11-13T00:00:00.000Z
|
||||
10067 | 1953-01-07T00:00:00.000Z
|
||||
10072 | 1952-05-15T00:00:00.000Z
|
||||
10076 | 1952-06-13T00:00:00.000Z
|
||||
10097 | 1952-02-27T00:00:00.000Z
|
||||
10100 | 1953-04-21T00:00:00.000Z
|
||||
;
|
||||
|
|
|
@ -112,6 +112,11 @@ public class EsqlCapabilities {
|
|||
*/
|
||||
CASTING_OPERATOR,
|
||||
|
||||
/**
|
||||
* Support for the ::date casting operator
|
||||
*/
|
||||
CASTING_OPERATOR_FOR_DATE,
|
||||
|
||||
/**
|
||||
* Blocks can be labelled with {@link org.elasticsearch.compute.data.Block.MvOrdering#SORTED_ASCENDING} for optimizations.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue