Skip to content

[ES|QL] Date nanos implicit casting in union types #123678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
42ce293
implicit casting for date nanos
fang-xing-esql Feb 26, 2025
e006e07
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Feb 26, 2025
5436afb
implicit casting for union typed field in logical plan
fang-xing-esql Feb 28, 2025
08d395c
Update docs/changelog/123678.yaml
fang-xing-esql Feb 28, 2025
93615fb
Merge branch 'main' into date-nanos-implicit-casting
elasticmachine Feb 28, 2025
3552ae3
more implicit casting for union typed field in logical plan
fang-xing-esql Mar 6, 2025
811c5a3
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 6, 2025
3fb26ed
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 14, 2025
b49a48d
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 14, 2025
29f7afe
refactor
fang-xing-esql Mar 18, 2025
ed8ce9b
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 18, 2025
c13e83c
support aggregations with bucket and more tests
fang-xing-esql Mar 19, 2025
e26d25d
correct typo
fang-xing-esql Mar 19, 2025
3b36978
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 19, 2025
02e2260
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Mar 27, 2025
29b1155
remove grok and dissect, add enrich
fang-xing-esql Apr 2, 2025
e0b903d
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 2, 2025
d0d46f6
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 3, 2025
654e6ce
more tests around date functions
fang-xing-esql Apr 4, 2025
612810e
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 4, 2025
700ef2a
Merge remote-tracking branch 'origin/main' into date-nanos-implicit-c…
craigtaverner Apr 11, 2025
2c5da6e
DateNanos should now require a minimum of three decimal places
craigtaverner Apr 11, 2025
76f19f3
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 21, 2025
279d368
refactor and remove implicit casting for numeric types
fang-xing-esql Apr 21, 2025
4fb446b
update tests
fang-xing-esql Apr 21, 2025
00b6229
fix tests
fang-xing-esql Apr 21, 2025
2d68f85
push down binary comparisons on date and date nanos union type fields
fang-xing-esql Apr 25, 2025
39acff6
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 25, 2025
8c04bcc
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 25, 2025
4284c16
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql Apr 25, 2025
56dd224
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql May 6, 2025
46e3c95
modify testSuggestedCast as date_nanos and date are casted to date_na…
fang-xing-esql May 6, 2025
7256326
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql May 7, 2025
deb3c41
Merge branch 'main' into date-nanos-implicit-casting
fang-xing-esql May 7, 2025
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
6 changes: 6 additions & 0 deletions docs/changelog/123678.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 123678
summary: Date nanos implicit casting
area: ES|QL
type: enhancement
issues:
- 110009
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class DateUtils {
.appendValue(MINUTE_OF_HOUR, 2)
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.appendFraction(NANO_OF_SECOND, 3, 9, true)
.appendFraction(NANO_OF_SECOND, 0, 9, true)
.appendOffsetId()
.toFormatter(Locale.ROOT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static org.elasticsearch.test.ListMatcher.matchesList;
import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.elasticsearch.xpack.esql.core.type.DataType.isMillisOrNanos;
import static org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase.Mode.SYNC;
import static org.elasticsearch.xpack.esql.tools.ProfileParser.parseProfile;
import static org.elasticsearch.xpack.esql.tools.ProfileParser.readProfileFromResponse;
Expand Down Expand Up @@ -724,6 +725,10 @@ public void testSuggestedCast() throws IOException {

for (int i = 0; i < listOfTypes.size(); i++) {
for (int j = i + 1; j < listOfTypes.size(); j++) {
if (isMillisOrNanos(listOfTypes.get(i)) && isMillisOrNanos(listOfTypes.get(j))) {
// datetime and date_nanos are casted to date_nanos implicitly
continue;
}
String query = String.format(Locale.ROOT, """
{
"query": "FROM index-%s,index-%s | LIMIT 100 | KEEP my_field"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class CsvTestsDataLoader {
);
private static final TestDataset AIRPORTS_WEB = new TestDataset("airports_web");
private static final TestDataset DATE_NANOS = new TestDataset("date_nanos");
private static final TestDataset DATE_NANOS_UNION_TYPES = new TestDataset("date_nanos_union_types");
private static final TestDataset COUNTRIES_BBOX = new TestDataset("countries_bbox");
private static final TestDataset COUNTRIES_BBOX_WEB = new TestDataset("countries_bbox_web");
private static final TestDataset AIRPORT_CITY_BOUNDARIES = new TestDataset("airport_city_boundaries");
Expand Down Expand Up @@ -192,6 +193,7 @@ public class CsvTestsDataLoader {
Map.entry(MULTIVALUE_GEOMETRIES.indexName, MULTIVALUE_GEOMETRIES),
Map.entry(MULTIVALUE_POINTS.indexName, MULTIVALUE_POINTS),
Map.entry(DATE_NANOS.indexName, DATE_NANOS),
Map.entry(DATE_NANOS_UNION_TYPES.indexName, DATE_NANOS_UNION_TYPES),
Map.entry(K8S.indexName, K8S),
Map.entry(DISTANCES.indexName, DISTANCES),
Map.entry(ADDRESSES.indexName, ADDRESSES),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
millis:date_nanos,nanos:date,num:long
2023-10-23T13:55:01.543123456Z,2023-10-23T13:55:01.543Z,1698069301543123456
2023-10-23T13:55:01.543123456Z,2023-10-23T13:55:01.543Z,1698069301543123456
2023-10-23T13:53:55.832987654Z,2023-10-23T13:53:55.832Z,1698069235832987654
2023-10-23T13:52:55.015787878Z,2023-10-23T13:52:55.015Z,1698069175015787878
2023-10-23T13:51:54.732102837Z,2023-10-23T13:51:54.732Z,1698069114732102837
2023-10-23T13:33:34.937193000Z,2023-10-23T13:33:34.937Z,1698068014937193000
2023-10-23T12:27:28.948000000Z,2023-10-23T12:27:28.948Z,1698064048948000000
2023-10-23T12:15:03.360103847Z,2023-10-23T12:15:03.360Z,1698063303360103847
2023-10-23T12:15:03.360103847Z,2023-10-23T12:15:03.360Z,1698063303360103847
1999-10-23T12:15:03.360103847Z,[2023-03-23T12:15:03.360Z, 2023-02-23T13:33:34.937Z, 2023-01-23T13:55:01.543Z], 0
1999-10-22T12:15:03.360103847Z,[2023-03-23T12:15:03.360Z, 2023-03-23T12:15:03.360Z, 2023-03-23T12:15:03.360Z], 0
2023-10-23T12:15:03.360103847Z,1923-10-23T12:15:03.360Z,1698063303360103847
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
birth_date:date_nanos ,emp_no:long,first_name:text,gender:text,hire_date:date_nanos,languages:byte,languages.long:long,languages.short:short,languages.byte:byte,last_name:text,salary:long,height:float,height.double:double,height.scaled_float:scaled_float,height.half_float:half_float,still_hired:keyword,avg_worked_seconds:unsigned_long,job_positions:text,is_rehired:keyword,salary_change:float,salary_change.int:integer,salary_change.long:long,salary_change.keyword:keyword
birth_date:date ,emp_no:long,first_name:text,gender:text,hire_date:date_nanos,languages:byte,languages.long:long,languages.short:short,languages.byte:byte,last_name:text,salary:long,height:float,height.double:double,height.scaled_float:scaled_float,height.half_float:half_float,still_hired:keyword,avg_worked_seconds:unsigned_long,job_positions:text,is_rehired:keyword,salary_change:float,salary_change.int:integer,salary_change.long:long,salary_change.keyword:keyword
1953-09-02T00:00:00Z,10001,Georgi ,M,1986-06-26T00:00:00Z,2,2,2,2,Facello ,57305,2.03,2.03,2.03,2.03,true ,268728049,[Senior Python Developer,Accountant],[false,true],[1.19],[1],[1],[1.19]
1964-06-02T00:00:00Z,10002,Bezalel ,F,1985-11-21T00:00:00Z,5,5,5,5,Simmel ,56371,2.08,2.08,2.08,2.08,true ,328922887,[Senior Team Lead],[false,false],[-7.23,11.17],[-7,11],[-7,11],[-7.23,11.17]
1959-12-03T00:00:00Z,10003,Parto ,M,1986-08-28T00:00:00Z,4,4,4,4,Bamford ,61805,1.83,1.83,1.83,1.83,false,200296405,[],[],[14.68,12.82],[14,12],[14,12],[14.68,12.82]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"properties": {
"millis": {
"type": "date_nanos"
},
"nanos": {
"type": "date"
},
"num": {
"type": "long"
}
}
}
Loading
Loading