|
34 | 34 | import java.sql.Types; |
35 | 35 | import java.time.Instant; |
36 | 36 | import java.time.ZoneId; |
| 37 | +import java.time.ZonedDateTime; |
37 | 38 | import java.util.Arrays; |
38 | 39 | import java.util.Calendar; |
39 | 40 | import java.util.Date; |
@@ -1157,6 +1158,33 @@ public void testGetDateType() throws Exception { |
1157 | 1158 | assertEquals(expectedTimestamp, results.getObject("date", java.sql.Timestamp.class)); |
1158 | 1159 | }); |
1159 | 1160 | } |
| 1161 | + |
| 1162 | + public void testGetDateTypeFromAggregation() throws Exception { |
| 1163 | + createIndex("test"); |
| 1164 | + updateMapping("test", builder -> builder.startObject("test_date").field("type", "date").endObject()); |
| 1165 | + |
| 1166 | + // 1984-05-02 14:59:12 UTC |
| 1167 | + Long timeInMillis = 452357952000L; |
| 1168 | + index("test", "1", builder -> builder.field("test_date", timeInMillis)); |
| 1169 | + |
| 1170 | + doWithQueryAndTimezone("SELECT CONVERT(test_date, DATE) AS converted FROM test GROUP BY converted", "UTC", results -> { |
| 1171 | + results.next(); |
| 1172 | + ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeInMillis), ZoneId.of("Z")) |
| 1173 | + .toLocalDate().atStartOfDay(ZoneId.of("Z")); |
| 1174 | + |
| 1175 | + java.sql.Date expectedDate = new java.sql.Date(zdt.toInstant().toEpochMilli()); |
| 1176 | + assertEquals(expectedDate, results.getDate("converted")); |
| 1177 | + assertEquals(expectedDate, results.getObject("converted", java.sql.Date.class)); |
| 1178 | + |
| 1179 | + java.sql.Time expectedTime = new java.sql.Time(0L); |
| 1180 | + assertEquals(expectedTime, results.getTime("converted")); |
| 1181 | + assertEquals(expectedTime, results.getObject("converted", java.sql.Time.class)); |
| 1182 | + |
| 1183 | + java.sql.Timestamp expectedTimestamp = new java.sql.Timestamp(zdt.toInstant().toEpochMilli()); |
| 1184 | + assertEquals(expectedTimestamp, results.getTimestamp("converted")); |
| 1185 | + assertEquals(expectedTimestamp, results.getObject("converted", java.sql.Timestamp.class)); |
| 1186 | + }); |
| 1187 | + } |
1160 | 1188 |
|
1161 | 1189 | public void testGetTimeType() throws Exception { |
1162 | 1190 | createIndex("test"); |
|
0 commit comments