You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2024/06/11 10:16:13 UTC
(iotdb) 01/01: Optimize UT/IT of rest api
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rest_test
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c097ae9ea864765be420396470ae9decf6cd7b85
Author: HTHou <hh...@outlook.com>
AuthorDate: Tue Jun 11 18:15:38 2024 +0800
Optimize UT/IT of rest api
---
.../iotdb/{db => rest}/it/GrafanaApiServiceIT.java | 54 +-
.../iotdb/{db => rest}/it/IoTDBRestServiceIT.java | 210 ++---
iotdb-client/jdbc/src/main/feature/feature.xml | 2 +-
.../InsertTabletDataUtils.java} | 141 ++--
.../rest/utils/InsertTabletSortDataUtils.java | 66 --
.../v1/handler/StatementConstructionHandler.java | 121 +--
.../protocol/rest/v1/impl/RestApiServiceImpl.java | 9 +-
.../v2/handler/StatementConstructionHandler.java | 122 +--
.../protocol/rest/v2/impl/RestApiServiceImpl.java | 9 +-
.../db/protocol/rest/GrafanaApiServiceTest.java | 450 ----------
.../db/protocol/rest/IoTDBRestServiceTest.java | 918 ---------------------
.../rest/v2/StatementConstructionTest.java | 75 ++
12 files changed, 291 insertions(+), 1886 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java b/integration-test/src/test/java/org/apache/iotdb/rest/it/GrafanaApiServiceIT.java
similarity index 94%
rename from integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java
rename to integration-test/src/test/java/org/apache/iotdb/rest/it/GrafanaApiServiceIT.java
index ee0ee073c96..46cb4a56120 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/rest/it/GrafanaApiServiceIT.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.it;
+package org.apache.iotdb.rest.it;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
@@ -54,9 +54,9 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-// move to integration-test
@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
+@SuppressWarnings("unchecked")
public class GrafanaApiServiceIT {
private int port = 18080;
@@ -118,7 +118,7 @@ public class GrafanaApiServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -129,7 +129,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -162,7 +162,7 @@ public class GrafanaApiServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -170,7 +170,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -191,12 +191,11 @@ public class GrafanaApiServiceIT {
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
List<Long> expressionsResult = (List<Long>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
Assert.assertTrue(timestampsResult.size() == 10);
Assert.assertTrue(valuesResult.size() == 1);
Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -204,7 +203,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -249,7 +248,7 @@ public class GrafanaApiServiceIT {
Assert.assertArrayEquals(
values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -257,7 +256,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -290,20 +289,19 @@ public class GrafanaApiServiceIT {
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
ObjectMapper mapper = new ObjectMapper();
- Map<String, List> map = mapper.readValue(message, Map.class);
+ Map<String, List<?>> map = mapper.readValue(message, Map.class);
String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"};
Long[] timestamps = {1635232133960L, 1635232153960L};
Object[] values1 = {11.0, 2.0};
Object[] values2 = {15.0, 13.0};
- Assert.assertArrayEquals(
- expressionsResult, (map.get("expressions")).toArray(new String[] {}));
- Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {}));
+ Assert.assertArrayEquals(expressionsResult, (map.get("expressions")).toArray(new Object[0]));
+ Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Object[0]));
Assert.assertArrayEquals(
values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {}));
Assert.assertArrayEquals(
values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -311,7 +309,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -342,19 +340,19 @@ public class GrafanaApiServiceIT {
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
ObjectMapper mapper = new ObjectMapper();
- Map<String, List> map = mapper.readValue(message, Map.class);
+ Map<String, List<?>> map = mapper.readValue(message, Map.class);
String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"};
Long[] timestamps = {1635232133960L, 1635232153960L};
Object[] values1 = {11.0, null};
Object[] values2 = {15.0, null};
- Assert.assertArrayEquals(expressionsResult, map.get("expressions").toArray(new String[] {}));
- Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {}));
+ Assert.assertArrayEquals(expressionsResult, map.get("expressions").toArray(new Object[0]));
+ Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Object[0]));
Assert.assertArrayEquals(
values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {}));
Assert.assertArrayEquals(
values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -362,7 +360,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -382,7 +380,7 @@ public class GrafanaApiServiceIT {
String[] expectedResult = {"s4", "s5"};
Assert.assertArrayEquals(expectedResult, list.toArray(new String[] {}));
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
} finally {
try {
@@ -390,7 +388,7 @@ public class GrafanaApiServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -404,7 +402,7 @@ public class GrafanaApiServiceIT {
try {
httpClient.close();
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -418,7 +416,7 @@ public class GrafanaApiServiceIT {
try {
httpClient.close();
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -431,7 +429,7 @@ public class GrafanaApiServiceIT {
try {
httpClient.close();
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
@@ -444,7 +442,7 @@ public class GrafanaApiServiceIT {
try {
httpClient.close();
} catch (IOException e) {
- e.printStackTrace();
+
fail(e.getMessage());
}
}
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java b/integration-test/src/test/java/org/apache/iotdb/rest/it/IoTDBRestServiceIT.java
similarity index 90%
rename from integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
rename to integration-test/src/test/java/org/apache/iotdb/rest/it/IoTDBRestServiceIT.java
index 8f843d1148c..b91ba0bc88d 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/rest/it/IoTDBRestServiceIT.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.it;
+package org.apache.iotdb.rest.it;
import org.apache.iotdb.db.queryengine.common.header.ColumnHeaderConstant;
import org.apache.iotdb.it.env.EnvFactory;
@@ -59,6 +59,7 @@ import static org.junit.Assert.fail;
@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
+@SuppressWarnings("unchecked")
public class IoTDBRestServiceIT {
private int port = 18080;
@@ -83,7 +84,7 @@ public class IoTDBRestServiceIT {
}
@Test
- public void ping() {
+ public void testPing() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpGet httpGet = new HttpGet("http://127.0.0.1:" + port + "/ping");
CloseableHttpResponse response = null;
@@ -110,7 +111,6 @@ public class IoTDBRestServiceIT {
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -121,7 +121,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -155,7 +154,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -163,7 +161,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -179,7 +176,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(700, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -187,7 +183,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -203,7 +198,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -211,7 +205,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -227,7 +220,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(509, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -235,7 +227,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -251,7 +242,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -259,7 +249,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -290,7 +279,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(200, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -298,13 +286,12 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
}
- public void errorInsertTablet(String json, HttpPost httpPost) {
+ public void errorInsertTablet(String json, HttpPost httpPost, int expectedCode) {
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
@@ -313,9 +300,9 @@ public class IoTDBRestServiceIT {
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(606, Integer.parseInt(result.get("code").toString()));
+ System.out.println(result);
+ assertEquals(expectedCode, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -323,14 +310,13 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
}
@Test
- public void errorInsertTablet() {
+ public void testErroredInsertTablet() {
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
@@ -357,9 +343,8 @@ public class IoTDBRestServiceIT {
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(606, Integer.parseInt(result.get("code").toString()));
+ assertEquals(507, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -367,7 +352,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -382,7 +366,7 @@ public class IoTDBRestServiceIT {
}
@Test
- public void insertAndQuery() {
+ public void testInsertAndQuery() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
//
rightInsertTablet(httpClient);
@@ -401,7 +385,7 @@ public class IoTDBRestServiceIT {
countNodes(httpClient);
showDevices(httpClient);
- showDevicesWithStroage(httpClient);
+ showDevicesWithStorage(httpClient);
listUser(httpClient);
selectCount(httpClient);
selectLast(httpClient);
@@ -421,7 +405,7 @@ public class IoTDBRestServiceIT {
countNodesV2(httpClient);
showDevicesV2(httpClient);
- showDevicesWithStroageV2(httpClient);
+ showDevicesWithStorageV2(httpClient);
listUserV2(httpClient);
selectCountV2(httpClient);
selectLastV2(httpClient);
@@ -429,25 +413,21 @@ public class IoTDBRestServiceIT {
List<String> insertTablet_right_json_list = new ArrayList<>();
List<String> insertTablet_error_json_list = new ArrayList<>();
- List<String> insertRecords_right_json_list = new ArrayList<>();
- List<String> insertRecords_error_json_list = new ArrayList<>();
-
List<String> nonQuery_right_json_list = new ArrayList<>();
List<String> nonQuery_error_json_list = new ArrayList<>();
List<String> insertTablet_right_json_list_v2 = new ArrayList<>();
List<String> insertTablet_error_json_list_v2 = new ArrayList<>();
+ List<String> insertTablet_dup_measurements_json_list_v2 = new ArrayList<>();
+
List<String> insertRecords_right_json_list_v2 = new ArrayList<>();
List<String> insertRecords_error_json_list_v2 = new ArrayList<>();
List<String> nonQuery_right_json_list_v2 = new ArrayList<>();
List<String> nonQuery_error_json_list_v2 = new ArrayList<>();
for (int i = 0; i <= 1; i++) {
- boolean isAligned = false;
- if (i == 0) {
- isAligned = true;
- }
+ boolean isAligned = i == 0;
insertTablet_right_json_list.add(
"{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[11,2],[1635000012345555,1635000012345556],[1.41,null],[null,false],[null,3.5555]],\"isAligned\":\""
+ isAligned
@@ -496,39 +476,6 @@ public class IoTDBRestServiceIT {
+ ",\"deviceId\":\"root.`3333a"
+ i
+ "`\"}");
- insertRecords_right_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"s33\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[1,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.s3\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_right_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"`s33`\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[1,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.s3\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_right_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"s33\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[1,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.`s3`\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_right_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"`s33`\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[1,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.`s11`\",\"root.s11\",\"root.s1\",\"root.`s3`\"],\"isAligned\":"
- + isAligned
- + "}");
-
- insertRecords_error_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"root\",\"442\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.time\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_error_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"time\",\"a123123\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.time\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_error_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"time\",\"a12321\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.111\",\"root.`s11`\",\"root.s1\",\"root.s3\"],\"isAligned\":"
- + isAligned
- + "}");
- insertRecords_error_json_list.add(
- "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurementsList\":[[\"`root`\",\"1111\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"dataTypesList\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"valuesList\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"deviceIds\":[\"root.s11\",\"root.s11\",\"root.time\",\"root.`s3`\"],\"isAligned\":"
- + isAligned
- + "}");
nonQuery_right_json_list.add("{\"sql\":\"insert into root.aa(time,`bb`) values(111,1)\"}");
nonQuery_right_json_list.add("{\"sql\":\"insert into root.`aa`(time,bb) values(111,1)\"}");
@@ -590,6 +537,13 @@ public class IoTDBRestServiceIT {
+ ",\"device\":\"root.`3333a"
+ i
+ "`\"}");
+ insertTablet_dup_measurements_json_list_v2.add(
+ "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"`1231231cc`\",\"s4\",\"s5\",\"s6\",\"s7\",\"s7\"],\"data_types\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"BOOLEAN\"],\"values\":[[\"2aa\",\"\"],[1,2],[16,15],[1.41,null],[null,false],[null,false]],\"is_aligned\":"
+ + isAligned
+ + ",\"device\":\"root.`3333a"
+ + i
+ + "`\"}");
+
insertRecords_right_json_list_v2.add(
"{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurements_list\":[[\"s33\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"data_types_list\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"values_list\":[[1,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"devices\":[\"root.s11\",\"root.s11\",\"root.s1\",\"root.s3\"],\"is_aligned\":"
+ isAligned
@@ -623,6 +577,10 @@ public class IoTDBRestServiceIT {
"{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurements_list\":[[\"`root`\",\"1111\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"data_types_list\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"values_list\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"devices\":[\"root.s11\",\"root.s11\",\"root.time\",\"root.`s3`\"],\"is_aligned\":"
+ isAligned
+ "}");
+ insertRecords_error_json_list_v2.add(
+ "{\"timestamps\":[1635232113960,1635232151960,1123,10],\"measurements_list\":[[\"`root`\",\"1111\"],[\"s55\",\"s55\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"data_types_list\":[[\"INT32\",\"INT64\"],[\"float\",\"double\"],[\"float\",\"double\"],[\"boolean\",\"text\"]],\"values_list\":[[true,11],[2.1,2],[4,6],[false,\"cccccc\"]],\"devices\":[\"root.s11\",\"root.s11\",\"root.time\",\"root.`s3`\"],\"is_aligned\":"
+ + isAligned
+ + "}");
nonQuery_right_json_list_v2.add("{\"sql\":\"insert into root.aa(time,`bb`) values(111,1)\"}");
nonQuery_right_json_list_v2.add("{\"sql\":\"insert into root.`aa`(time,bb) values(111,1)\"}");
@@ -649,7 +607,7 @@ public class IoTDBRestServiceIT {
rightInsertTablet(httpClient, json, hp);
}
for (String json : insertTablet_error_json_list) {
- errorInsertTablet(json, hp);
+ errorInsertTablet(json, hp, 507);
}
}
@@ -685,8 +643,9 @@ public class IoTDBRestServiceIT {
rightInsertTablet(httpClient, json, hp);
}
for (String json : insertTablet_error_json_list_v2) {
- errorInsertTablet(json, hp);
+ errorInsertTablet(json, hp, 507);
}
+ errorInsertTablet(insertTablet_dup_measurements_json_list_v2.get(0), hp, 701);
}
HttpPost httpPost3V2 = getHttpPost("http://127.0.0.1:" + port + "/rest/v2/nonQuery");
@@ -720,13 +679,12 @@ public class IoTDBRestServiceIT {
try {
httpClient.close();
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@Test
- public void queryWithUnsetAuthorization() {
+ public void testQueryWithUnsetAuthorization() {
CloseableHttpResponse response = null;
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
@@ -756,7 +714,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(800, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -764,14 +721,13 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
}
@Test
- public void queryWithWrongAuthorization() {
+ public void testQueryWithWrongAuthorization() {
CloseableHttpResponse response = null;
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
@@ -803,7 +759,6 @@ public class IoTDBRestServiceIT {
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
assertEquals(801, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -811,7 +766,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -827,11 +781,11 @@ public class IoTDBRestServiceIT {
HttpEntity responseEntity = response.getEntity();
String message = EntityUtils.toString(responseEntity, "utf-8");
ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Map<String, Object> map = mapper.readValue(message, Map.class);
+ Object timestampsResult = map.get("timestamps");
+ Object expressionsResult = map.get("expressions");
+ List<Object> valuesResult = (List<Object>) map.get("values");
+ Assert.assertFalse(map.isEmpty());
List<Object> expressions =
new ArrayList<Object>() {
{
@@ -848,8 +802,8 @@ public class IoTDBRestServiceIT {
List<Object> timestamps =
new ArrayList<Object>() {
{
- add(1635232143960l);
- add(1635232153960l);
+ add(1635232143960L);
+ add(1635232153960L);
}
};
List<Object> values1 =
@@ -869,8 +823,8 @@ public class IoTDBRestServiceIT {
List<Object> values3 =
new ArrayList<Object>() {
{
- add(1635000012345555l);
- add(1635000012345556l);
+ add(1635000012345555L);
+ add(1635000012345556L);
}
};
@@ -905,7 +859,6 @@ public class IoTDBRestServiceIT {
Assert.assertEquals(values5, valuesResult.get(4));
Assert.assertEquals(values6, valuesResult.get(5));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -913,7 +866,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -934,12 +886,11 @@ public class IoTDBRestServiceIT {
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
List<Long> expressionsResult = (List<Long>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
Assert.assertTrue(timestampsResult.size() == 10);
Assert.assertTrue(valuesResult.size() == 1);
Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -947,7 +898,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -964,7 +914,6 @@ public class IoTDBRestServiceIT {
String message = EntityUtils.toString(responseEntity, "utf-8");
assertTrue(message.contains("row size exceeded the given max row size"));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -972,7 +921,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -991,7 +939,6 @@ public class IoTDBRestServiceIT {
return map;
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -999,7 +946,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -1011,7 +957,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1035,7 +981,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1058,7 +1004,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1088,7 +1034,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1123,7 +1069,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1185,7 +1131,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1247,7 +1193,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1278,7 +1224,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1300,7 +1246,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1332,12 +1278,12 @@ public class IoTDBRestServiceIT {
Assert.assertEquals(values1, valuesResult.get(0));
}
- public void showDevicesWithStroage(CloseableHttpClient httpClient) {
+ public void showDevicesWithStorage(CloseableHttpClient httpClient) {
String sql = "{\"sql\":\"show devices with database\"}";
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1384,7 +1330,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("columnNames");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1406,7 +1352,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaData(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1429,7 +1375,7 @@ public class IoTDBRestServiceIT {
List<String> columnNamesResult = (List<String>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1441,7 +1387,7 @@ public class IoTDBRestServiceIT {
List<Long> timestamps =
new ArrayList<Long>() {
{
- add(1635232153960l);
+ add(1635232153960L);
}
};
List<Object> values1 =
@@ -1483,7 +1429,7 @@ public class IoTDBRestServiceIT {
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
List<Long> expressionsResult = (List<Long>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> expressions =
new ArrayList<Object>() {
{
@@ -1500,8 +1446,8 @@ public class IoTDBRestServiceIT {
List<Object> timestamps =
new ArrayList<Object>() {
{
- add(1635232143960l);
- add(1635232153960l);
+ add(1635232143960L);
+ add(1635232153960L);
}
};
List<Object> values1 =
@@ -1557,7 +1503,6 @@ public class IoTDBRestServiceIT {
Assert.assertEquals(values5, valuesResult.get(4));
Assert.assertEquals(values6, valuesResult.get(5));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -1565,7 +1510,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -1586,12 +1530,11 @@ public class IoTDBRestServiceIT {
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
List<Long> expressionsResult = (List<Long>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
Assert.assertTrue(timestampsResult.size() == 10);
Assert.assertTrue(valuesResult.size() == 1);
Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -1599,7 +1542,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -1616,7 +1558,6 @@ public class IoTDBRestServiceIT {
String message = EntityUtils.toString(responseEntity, "utf-8");
assertTrue(message.contains("row size exceeded the given max row size"));
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -1624,7 +1565,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -1643,7 +1583,6 @@ public class IoTDBRestServiceIT {
return map;
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
} finally {
try {
@@ -1651,7 +1590,6 @@ public class IoTDBRestServiceIT {
response.close();
}
} catch (IOException e) {
- e.printStackTrace();
fail(e.getMessage());
}
}
@@ -1663,7 +1601,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1687,7 +1625,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1710,7 +1648,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1740,7 +1678,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1775,7 +1713,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1837,7 +1775,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1899,7 +1837,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1930,7 +1868,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1952,7 +1890,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -1985,12 +1923,12 @@ public class IoTDBRestServiceIT {
// Assert.assertEquals(values2, valuesResult.get(1));
}
- public void showDevicesWithStroageV2(CloseableHttpClient httpClient) {
+ public void showDevicesWithStorageV2(CloseableHttpClient httpClient) {
String sql = "{\"sql\":\"show devices with database\"}";
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -2037,7 +1975,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("column_names");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -2059,7 +1997,7 @@ public class IoTDBRestServiceIT {
Map map = queryMetaDataV2(httpClient, sql);
List<String> columnNamesResult = (List<String>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -2082,7 +2020,7 @@ public class IoTDBRestServiceIT {
List<String> columnNamesResult = (List<String>) map.get("expressions");
List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- Assert.assertTrue(map.size() > 0);
+ Assert.assertFalse(map.isEmpty());
List<Object> columnNames =
new ArrayList<Object>() {
{
@@ -2094,7 +2032,7 @@ public class IoTDBRestServiceIT {
List<Long> timestamps =
new ArrayList<Long>() {
{
- add(1635232153960l);
+ add(1635232153960L);
}
};
List<Object> values1 =
diff --git a/iotdb-client/jdbc/src/main/feature/feature.xml b/iotdb-client/jdbc/src/main/feature/feature.xml
index 8f37dae5f8c..3fed28e17a5 100644
--- a/iotdb-client/jdbc/src/main/feature/feature.xml
+++ b/iotdb-client/jdbc/src/main/feature/feature.xml
@@ -18,7 +18,7 @@
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.5.0" name="driver-s7-feature">
- <feature name="iotdb-feature" description="iotdb-feature" version="1.0.0">
+ <feature name="iotdb-feature" description="iotdb-feature" version="${project.version}">
<details>Feature to install required Bundle to use IoTDB inside Karaf container</details>
<feature prerequisite="true">wrap</feature>
<feature>scr</feature>
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletDataUtils.java
similarity index 58%
copy from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java
copy to iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletDataUtils.java
index 30e1eae8ad1..5cfd0c0baf0 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletDataUtils.java
@@ -15,69 +15,96 @@
* limitations under the License.
*/
-package org.apache.iotdb.db.protocol.rest.v1.handler;
+package org.apache.iotdb.db.protocol.rest.utils;
-import org.apache.iotdb.commons.exception.MetadataException;
-import org.apache.iotdb.commons.utils.PathUtils;
-import org.apache.iotdb.db.exception.WriteProcessRejectException;
-import org.apache.iotdb.db.protocol.rest.v1.model.InsertTabletRequest;
-import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache;
-import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
-import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
+import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.List;
-import java.util.Locale;
+import java.util.stream.Collectors;
-public class StatementConstructionHandler {
- private StatementConstructionHandler() {}
-
- public static InsertTabletStatement constructInsertTabletStatement(
- InsertTabletRequest insertTabletRequest)
- throws MetadataException, WriteProcessRejectException {
- TimestampPrecisionUtils.checkTimestampPrecision(
- insertTabletRequest.getTimestamps().get(insertTabletRequest.getTimestamps().size() - 1));
- // construct insert statement
- InsertTabletStatement insertStatement = new InsertTabletStatement();
- insertStatement.setDevicePath(
- DataNodeDevicePathCache.getInstance().getPartialPath(insertTabletRequest.getDeviceId()));
- insertStatement.setMeasurements(
- PathUtils.checkIsLegalSingleMeasurementsAndUpdate(insertTabletRequest.getMeasurements())
- .toArray(new String[0]));
- List<List<Object>> rawData = insertTabletRequest.getValues();
- List<String> rawDataType = insertTabletRequest.getDataTypes();
-
- int rowSize = insertTabletRequest.getTimestamps().size();
- int columnSize = rawDataType.size();
+public class InsertTabletDataUtils {
+ public static boolean checkSorted(List<Long> times) {
+ for (int i = 1; i < times.size(); i++) {
+ if (times.get(i) < times.get(i - 1)) {
+ return false;
+ }
+ }
+ return true;
+ }
- Object[] columns = new Object[columnSize];
- BitMap[] bitMaps = new BitMap[columnSize];
- TSDataType[] dataTypes = new TSDataType[columnSize];
+ public static int[] sortTimeStampList(List<Long> list) {
+ List<Integer> indexes = new ArrayList<>();
+ for (int i = 0; i < list.size(); i++) {
+ indexes.add(i);
+ }
+ indexes.sort(Comparator.comparing(list::get));
+ return indexes.stream().mapToInt(Integer::intValue).toArray();
+ }
- for (int i = 0; i < columnSize; i++) {
- dataTypes[i] = TSDataType.valueOf(rawDataType.get(i).toUpperCase(Locale.ROOT));
+ public static <T> List<List<T>> sortList(List<List<T>> values, int[] index, int num) {
+ List<List<T>> sortedValues = new ArrayList<>();
+ for (int i = 0; i < num; i++) {
+ sortedValues.add(sortValueList(values.get(i), index));
}
+ return sortedValues;
+ }
+ /**
+ * Sort the input source list.
+ *
+ * <p>e.g. source:[1,0,3,2,4], index: [1,2,3,4,5], return : [2,1,4,3,5]
+ *
+ * @param source Input list
+ * @param index return order
+ * @param <T> Input type
+ * @return ordered list
+ */
+ private static <T> List<T> sortValueList(List<T> source, int[] index) {
+ return Arrays.stream(index).mapToObj(source::get).collect(Collectors.toList());
+ }
+
+ public static Object[] genTabletValue(
+ String device,
+ String[] measurements,
+ long[] times,
+ TSDataType[] dataTypes,
+ List<List<Object>> rawData,
+ BitMap[] bitMaps)
+ throws DataTypeMismatchException {
+ int rowSize = times.length;
+ int columnSize = dataTypes.length;
+ Object[] columns = new Object[columnSize];
for (int columnIndex = 0; columnIndex < columnSize; columnIndex++) {
bitMaps[columnIndex] = new BitMap(rowSize);
switch (dataTypes[columnIndex]) {
case BOOLEAN:
boolean[] booleanValues = new boolean[rowSize];
for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object data = rawData.get(columnIndex).get(rowIndex);
- if (data == null) {
+ Object object = rawData.get(columnIndex).get(rowIndex);
+ if (object == null) {
bitMaps[columnIndex].mark(rowIndex);
+ } else if (object instanceof Boolean) {
+ booleanValues[rowIndex] = (Boolean) object;
} else {
- if ("1".equals(data.toString())) {
+ if ("1".equals(object.toString())) {
booleanValues[rowIndex] = true;
- } else if ("0".equals(data.toString())) {
+ } else if ("0".equals(object.toString())) {
booleanValues[rowIndex] = false;
} else {
- booleanValues[rowIndex] = (Boolean) data;
+ throw new DataTypeMismatchException(
+ device,
+ measurements[columnIndex],
+ dataTypes[columnIndex],
+ times[rowIndex],
+ object);
}
}
}
@@ -91,10 +118,14 @@ public class StatementConstructionHandler {
if (object == null) {
bitMaps[columnIndex].mark(rowIndex);
} else if (object instanceof Integer) {
- intValues[rowIndex] = (int) object;
+ intValues[rowIndex] = (Integer) object;
} else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
+ throw new DataTypeMismatchException(
+ device,
+ measurements[columnIndex],
+ dataTypes[columnIndex],
+ times[rowIndex],
+ object);
}
}
columns[columnIndex] = intValues;
@@ -106,13 +137,15 @@ public class StatementConstructionHandler {
Object object = rawData.get(columnIndex).get(rowIndex);
if (object == null) {
bitMaps[columnIndex].mark(rowIndex);
- } else if (object instanceof Integer) {
- longValues[rowIndex] = (int) object;
- } else if (object instanceof Long) {
- longValues[rowIndex] = (long) object;
+ } else if (object instanceof Integer || object instanceof Long) {
+ longValues[rowIndex] = ((Number) object).longValue();
} else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
+ throw new DataTypeMismatchException(
+ device,
+ measurements[columnIndex],
+ dataTypes[columnIndex],
+ times[rowIndex],
+ object);
}
}
columns[columnIndex] = longValues;
@@ -162,17 +195,9 @@ public class StatementConstructionHandler {
columns[columnIndex] = binaryValues;
break;
default:
- throw new IllegalArgumentException("Invalid input: " + rawDataType.get(columnIndex));
+ throw new IllegalArgumentException("Invalid input: " + dataTypes[columnIndex]);
}
}
-
- insertStatement.setTimes(
- insertTabletRequest.getTimestamps().stream().mapToLong(Long::longValue).toArray());
- insertStatement.setColumns(columns);
- insertStatement.setBitMaps(bitMaps);
- insertStatement.setRowCount(insertTabletRequest.getTimestamps().size());
- insertStatement.setDataTypes(dataTypes);
- insertStatement.setAligned(insertTabletRequest.getIsAligned());
- return insertStatement;
+ return columns;
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java
deleted file mode 100644
index e2e3d2f7976..00000000000
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.iotdb.db.protocol.rest.utils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class InsertTabletSortDataUtils {
- public static boolean checkSorted(List<Long> times) {
- for (int i = 1; i < times.size(); i++) {
- if (times.get(i) < times.get(i - 1)) {
- return false;
- }
- }
- return true;
- }
-
- public static int[] sortTimeStampList(List<Long> list) {
- List<Integer> indexes = new ArrayList<>();
- for (int i = 0; i < list.size(); i++) {
- indexes.add(i);
- }
- indexes.sort(Comparator.comparing(list::get));
- return indexes.stream().mapToInt(Integer::intValue).toArray();
- }
-
- public static <T> List<List<T>> sortList(List<List<T>> values, int[] index, int num) {
- List<List<T>> sortedValues = new ArrayList<>();
- for (int i = 0; i < num; i++) {
- sortedValues.add(sortValueList(values.get(i), index));
- }
- return sortedValues;
- }
-
- /**
- * Sort the input source list.
- *
- * <p>e.g. source:[1,0,3,2,4], index: [1,2,3,4,5], return : [2,1,4,3,5]
- *
- * @param source Input list
- * @param index return order
- * @param <T> Input type
- * @return ordered list
- */
- private static <T> List<T> sortValueList(List<T> source, int[] index) {
- return Arrays.stream(index).mapToObj(source::get).collect(Collectors.toList());
- }
-}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java
index 30e1eae8ad1..7f20e541964 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java
@@ -20,16 +20,15 @@ package org.apache.iotdb.db.protocol.rest.v1.handler;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.db.exception.WriteProcessRejectException;
+import org.apache.iotdb.db.protocol.rest.utils.InsertTabletDataUtils;
import org.apache.iotdb.db.protocol.rest.v1.model.InsertTabletRequest;
import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache;
import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement;
import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
import org.apache.tsfile.enums.TSDataType;
-import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
-import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
@@ -54,7 +53,6 @@ public class StatementConstructionHandler {
int rowSize = insertTabletRequest.getTimestamps().size();
int columnSize = rawDataType.size();
- Object[] columns = new Object[columnSize];
BitMap[] bitMaps = new BitMap[columnSize];
TSDataType[] dataTypes = new TSDataType[columnSize];
@@ -62,115 +60,22 @@ public class StatementConstructionHandler {
dataTypes[i] = TSDataType.valueOf(rawDataType.get(i).toUpperCase(Locale.ROOT));
}
- for (int columnIndex = 0; columnIndex < columnSize; columnIndex++) {
- bitMaps[columnIndex] = new BitMap(rowSize);
- switch (dataTypes[columnIndex]) {
- case BOOLEAN:
- boolean[] booleanValues = new boolean[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object data = rawData.get(columnIndex).get(rowIndex);
- if (data == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- if ("1".equals(data.toString())) {
- booleanValues[rowIndex] = true;
- } else if ("0".equals(data.toString())) {
- booleanValues[rowIndex] = false;
- } else {
- booleanValues[rowIndex] = (Boolean) data;
- }
- }
- }
- columns[columnIndex] = booleanValues;
- break;
- case INT32:
- case DATE:
- int[] intValues = new int[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object object = rawData.get(columnIndex).get(rowIndex);
- if (object == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else if (object instanceof Integer) {
- intValues[rowIndex] = (int) object;
- } else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
- }
- }
- columns[columnIndex] = intValues;
- break;
- case INT64:
- case TIMESTAMP:
- long[] longValues = new long[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object object = rawData.get(columnIndex).get(rowIndex);
- if (object == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else if (object instanceof Integer) {
- longValues[rowIndex] = (int) object;
- } else if (object instanceof Long) {
- longValues[rowIndex] = (long) object;
- } else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
- }
- }
- columns[columnIndex] = longValues;
- break;
- case FLOAT:
- float[] floatValues = new float[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object data = rawData.get(columnIndex).get(rowIndex);
- if (data == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- floatValues[rowIndex] = Float.parseFloat(String.valueOf(data));
- }
- }
- columns[columnIndex] = floatValues;
- break;
- case DOUBLE:
- double[] doubleValues = new double[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- if (rawData.get(columnIndex).get(rowIndex) == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- doubleValues[rowIndex] =
- Double.parseDouble(String.valueOf(rawData.get(columnIndex).get(rowIndex)));
- }
- }
- columns[columnIndex] = doubleValues;
- break;
- case TEXT:
- case BLOB:
- case STRING:
- Binary[] binaryValues = new Binary[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- if (rawData.get(columnIndex).get(rowIndex) == null) {
- bitMaps[columnIndex].mark(rowIndex);
- binaryValues[rowIndex] = new Binary("".getBytes(StandardCharsets.UTF_8));
- } else {
- binaryValues[rowIndex] =
- new Binary(
- rawData
- .get(columnIndex)
- .get(rowIndex)
- .toString()
- .getBytes(StandardCharsets.UTF_8));
- }
- }
- columns[columnIndex] = binaryValues;
- break;
- default:
- throw new IllegalArgumentException("Invalid input: " + rawDataType.get(columnIndex));
- }
- }
-
insertStatement.setTimes(
insertTabletRequest.getTimestamps().stream().mapToLong(Long::longValue).toArray());
+ insertStatement.setTimes(
+ insertTabletRequest.getTimestamps().stream().mapToLong(Long::longValue).toArray());
+ Object[] columns =
+ InsertTabletDataUtils.genTabletValue(
+ insertTabletRequest.getDeviceId(),
+ insertStatement.getMeasurements(),
+ insertStatement.getTimes(),
+ dataTypes,
+ rawData,
+ bitMaps);
+
insertStatement.setColumns(columns);
insertStatement.setBitMaps(bitMaps);
- insertStatement.setRowCount(insertTabletRequest.getTimestamps().size());
+ insertStatement.setRowCount(rowSize);
insertStatement.setDataTypes(dataTypes);
insertStatement.setAligned(insertTabletRequest.getIsAligned());
return insertStatement;
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
index 428f2c3baaa..31188ad4f76 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java
@@ -21,7 +21,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler;
-import org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils;
+import org.apache.iotdb.db.protocol.rest.utils.InsertTabletDataUtils;
import org.apache.iotdb.db.protocol.rest.v1.RestApiService;
import org.apache.iotdb.db.protocol.rest.v1.handler.ExceptionHandler;
import org.apache.iotdb.db.protocol.rest.v1.handler.ExecuteStatementHandler;
@@ -191,13 +191,12 @@ public class RestApiServiceImpl extends RestApiService {
try {
RequestValidationHandler.validateInsertTabletRequest(insertTabletRequest);
- if (!InsertTabletSortDataUtils.checkSorted(insertTabletRequest.getTimestamps())) {
+ if (!InsertTabletDataUtils.checkSorted(insertTabletRequest.getTimestamps())) {
- int[] index =
- InsertTabletSortDataUtils.sortTimeStampList(insertTabletRequest.getTimestamps());
+ int[] index = InsertTabletDataUtils.sortTimeStampList(insertTabletRequest.getTimestamps());
insertTabletRequest.getTimestamps().sort(Long::compareTo);
insertTabletRequest.setValues(
- InsertTabletSortDataUtils.sortList(
+ InsertTabletDataUtils.sortList(
insertTabletRequest.getValues(), index, insertTabletRequest.getDataTypes().size()));
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java
index c0559b40c2d..6c7197e59ef 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java
@@ -19,9 +19,9 @@ package org.apache.iotdb.db.protocol.rest.v2.handler;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.utils.PathUtils;
-import org.apache.iotdb.db.exception.WriteProcessRejectException;
import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
import org.apache.iotdb.db.protocol.rest.utils.InsertRowDataUtils;
+import org.apache.iotdb.db.protocol.rest.utils.InsertTabletDataUtils;
import org.apache.iotdb.db.protocol.rest.v2.model.InsertRecordsRequest;
import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest;
import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache;
@@ -32,10 +32,8 @@ import org.apache.iotdb.db.utils.TimestampPrecisionUtils;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.tsfile.enums.TSDataType;
-import org.apache.tsfile.utils.Binary;
import org.apache.tsfile.utils.BitMap;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -46,8 +44,7 @@ public class StatementConstructionHandler {
private StatementConstructionHandler() {}
public static InsertTabletStatement constructInsertTabletStatement(
- InsertTabletRequest insertTabletRequest)
- throws MetadataException, WriteProcessRejectException {
+ InsertTabletRequest insertTabletRequest) throws MetadataException {
TimestampPrecisionUtils.checkTimestampPrecision(
insertTabletRequest.getTimestamps().get(insertTabletRequest.getTimestamps().size() - 1));
// construct insert statement
@@ -64,120 +61,23 @@ public class StatementConstructionHandler {
int rowSize = insertTabletRequest.getTimestamps().size();
int columnSize = rawDataType.size();
- Object[] columns = new Object[columnSize];
BitMap[] bitMaps = new BitMap[columnSize];
TSDataType[] dataTypes = new TSDataType[columnSize];
for (int i = 0; i < columnSize; i++) {
dataTypes[i] = TSDataType.valueOf(rawDataType.get(i).toUpperCase(Locale.ROOT));
}
-
- for (int columnIndex = 0; columnIndex < columnSize; columnIndex++) {
- bitMaps[columnIndex] = new BitMap(rowSize);
- switch (dataTypes[columnIndex]) {
- case BOOLEAN:
- boolean[] booleanValues = new boolean[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object data = rawData.get(columnIndex).get(rowIndex);
- if (data == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- if ("1".equals(data.toString())) {
- booleanValues[rowIndex] = true;
- } else if ("0".equals(data.toString())) {
- booleanValues[rowIndex] = false;
- } else {
- booleanValues[rowIndex] = (Boolean) data;
- }
- }
- }
- columns[columnIndex] = booleanValues;
- break;
- case INT32:
- case DATE:
- int[] intValues = new int[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object object = rawData.get(columnIndex).get(rowIndex);
- if (object == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else if (object instanceof Integer) {
- intValues[rowIndex] = (int) object;
- } else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
- }
- }
- columns[columnIndex] = intValues;
- break;
- case INT64:
- case TIMESTAMP:
- long[] longValues = new long[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object object = rawData.get(columnIndex).get(rowIndex);
- if (object == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else if (object instanceof Integer) {
- longValues[rowIndex] = (int) object;
- } else if (object instanceof Long) {
- longValues[rowIndex] = (long) object;
- } else {
- throw new WriteProcessRejectException(
- "unsupported data type: " + object.getClass().toString());
- }
- }
- columns[columnIndex] = longValues;
- break;
- case FLOAT:
- float[] floatValues = new float[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- Object data = rawData.get(columnIndex).get(rowIndex);
- if (data == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- floatValues[rowIndex] = Float.parseFloat(String.valueOf(data));
- }
- }
- columns[columnIndex] = floatValues;
- break;
- case DOUBLE:
- double[] doubleValues = new double[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- if (rawData.get(columnIndex).get(rowIndex) == null) {
- bitMaps[columnIndex].mark(rowIndex);
- } else {
- doubleValues[rowIndex] =
- Double.parseDouble(String.valueOf(rawData.get(columnIndex).get(rowIndex)));
- }
- }
- columns[columnIndex] = doubleValues;
- break;
- case TEXT:
- case BLOB:
- case STRING:
- Binary[] binaryValues = new Binary[rowSize];
- for (int rowIndex = 0; rowIndex < rowSize; rowIndex++) {
- if (rawData.get(columnIndex).get(rowIndex) == null) {
- bitMaps[columnIndex].mark(rowIndex);
- binaryValues[rowIndex] = new Binary("".getBytes(StandardCharsets.UTF_8));
- } else {
- binaryValues[rowIndex] =
- new Binary(
- rawData
- .get(columnIndex)
- .get(rowIndex)
- .toString()
- .getBytes(StandardCharsets.UTF_8));
- }
- }
- columns[columnIndex] = binaryValues;
- break;
- default:
- throw new IllegalArgumentException("Invalid input: " + rawDataType.get(columnIndex));
- }
- }
-
insertStatement.setTimes(
insertTabletRequest.getTimestamps().stream().mapToLong(Long::longValue).toArray());
+ Object[] columns =
+ InsertTabletDataUtils.genTabletValue(
+ insertTabletRequest.getDevice(),
+ insertStatement.getMeasurements(),
+ insertStatement.getTimes(),
+ dataTypes,
+ rawData,
+ bitMaps);
+
insertStatement.setColumns(columns);
insertStatement.setBitMaps(bitMaps);
insertStatement.setRowCount(insertTabletRequest.getTimestamps().size());
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
index 854fd7feb70..d61394e3802 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java
@@ -22,7 +22,7 @@ import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor;
import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler;
-import org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils;
+import org.apache.iotdb.db.protocol.rest.utils.InsertTabletDataUtils;
import org.apache.iotdb.db.protocol.rest.v2.RestApiService;
import org.apache.iotdb.db.protocol.rest.v2.handler.ExceptionHandler;
import org.apache.iotdb.db.protocol.rest.v2.handler.ExecuteStatementHandler;
@@ -221,13 +221,12 @@ public class RestApiServiceImpl extends RestApiService {
try {
RequestValidationHandler.validateInsertTabletRequest(insertTabletRequest);
- if (!InsertTabletSortDataUtils.checkSorted(insertTabletRequest.getTimestamps())) {
+ if (!InsertTabletDataUtils.checkSorted(insertTabletRequest.getTimestamps())) {
- int[] index =
- InsertTabletSortDataUtils.sortTimeStampList(insertTabletRequest.getTimestamps());
+ int[] index = InsertTabletDataUtils.sortTimeStampList(insertTabletRequest.getTimestamps());
insertTabletRequest.getTimestamps().sort(Long::compareTo);
insertTabletRequest.setValues(
- InsertTabletSortDataUtils.sortList(
+ InsertTabletDataUtils.sortList(
insertTabletRequest.getValues(), index, insertTabletRequest.getDataTypes().size()));
}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java
deleted file mode 100644
index 55d74742453..00000000000
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.iotdb.db.protocol.rest;
-
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-// move to integration-test
-@Ignore
-public class GrafanaApiServiceTest {
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.envSetUp();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvironmentUtils.cleanEnv();
- }
-
- private String getAuthorization(String username, String password) {
- return Base64.getEncoder()
- .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
- }
-
- private HttpPost getHttpPost(String url) {
- HttpPost httpPost = new HttpPost(url);
- httpPost.addHeader("Content-type", "application/json; charset=utf-8");
- httpPost.setHeader("Accept", "application/json");
- String authorization = getAuthorization("root", "root");
- httpPost.setHeader("Authorization", authorization);
- return httpPost;
- }
-
- @Test
- public void login() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/grafana/v1/login");
- CloseableHttpResponse response = null;
- try {
- String authorization = getAuthorization("root", "root");
- httpGet.setHeader("Authorization", authorization);
- response = httpClient.execute(httpGet);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(200, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (httpClient != null) {
- httpClient.close();
- }
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void rightInsertTablet(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet");
- String json =
- "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s4\",\"s5\"],\"dataTypes\":[\"INT32\",\"INT32\"],\"values\":[[11,2],[15,13]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}";
- httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(200, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void expressionAggGroupByTimeAndLevel(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by([1635232143960,1635232153960),1s),level=1\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- Assert.assertTrue(timestampsResult.size() == 10);
- Assert.assertTrue(valuesResult.size() == 1);
- Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void expression(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"s4\",\"s5\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map<String, List> map = mapper.readValue(message, Map.class);
- String[] expressionsResult = {"root.sg25.s4", "root.sg25.s5"};
- Long[] timestamps = {1635232143960L, 1635232153960L};
- Object[] values1 = {11, 2};
- Object[] values2 = {15, 13};
- Assert.assertArrayEquals(
- expressionsResult, (map.get("expressions")).toArray(new String[] {}));
- Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {}));
- Assert.assertArrayEquals(
- values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {}));
- Assert.assertArrayEquals(
- values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void expressionWithControl(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map<String, List> map = mapper.readValue(message, Map.class);
- String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"};
- Long[] timestamps = {1635232133960L, 1635232153960L};
- Object[] values1 = {11.0, 2.0};
- Object[] values2 = {15.0, 13.0};
- Assert.assertArrayEquals(
- expressionsResult, (map.get("expressions")).toArray(new String[] {}));
- Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {}));
- Assert.assertArrayEquals(
- values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {}));
- Assert.assertArrayEquals(
- values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void expressionWithConditionControl(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"condition\":\"timestamp=1635232143960\",\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map<String, List> map = mapper.readValue(message, Map.class);
- String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"};
- Long[] timestamps = {1635232133960L, 1635232153960L};
- Object[] values1 = {11.0, null};
- Object[] values2 = {15.0, null};
- Assert.assertArrayEquals(expressionsResult, map.get("expressions").toArray(new String[] {}));
- Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {}));
- Assert.assertArrayEquals(
- values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {}));
- Assert.assertArrayEquals(
- values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {}));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void variable(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/variable");
- String sql = "{\"sql\":\"show child paths root.sg25\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- List list = mapper.readValue(message, List.class);
- String[] expectedResult = {"s4", "s5"};
- Assert.assertArrayEquals(expectedResult, list.toArray(new String[] {}));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void expressionWithConditionControlTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
- expressionWithConditionControl(httpClient);
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void expressionTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
- expression(httpClient);
- expressionAggGroupByTimeAndLevel(httpClient);
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void expressionWithControlTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
- expressionWithControl(httpClient);
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void variableTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
- variable(httpClient);
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void expressionWithAggGroupByTimeTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
-
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by([1635232143960,1635232153960),1s)\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- Assert.assertTrue(timestampsResult.size() == 10);
- Assert.assertTrue(valuesResult.size() == 1);
- Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void expressionWithAggGroupByLevelTest() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
-
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression");
- String sql =
- "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by level = 1\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- Assert.assertTrue(timestampsResult == null);
- Assert.assertTrue(valuesResult.size() == 1);
- Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java
deleted file mode 100644
index e87bfa58335..00000000000
--- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java
+++ /dev/null
@@ -1,918 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.iotdb.db.protocol.rest;
-
-import org.apache.iotdb.commons.exception.StartupException;
-import org.apache.iotdb.db.service.RPCService;
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.util.EntityUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.FixMethodOrder;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Base64;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-// Move it to integration-test
-@Ignore
-@FixMethodOrder(MethodSorters.JVM)
-public class IoTDBRestServiceTest {
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.envSetUp();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvironmentUtils.cleanEnv();
- }
-
- private String getAuthorization(String username, String password) {
- return Base64.getEncoder()
- .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
- }
-
- @Test
- public void ping() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/ping");
- CloseableHttpResponse response = null;
- try {
- response = httpClient.execute(httpGet);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(200, response.getStatusLine().getStatusCode());
- assertEquals(200, Integer.parseInt(result.get("code").toString()));
-
- // Shutdown RPCService to test
- RPCService.getInstance().stop();
- response = httpClient.execute(httpGet);
- responseEntity = response.getEntity();
- message = EntityUtils.toString(responseEntity, "utf-8");
- result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(503, response.getStatusLine().getStatusCode());
- assertEquals(500, Integer.parseInt(result.get("code").toString()));
- RPCService.getInstance().start();
-
- } catch (IOException | StartupException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (httpClient != null) {
- httpClient.close();
- }
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- private HttpPost getHttpPost(String url) {
- HttpPost httpPost = new HttpPost(url);
- httpPost.addHeader("Content-type", "application/json; charset=utf-8");
- httpPost.setHeader("Accept", "application/json");
- String authorization = getAuthorization("root", "root");
- httpPost.setHeader("Authorization", authorization);
- return httpPost;
- }
-
- public void rightInsertTablet(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet");
- String json =
- "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[11,2],[1635000012345555,1635000012345556],[1.41,null],[null,false],[null,3.5555]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}";
- httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(200, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void errorInsertTablet() {
- CloseableHttpResponse response = null;
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet");
- String json =
- "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[111111112312312442352545452323123,2],[16,15],[1.41,null],[null,false],[null,3.55555555555555555555555555555555555555555555312234235345123127318927461482308478123645555555555555555555555555555555555555555555531223423534512312731892746148230847812364]],\"isAligned\":fal [...]
- httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(413, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void insertAndQuery() {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- rightInsertTablet(httpClient);
- query(httpClient);
- queryGroupByLevel(httpClient);
- queryRowLimit(httpClient);
- queryShowChildPaths(httpClient);
- queryShowNodes(httpClient);
- showAllTTL(httpClient);
- showStorageGroup(httpClient);
- showFunctions(httpClient);
- showTimeseries(httpClient);
-
- showLastTimeseries(httpClient);
- countTimeseries(httpClient);
- countNodes(httpClient);
- showDevices(httpClient);
-
- showDevicesWithStroage(httpClient);
- listUser(httpClient);
- selectCount(httpClient);
- selectLast(httpClient);
- try {
- httpClient.close();
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void queryWithUnsetAuthorization() {
- CloseableHttpResponse response = null;
- try {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- HttpPost httpPost = new HttpPost("http://127.0.0.1:18080/rest/v1/query");
- httpPost.addHeader("Content-type", "application/json; charset=utf-8");
- httpPost.setHeader("Accept", "application/json");
- String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- Assert.assertEquals(401, response.getStatusLine().getStatusCode());
- String message = EntityUtils.toString(response.getEntity(), "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(603, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- public void queryWithWrongAuthorization() {
- CloseableHttpResponse response = null;
- try {
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- HttpPost httpPost = new HttpPost("http://127.0.0.1:18080/rest/v1/query");
- httpPost.addHeader("Content-type", "application/json; charset=utf-8");
- httpPost.setHeader("Accept", "application/json");
- String authorization = getAuthorization("abc", "def");
- httpPost.setHeader("Authorization", authorization);
- String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- Assert.assertEquals(401, response.getStatusLine().getStatusCode());
- String message = EntityUtils.toString(response.getEntity(), "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(600, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void query(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query");
- String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> expressions =
- new ArrayList<Object>() {
- {
- add("root.sg25.s3");
- add("root.sg25.s4");
- add("root.sg25.s5");
- add("root.sg25.s6");
- add("root.sg25.s7");
- add("root.sg25.s8");
- add("root.sg25.s4 + 1");
- add("root.sg25.s4 + 1");
- }
- };
- List<Object> timestamps =
- new ArrayList<Object>() {
- {
- add(1635232143960l);
- add(1635232153960l);
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("2aa");
- add("");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add(11);
- add(2);
- }
- };
- List<Object> values3 =
- new ArrayList<Object>() {
- {
- add(1635000012345555l);
- add(1635000012345556l);
- }
- };
-
- List<Object> values4 =
- new ArrayList<Object>() {
- {
- add(1.41);
- add(null);
- }
- };
- List<Object> values5 =
- new ArrayList<Object>() {
- {
- add(null);
- add(false);
- }
- };
- List<Object> values6 =
- new ArrayList<Object>() {
- {
- add(null);
- add(3.5555);
- }
- };
-
- Assert.assertEquals(expressions, expressionsResult);
- Assert.assertEquals(timestamps, timestampsResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- Assert.assertEquals(values3, valuesResult.get(2));
- Assert.assertEquals(values4, valuesResult.get(3));
- Assert.assertEquals(values5, valuesResult.get(4));
- Assert.assertEquals(values6, valuesResult.get(5));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void queryGroupByLevel(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query");
- String sql =
- "{\"sql\":\"select count(s4) from root.sg25 group by([1635232143960,1635232153960),1s),level=1\"}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- List<Long> expressionsResult = (List<Long>) map.get("expressions");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- Assert.assertTrue(timestampsResult.size() == 10);
- Assert.assertTrue(valuesResult.size() == 1);
- Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0)));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public void queryRowLimit(CloseableHttpClient httpClient) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query");
- String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\",\"rowLimit\":1}";
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- assertTrue(message.contains("row size exceeded the given max row size"));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- }
-
- public Map queryMetaData(CloseableHttpClient httpClient, String sql) {
- CloseableHttpResponse response = null;
- try {
- HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query");
- httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset()));
- response = httpClient.execute(httpPost);
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- ObjectMapper mapper = new ObjectMapper();
- Map map = mapper.readValue(message, Map.class);
- return map;
-
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
- return null;
- }
-
- public void queryShowChildPaths(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show child paths root\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("child paths");
- add("node types");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
-
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void queryShowNodes(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show child nodes root\",\"rowLimit\":1}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("child nodes");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("sg25");
- }
- };
-
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void showAllTTL(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show all ttl\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("database");
- add("ttl");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add(null);
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- }
-
- public void showStorageGroup(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"SHOW DATABASES root.*\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("database");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void showFunctions(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show functions\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- assertEquals(3, columnNamesResult.size());
- assertEquals(3, valuesResult.size());
- }
-
- public void showTimeseries(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show timeseries\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("timeseries");
- add("alias");
- add("database");
- add("dataType");
- add("encoding");
- add("compression");
- add("tags");
- add("attributes");
- add("deadband");
- add("deadbandparameters");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25.s3");
- add("root.sg25.s4");
- add("root.sg25.s5");
- add("root.sg25.s6");
- add("root.sg25.s7");
- add("root.sg25.s8");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add(null);
- add(null);
- add(null);
- add(null);
- add(null);
- add(null);
- }
- };
- List<Object> values3 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- }
- };
-
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- Assert.assertEquals(values3, valuesResult.get(2));
- }
-
- public void showLastTimeseries(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"SHOW LATEST TIMESERIES\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("timeseries");
- add("alias");
- add("database");
- add("dataType");
- add("encoding");
- add("compression");
- add("tags");
- add("attributes");
- add("deadband");
- add("deadbandparameters");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25.s3");
- add("root.sg25.s4");
- add("root.sg25.s5");
- add("root.sg25.s7");
- add("root.sg25.s8");
- add("root.sg25.s6");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add(null);
- add(null);
- add(null);
- add(null);
- add(null);
- add(null);
- }
- };
- List<Object> values3 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- add("root.sg25");
- }
- };
-
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- Assert.assertEquals(values3, valuesResult.get(2));
- }
-
- public void countTimeseries(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"COUNT TIMESERIES root.** GROUP BY LEVEL=1\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("column");
- add("count");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add(6);
- }
- };
-
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- }
-
- public void countNodes(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"count nodes root.** level=2\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("count");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add(6);
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void showDevices(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show devices\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("devices");
- add("isAligned");
- add("Template");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- List<Boolean> values2 =
- new ArrayList<Boolean>() {
- {
- add(false);
- }
- };
- List<String> values3 =
- new ArrayList<String>() {
- {
- add("null");
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- // Assert.assertEquals(values2, valuesResult.get(1));
- }
-
- public void showDevicesWithStroage(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"show devices with database\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("devices");
- add("database");
- add("isAligned");
- add("Template");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add("root.sg25");
- }
- };
- List<Object> values3 =
- new ArrayList<Object>() {
- {
- add("false");
- }
- };
- List<Object> values4 =
- new ArrayList<Object>() {
- {
- add("null");
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2, valuesResult.get(1));
- Assert.assertEquals(values3, valuesResult.get(2));
- Assert.assertEquals(values4, valuesResult.get(3));
- }
-
- public void listUser(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"list user\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("user");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root");
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void selectCount(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"select count(s3) from root.** group by level = 1\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("count(root.sg25.s3)");
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add(2);
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- }
-
- public void selectLast(CloseableHttpClient httpClient) {
- String sql = "{\"sql\":\"select last s4 from root.sg25\"}";
- Map map = queryMetaData(httpClient, sql);
- List<String> columnNamesResult = (List<String>) map.get("columnNames");
- List<List<Object>> valuesResult = (List<List<Object>>) map.get("values");
- List<Long> timestampsResult = (List<Long>) map.get("timestamps");
- Assert.assertTrue(map.size() > 0);
- List<Object> columnNames =
- new ArrayList<Object>() {
- {
- add("timeseries");
- add("value");
- add("dataType");
- }
- };
- List<Long> timestamps =
- new ArrayList<Long>() {
- {
- add(1635232153960l);
- }
- };
- List<Object> values1 =
- new ArrayList<Object>() {
- {
- add("root.sg25.s4");
- }
- };
- List<Object> values2 =
- new ArrayList<Object>() {
- {
- add("2");
- }
- };
- List<Object> values3 =
- new ArrayList<Object>() {
- {
- add("INT32");
- }
- };
- Assert.assertEquals(columnNames, columnNamesResult);
- Assert.assertEquals(timestamps, timestampsResult);
- Assert.assertEquals(values1, valuesResult.get(0));
- Assert.assertEquals(values2.get(0), valuesResult.get(1).get(0));
- Assert.assertEquals(values3, valuesResult.get(2));
- }
-}
diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/v2/StatementConstructionTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/v2/StatementConstructionTest.java
new file mode 100644
index 00000000000..223ab6aecdb
--- /dev/null
+++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/v2/StatementConstructionTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.protocol.rest.v2;
+
+import org.apache.iotdb.db.protocol.rest.v2.handler.StatementConstructionHandler;
+import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class StatementConstructionTest {
+
+ @Test
+ public void testConstructInsertTabletStatement() {
+ InsertTabletRequest insertTabletRequest = genInsertTabletRequest();
+ try {
+ StatementConstructionHandler.constructInsertTabletStatement(insertTabletRequest);
+ } catch (Exception e) {
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void testConstructInsertRowsStatement() {}
+
+ private InsertTabletRequest genInsertTabletRequest() {
+ List<String> measurements = new ArrayList<>();
+ measurements.add("sensor0");
+ measurements.add("sensor1");
+ List<String> dataTypes = new ArrayList<>();
+ dataTypes.add(TSDataType.BOOLEAN.name());
+ dataTypes.add(TSDataType.INT64.name());
+
+ List<Long> times = new ArrayList<>();
+ List<List<Object>> columns = new ArrayList<>();
+ columns.add(new ArrayList<>());
+ columns.add(new ArrayList<>());
+
+ for (long r = 0; r < 101; r++) {
+ times.add(r);
+ columns.get(0).add(false);
+ columns.get(1).add(r);
+ }
+ InsertTabletRequest insertTabletRequest = new InsertTabletRequest();
+ insertTabletRequest.setTimestamps(times);
+ insertTabletRequest.setValues(columns);
+ insertTabletRequest.setDataTypes(dataTypes);
+ insertTabletRequest.setMeasurements(measurements);
+ insertTabletRequest.device("root.sg.d1");
+ insertTabletRequest.setIsAligned(false);
+
+ return insertTabletRequest;
+ }
+}