Skip to content

[ES|QL] Date nanos implicit casting in union types option #2 #127797

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 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
3b99762
implicit casting for date and date_nanos in EsRelation
fang-xing-esql May 7, 2025
131ab6c
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 7, 2025
437bfdc
update testSuggestedCast as date and date_nanos are cast to date_nano…
fang-xing-esql May 7, 2025
fc88626
Update docs/changelog/127797.yaml
fang-xing-esql May 7, 2025
3c257fb
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 7, 2025
b0abae7
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 7, 2025
83650e9
clean up
fang-xing-esql May 7, 2025
f9cf6fb
fix multi cluster tests
fang-xing-esql May 7, 2025
236bb57
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 21, 2025
5dd906e
refactor and remove pushdown optimization
fang-xing-esql May 23, 2025
e7b8cd7
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 23, 2025
1e57eb8
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 23, 2025
1510069
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 23, 2025
56db2a5
more tests on invalid nanos valid millis
fang-xing-esql May 23, 2025
71306d9
more tests on implicit and explicit casting
fang-xing-esql May 23, 2025
c95bdbb
[CI] Auto commit changes from spotless
elasticsearchmachine May 23, 2025
48524be
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 25, 2025
1b53d41
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 25, 2025
e65814d
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql May 27, 2025
5202447
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql Jun 3, 2025
da2bf6f
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql Jun 3, 2025
d4e4d70
more tests and validation of data type conversions
fang-xing-esql Jun 4, 2025
be6a68d
Merge branch 'main' into date-nanos-implicit-casting-2
fang-xing-esql Jun 4, 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/127797.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 127797
summary: "Date nanos implicit casting in union types option #2"
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
1 change: 1 addition & 0 deletions x-pack/plugin/esql/qa/server/single-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
javaRestTestImplementation project(xpackModule('esql:qa:testFixtures'))
javaRestTestImplementation project(xpackModule('esql:qa:server'))
javaRestTestImplementation project(xpackModule('esql:tools'))
javaRestTestImplementation project(xpackModule('esql'))
yamlRestTestImplementation project(xpackModule('esql:qa:server'))

javaRestTestImplementation('org.apache.arrow:arrow-vector:16.1.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
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.action.EsqlCapabilities.Cap.IMPLICIT_CASTING_DATE_AND_DATE_NANOS;
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 @@ -736,19 +738,26 @@ public void testSuggestedCast() throws IOException {
Map<String, Object> results = entityAsMap(resp);
List<?> columns = (List<?>) results.get("columns");
DataType suggestedCast = DataType.suggestedCast(Set.of(listOfTypes.get(i), listOfTypes.get(j)));
assertThat(
columns,
equalTo(
List.of(
Map.ofEntries(
Map.entry("name", "my_field"),
Map.entry("type", "unsupported"),
Map.entry("original_types", List.of(listOfTypes.get(i).typeName(), listOfTypes.get(j).typeName())),
Map.entry("suggested_cast", suggestedCast.typeName())
if (IMPLICIT_CASTING_DATE_AND_DATE_NANOS.isEnabled()
&& isMillisOrNanos(listOfTypes.get(i))
&& isMillisOrNanos(listOfTypes.get(j))) {
// datetime and date_nanos are casted to date_nanos implicitly
assertThat(columns, equalTo(List.of(Map.ofEntries(Map.entry("name", "my_field"), Map.entry("type", "date_nanos")))));
} else {
assertThat(
columns,
equalTo(
List.of(
Map.ofEntries(
Map.entry("name", "my_field"),
Map.entry("type", "unsupported"),
Map.entry("original_types", List.of(listOfTypes.get(i).typeName(), listOfTypes.get(j).typeName())),
Map.entry("suggested_cast", suggestedCast.typeName())
)
)
)
)
);
);
}

String castedQuery = String.format(
Locale.ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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 @@ -197,6 +198,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