Skip to content

Commit db57280

Browse files
[8.x] [ESQL] test date nanos union type (#116265) (#116602)
* [ESQL] test date nanos union type (#116265) Resolves #112885 This PR adds a bunch of basic testing for using TO_DATE_NANOS as a union type. It also tests the TO_DATETIME union type for casting date nanos. There are still some cases that aren't covered here, mostly because we haven't finished adding date nanos support to all the relevant functions. I expect we'll add in those cases as we add functions support. --------- Co-authored-by: Elastic Machine <[email protected]> * add capability check * add capability check --------- Co-authored-by: Elastic Machine <[email protected]>
1 parent 087bfd3 commit db57280

File tree

4 files changed

+349
-139
lines changed

4 files changed

+349
-139
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
1414
import org.elasticsearch.common.network.InetAddresses;
1515
import org.elasticsearch.common.time.DateFormatters;
16+
import org.elasticsearch.common.time.DateUtils;
1617
import org.elasticsearch.common.util.BigArrays;
1718
import org.elasticsearch.compute.data.Block;
1819
import org.elasticsearch.compute.data.BlockFactory;
@@ -471,7 +472,7 @@ public enum Type {
471472
return null;
472473
}
473474
Instant parsed = DateFormatters.from(ISO_DATE_WITH_NANOS.parse(x)).toInstant();
474-
return parsed.getEpochSecond() * 1_000_000_000 + parsed.getNano();
475+
return DateUtils.toLong(parsed);
475476
}, (l, r) -> l instanceof Long maybeIP ? maybeIP.compareTo((Long) r) : l.toString().compareTo(r.toString()), Long.class),
476477
BOOLEAN(Booleans::parseBoolean, Boolean.class),
477478
GEO_POINT(x -> x == null ? null : GEO.wktToWkb(x), BytesRef.class),

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class CsvTestsDataLoader {
6464
private static final TestsDataset SAMPLE_DATA_TS_LONG = SAMPLE_DATA.withIndex("sample_data_ts_long")
6565
.withData("sample_data_ts_long.csv")
6666
.withTypeMapping(Map.of("@timestamp", "long"));
67+
private static final TestsDataset SAMPLE_DATA_TS_NANOS = SAMPLE_DATA.withIndex("sample_data_ts_nanos")
68+
.withData("sample_data_ts_nanos.csv")
69+
.withTypeMapping(Map.of("@timestamp", "date_nanos"));
6770
private static final TestsDataset MISSING_IP_SAMPLE_DATA = new TestsDataset("missing_ip_sample_data");
6871
private static final TestsDataset CLIENT_IPS = new TestsDataset("clientips");
6972
private static final TestsDataset CLIENT_CIDR = new TestsDataset("client_cidr");
@@ -101,6 +104,7 @@ public class CsvTestsDataLoader {
101104
Map.entry(ALERTS.indexName, ALERTS),
102105
Map.entry(SAMPLE_DATA_STR.indexName, SAMPLE_DATA_STR),
103106
Map.entry(SAMPLE_DATA_TS_LONG.indexName, SAMPLE_DATA_TS_LONG),
107+
Map.entry(SAMPLE_DATA_TS_NANOS.indexName, SAMPLE_DATA_TS_NANOS),
104108
Map.entry(MISSING_IP_SAMPLE_DATA.indexName, MISSING_IP_SAMPLE_DATA),
105109
Map.entry(CLIENT_IPS.indexName, CLIENT_IPS),
106110
Map.entry(CLIENT_CIDR.indexName, CLIENT_CIDR),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@timestamp:date_nanos,client_ip:ip,event_duration:long,message:keyword
2+
2023-10-23T13:55:01.543123456Z,172.21.3.15,1756467,Connected to 10.1.0.1
3+
2023-10-23T13:53:55.832123456Z,172.21.3.15,5033755,Connection error
4+
2023-10-23T13:52:55.015123456Z,172.21.3.15,8268153,Connection error
5+
2023-10-23T13:51:54.732123456Z,172.21.3.15,725448,Connection error
6+
2023-10-23T13:33:34.937123456Z,172.21.0.5,1232382,Disconnected
7+
2023-10-23T12:27:28.948123456Z,172.21.2.113,2764889,Connected to 10.1.0.2
8+
2023-10-23T12:15:03.360123456Z,172.21.2.162,3450233,Connected to 10.1.0.3

0 commit comments

Comments
 (0)