|
81 | 81 |
|
82 | 82 | import java.io.IOException;
|
83 | 83 | import java.net.InetAddress;
|
84 |
| -import java.time.ZoneOffset; |
| 84 | +import java.time.ZoneId; |
85 | 85 | import java.util.ArrayList;
|
86 | 86 | import java.util.Arrays;
|
87 | 87 | import java.util.Collections;
|
@@ -1088,6 +1088,67 @@ public void testWithDateHistogram() throws IOException {
|
1088 | 1088 | assertEquals(1L, result.getBuckets().get(2).getDocCount());
|
1089 | 1089 | }
|
1090 | 1090 | );
|
| 1091 | + |
| 1092 | + /* |
| 1093 | + * Tests the -04:00 time zone. This functions identically to |
| 1094 | + * the four hour offset. |
| 1095 | + */ |
| 1096 | + testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("date"), |
| 1097 | + LongPoint.newRangeQuery( |
| 1098 | + "date", |
| 1099 | + asLong("2016-09-20T09:00:34"), |
| 1100 | + asLong("2017-10-20T06:09:24") |
| 1101 | + )), dataset, |
| 1102 | + () -> { |
| 1103 | + DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date") |
| 1104 | + .field("date") |
| 1105 | + .calendarInterval(DateHistogramInterval.days(1)) |
| 1106 | + .timeZone(ZoneId.of("-04:00")); |
| 1107 | + return new CompositeAggregationBuilder("name", Collections.singletonList(histo)) |
| 1108 | + .aggregateAfter(createAfterKey("date", 1474329600000L)); |
| 1109 | + |
| 1110 | + }, (result) -> { |
| 1111 | + assertEquals(3, result.getBuckets().size()); |
| 1112 | + assertEquals("{date=1508472000000}", result.afterKey().toString()); |
| 1113 | + assertEquals("{date=1474344000000}", result.getBuckets().get(0).getKeyAsString()); |
| 1114 | + assertEquals(2L, result.getBuckets().get(0).getDocCount()); |
| 1115 | + assertEquals("{date=1508385600000}", result.getBuckets().get(1).getKeyAsString()); |
| 1116 | + assertEquals(2L, result.getBuckets().get(1).getDocCount()); |
| 1117 | + assertEquals("{date=1508472000000}", result.getBuckets().get(2).getKeyAsString()); |
| 1118 | + assertEquals(1L, result.getBuckets().get(2).getDocCount()); |
| 1119 | + } |
| 1120 | + ); |
| 1121 | + |
| 1122 | + /* |
| 1123 | + * Tests a four hour offset with a time zone, demonstrating |
| 1124 | + * why we support both things. |
| 1125 | + */ |
| 1126 | + testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("date"), |
| 1127 | + LongPoint.newRangeQuery( |
| 1128 | + "date", |
| 1129 | + asLong("2016-09-20T09:00:34"), |
| 1130 | + asLong("2017-10-20T06:09:24") |
| 1131 | + )), dataset, |
| 1132 | + () -> { |
| 1133 | + DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date") |
| 1134 | + .field("date") |
| 1135 | + .calendarInterval(DateHistogramInterval.days(1)) |
| 1136 | + .offset(TimeUnit.HOURS.toMillis(4)) |
| 1137 | + .timeZone(ZoneId.of("America/Los_Angeles")); |
| 1138 | + return new CompositeAggregationBuilder("name", Collections.singletonList(histo)) |
| 1139 | + .aggregateAfter(createAfterKey("date", 1474329600000L)); |
| 1140 | + |
| 1141 | + }, (result) -> { |
| 1142 | + assertEquals(3, result.getBuckets().size()); |
| 1143 | + assertEquals("{date=1508410800000}", result.afterKey().toString()); |
| 1144 | + assertEquals("{date=1474369200000}", result.getBuckets().get(0).getKeyAsString()); |
| 1145 | + assertEquals(1L, result.getBuckets().get(0).getDocCount()); |
| 1146 | + assertEquals("{date=1508324400000}", result.getBuckets().get(1).getKeyAsString()); |
| 1147 | + assertEquals(1L, result.getBuckets().get(1).getDocCount()); |
| 1148 | + assertEquals("{date=1508410800000}", result.getBuckets().get(2).getKeyAsString()); |
| 1149 | + assertEquals(2L, result.getBuckets().get(2).getDocCount()); |
| 1150 | + } |
| 1151 | + ); |
1091 | 1152 | }
|
1092 | 1153 |
|
1093 | 1154 | public void testWithDateTerms() throws IOException {
|
@@ -1219,60 +1280,6 @@ public void testThatDateHistogramFailsFormatAfter() throws IOException {
|
1219 | 1280 | assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
|
1220 | 1281 | }
|
1221 | 1282 |
|
1222 |
| - public void testWithDateHistogramAndTimeZone() throws IOException { |
1223 |
| - final List<Map<String, List<Object>>> dataset = new ArrayList<>(); |
1224 |
| - dataset.addAll( |
1225 |
| - Arrays.asList( |
1226 |
| - createDocument("date", asLong("2017-10-20T03:08:45")), |
1227 |
| - createDocument("date", asLong("2016-09-20T09:00:34")), |
1228 |
| - createDocument("date", asLong("2016-09-20T11:34:00")), |
1229 |
| - createDocument("date", asLong("2017-10-20T06:09:24")), |
1230 |
| - createDocument("date", asLong("2017-10-19T06:09:24")), |
1231 |
| - createDocument("long", 4L) |
1232 |
| - ) |
1233 |
| - ); |
1234 |
| - testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("date")), dataset, |
1235 |
| - () -> { |
1236 |
| - DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date") |
1237 |
| - .field("date") |
1238 |
| - .dateHistogramInterval(DateHistogramInterval.days(1)) |
1239 |
| - .timeZone(ZoneOffset.ofHours(1)); |
1240 |
| - return new CompositeAggregationBuilder("name", Collections.singletonList(histo)); |
1241 |
| - }, |
1242 |
| - (result) -> { |
1243 |
| - assertEquals(3, result.getBuckets().size()); |
1244 |
| - assertEquals("{date=1508454000000}", result.afterKey().toString()); |
1245 |
| - assertEquals("{date=1474326000000}", result.getBuckets().get(0).getKeyAsString()); |
1246 |
| - assertEquals(2L, result.getBuckets().get(0).getDocCount()); |
1247 |
| - assertEquals("{date=1508367600000}", result.getBuckets().get(1).getKeyAsString()); |
1248 |
| - assertEquals(1L, result.getBuckets().get(1).getDocCount()); |
1249 |
| - assertEquals("{date=1508454000000}", result.getBuckets().get(2).getKeyAsString()); |
1250 |
| - assertEquals(2L, result.getBuckets().get(2).getDocCount()); |
1251 |
| - } |
1252 |
| - ); |
1253 |
| - |
1254 |
| - testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("date")), dataset, |
1255 |
| - () -> { |
1256 |
| - DateHistogramValuesSourceBuilder histo = new DateHistogramValuesSourceBuilder("date") |
1257 |
| - .field("date") |
1258 |
| - .dateHistogramInterval(DateHistogramInterval.days(1)) |
1259 |
| - .timeZone(ZoneOffset.ofHours(1)); |
1260 |
| - return new CompositeAggregationBuilder("name", Collections.singletonList(histo)) |
1261 |
| - .aggregateAfter(createAfterKey("date", 1474326000000L)); |
1262 |
| - |
1263 |
| - }, (result) -> { |
1264 |
| - assertEquals(2, result.getBuckets().size()); |
1265 |
| - assertEquals("{date=1508454000000}", result.afterKey().toString()); |
1266 |
| - assertEquals("{date=1508367600000}", result.getBuckets().get(0).getKeyAsString()); |
1267 |
| - assertEquals(1L, result.getBuckets().get(0).getDocCount()); |
1268 |
| - assertEquals("{date=1508454000000}", result.getBuckets().get(1).getKeyAsString()); |
1269 |
| - assertEquals(2L, result.getBuckets().get(1).getDocCount()); |
1270 |
| - } |
1271 |
| - ); |
1272 |
| - |
1273 |
| - assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future."); |
1274 |
| - } |
1275 |
| - |
1276 | 1283 | public void testWithDateHistogramAndKeyword() throws IOException {
|
1277 | 1284 | final List<Map<String, List<Object>>> dataset = new ArrayList<>();
|
1278 | 1285 | dataset.addAll(
|
|
0 commit comments