|
17 | 17 | import org.elasticsearch.common.Strings;
|
18 | 18 | import org.elasticsearch.common.collect.Tuple;
|
19 | 19 | import org.elasticsearch.common.io.Streams;
|
| 20 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
20 | 21 | import org.elasticsearch.common.xcontent.XContentHelper;
|
21 | 22 | import org.elasticsearch.common.xcontent.json.JsonXContent;
|
22 | 23 | import org.elasticsearch.test.NotEqualMessageBuilder;
|
|
30 | 31 | import java.io.InputStreamReader;
|
31 | 32 | import java.nio.charset.StandardCharsets;
|
32 | 33 | import java.sql.JDBCType;
|
| 34 | +import java.time.Instant; |
| 35 | +import java.time.ZoneId; |
| 36 | +import java.time.ZonedDateTime; |
33 | 37 | import java.util.ArrayList;
|
34 | 38 | import java.util.Arrays;
|
35 | 39 | import java.util.Collections;
|
@@ -126,7 +130,76 @@ public void testNextPage() throws IOException {
|
126 | 130 | ContentType.APPLICATION_JSON), StringUtils.EMPTY));
|
127 | 131 | }
|
128 | 132 |
|
129 |
| - @AwaitsFix(bugUrl = "https://github.com/elastic/x-pack-elasticsearch/issues/2074") |
| 133 | + public void testNextPageWithDatetimeAndTimezoneParam() throws IOException { |
| 134 | + Request request = new Request("PUT", "/test_date_timezone"); |
| 135 | + XContentBuilder createIndex = JsonXContent.contentBuilder().startObject(); |
| 136 | + createIndex.startObject("mappings"); |
| 137 | + { |
| 138 | + createIndex.startObject("_doc"); |
| 139 | + { |
| 140 | + createIndex.startObject("properties"); |
| 141 | + { |
| 142 | + createIndex.startObject("date").field("type", "date").field("format", "epoch_millis"); |
| 143 | + createIndex.endObject(); |
| 144 | + } |
| 145 | + createIndex.endObject(); |
| 146 | + } |
| 147 | + createIndex.endObject(); |
| 148 | + } |
| 149 | + createIndex.endObject().endObject(); |
| 150 | + request.setJsonEntity(Strings.toString(createIndex)); |
| 151 | + client().performRequest(request); |
| 152 | + |
| 153 | + request = new Request("PUT", "/test_date_timezone/_doc/_bulk"); |
| 154 | + request.addParameter("refresh", "true"); |
| 155 | + StringBuilder bulk = new StringBuilder(); |
| 156 | + long[] datetimes = new long[] { 1_000, 10_000, 100_000, 1_000_000, 10_000_000 }; |
| 157 | + for (long datetime : datetimes) { |
| 158 | + bulk.append("{\"index\":{}}\n"); |
| 159 | + bulk.append("{\"date\":").append(datetime).append("}\n"); |
| 160 | + } |
| 161 | + request.setJsonEntity(bulk.toString()); |
| 162 | + assertEquals(200, client().performRequest(request).getStatusLine().getStatusCode()); |
| 163 | + |
| 164 | + ZoneId zoneId = randomZone(); |
| 165 | + String mode = randomMode(); |
| 166 | + String sqlRequest = |
| 167 | + "{\"query\":\"SELECT CAST(date AS string) AS date FROM test_date_timezone ORDER BY date\"," |
| 168 | + + "\"time_zone\":\"" + zoneId.getId() + "\", " |
| 169 | + + "\"mode\":\"" + mode + "\", " |
| 170 | + + "\"fetch_size\":2}"; |
| 171 | + |
| 172 | + String cursor = null; |
| 173 | + for (int i = 0; i <= datetimes.length; i += 2) { |
| 174 | + Map<String, Object> expected = new HashMap<>(); |
| 175 | + Map<String, Object> response; |
| 176 | + |
| 177 | + if (i == 0) { |
| 178 | + expected.put("columns", singletonList(columnInfo(mode, "date", "keyword", JDBCType.VARCHAR, |
| 179 | + Integer.MAX_VALUE))); |
| 180 | + response = runSql(new StringEntity(sqlRequest, ContentType.APPLICATION_JSON), ""); |
| 181 | + } else { |
| 182 | + response = runSql(new StringEntity("{\"cursor\":\"" + cursor + "\"" + mode(mode) + "}", |
| 183 | + ContentType.APPLICATION_JSON), StringUtils.EMPTY); |
| 184 | + } |
| 185 | + |
| 186 | + List<Object> values = new ArrayList<>(2); |
| 187 | + for (int j = 0; j < (i < datetimes.length - 1 ? 2 : 1); j++) { |
| 188 | + values.add(singletonList(StringUtils.toString( |
| 189 | + ZonedDateTime.ofInstant(Instant.ofEpochMilli(datetimes[i + j]), zoneId)))); |
| 190 | + } |
| 191 | + expected.put("rows", values); |
| 192 | + cursor = (String) response.remove("cursor"); |
| 193 | + assertResponse(expected, response); |
| 194 | + assertNotNull(cursor); |
| 195 | + } |
| 196 | + Map<String, Object> expected = new HashMap<>(); |
| 197 | + expected.put("rows", emptyList()); |
| 198 | + assertResponse(expected, runSql(new StringEntity("{ \"cursor\":\"" + cursor + "\"" + mode(mode) + "}", |
| 199 | + ContentType.APPLICATION_JSON), StringUtils.EMPTY)); |
| 200 | + } |
| 201 | + |
| 202 | + @AwaitsFix(bugUrl = "Unclear status, https://github.com/elastic/x-pack-elasticsearch/issues/2074") |
130 | 203 | public void testTimeZone() throws IOException {
|
131 | 204 | String mode = randomMode();
|
132 | 205 | index("{\"test\":\"2017-07-27 00:00:00\"}",
|
|
0 commit comments