|
29 | 29 | import org.apache.iotdb.rpc.TSStatusCode; |
30 | 30 |
|
31 | 31 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 32 | +import com.google.gson.JsonArray; |
32 | 33 | import com.google.gson.JsonObject; |
33 | 34 | import com.google.gson.JsonParser; |
34 | 35 | import org.apache.http.HttpEntity; |
@@ -2367,20 +2368,32 @@ public void queryDateAndBlobV2(CloseableHttpClient httpClient) { |
2367 | 2368 | public void queryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { |
2368 | 2369 | CloseableHttpResponse response = null; |
2369 | 2370 | try { |
| 2371 | + long expectedTimestamp = |
| 2372 | + ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); |
| 2373 | + HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); |
| 2374 | + String insertSql = |
| 2375 | + String.format( |
| 2376 | + "{\"sql\":\"INSERT INTO root.sg_tz.d2(timestamp, s3) VALUES(%d, 10.5)\"}", |
| 2377 | + expectedTimestamp); |
| 2378 | + insertPost.setEntity(new StringEntity(insertSql, Charset.defaultCharset())); |
| 2379 | + try (CloseableHttpResponse insertResponse = httpClient.execute(insertPost)) { |
| 2380 | + assertEquals(200, insertResponse.getStatusLine().getStatusCode()); |
| 2381 | + } |
2370 | 2382 | HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/query"); |
2371 | 2383 | httpPost.setHeader("Time-Zone", "+05:00"); |
2372 | 2384 | String sql = |
2373 | | - "{\"sql\":\"SELECT count(s3) FROM root.sg25 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; |
| 2385 | + "{\"sql\":\"SELECT count(s3) FROM root.sg_tz.d2 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; |
2374 | 2386 | httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); |
2375 | 2387 | response = httpClient.execute(httpPost); |
2376 | 2388 | assertEquals(200, response.getStatusLine().getStatusCode()); |
2377 | 2389 | String message = EntityUtils.toString(response.getEntity(), "utf-8"); |
2378 | 2390 | JsonObject result = JsonParser.parseString(message).getAsJsonObject(); |
2379 | 2391 | assertTrue(result.has("timestamps")); |
2380 | 2392 | assertTrue(result.getAsJsonArray("timestamps").size() > 0); |
2381 | | - long expectedTimestamp = |
2382 | | - ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); |
2383 | 2393 | assertEquals(expectedTimestamp, result.getAsJsonArray("timestamps").get(0).getAsLong()); |
| 2394 | + JsonArray values = result.getAsJsonArray("values"); |
| 2395 | + int countResult = values.get(0).getAsJsonArray().get(0).getAsInt(); |
| 2396 | + assertEquals(1, countResult); |
2384 | 2397 | } catch (IOException e) { |
2385 | 2398 | e.printStackTrace(); |
2386 | 2399 | fail(e.getMessage()); |
@@ -2440,20 +2453,32 @@ public void nonQueryWithValidTimeZoneHeader(CloseableHttpClient httpClient) { |
2440 | 2453 | public void queryWithValidTimeZoneHeaderV2(CloseableHttpClient httpClient) { |
2441 | 2454 | CloseableHttpResponse response = null; |
2442 | 2455 | try { |
| 2456 | + long expectedTimestamp = |
| 2457 | + ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); |
| 2458 | + HttpPost insertPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v1/nonQuery"); |
| 2459 | + String insertSql = |
| 2460 | + String.format( |
| 2461 | + "{\"sql\":\"INSERT INTO root.sg_tz.d3(timestamp, s3) VALUES(%d, 10.5)\"}", |
| 2462 | + expectedTimestamp); |
| 2463 | + insertPost.setEntity(new StringEntity(insertSql, Charset.defaultCharset())); |
| 2464 | + try (CloseableHttpResponse insertResponse = httpClient.execute(insertPost)) { |
| 2465 | + assertEquals(200, insertResponse.getStatusLine().getStatusCode()); |
| 2466 | + } |
2443 | 2467 | HttpPost httpPost = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/query"); |
2444 | 2468 | httpPost.setHeader("Time-Zone", "+05:00"); |
2445 | 2469 | String sql = |
2446 | | - "{\"sql\":\"SELECT count(s3) FROM root.sg25 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; |
| 2470 | + "{\"sql\":\"SELECT count(s3) FROM root.sg_tz.d3 GROUP BY ([2026-03-28T00:00:00, 2026-03-29T00:00:00), 1d)\"}"; |
2447 | 2471 | httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); |
2448 | 2472 | response = httpClient.execute(httpPost); |
2449 | 2473 | assertEquals(200, response.getStatusLine().getStatusCode()); |
2450 | 2474 | String message = EntityUtils.toString(response.getEntity(), "utf-8"); |
2451 | 2475 | JsonObject result = JsonParser.parseString(message).getAsJsonObject(); |
2452 | 2476 | assertTrue(result.has("timestamps")); |
2453 | 2477 | assertTrue(result.getAsJsonArray("timestamps").size() > 0); |
2454 | | - long expectedTimestamp = |
2455 | | - ZonedDateTime.of(2026, 3, 28, 0, 0, 0, 0, ZoneId.of("+05:00")).toInstant().toEpochMilli(); |
2456 | 2478 | assertEquals(expectedTimestamp, result.getAsJsonArray("timestamps").get(0).getAsLong()); |
| 2479 | + JsonArray values = result.getAsJsonArray("values"); |
| 2480 | + int countResult = values.get(0).getAsJsonArray().get(0).getAsInt(); |
| 2481 | + assertEquals(1, countResult); |
2457 | 2482 | } catch (IOException e) { |
2458 | 2483 | e.printStackTrace(); |
2459 | 2484 | fail(e.getMessage()); |
|
0 commit comments