You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by zy...@apache.org on 2022/07/06 12:56:38 UTC
[iotdb] branch master updated: remove duplicate IT (#6602)
This is an automated email from the ASF dual-hosted git repository.
zyk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 2343a33b88 remove duplicate IT (#6602)
2343a33b88 is described below
commit 2343a33b882942b5a8e3d84b4583656982686c7f
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Wed Jul 6 20:56:33 2022 +0800
remove duplicate IT (#6602)
[IOTDB-3696] Remove duplicated IT #6602
---
.../db/integration/IoTDBAutoCreateSchemaIT.java | 208 ----
.../IoTDBCreateAlignedTimeseriesIT.java | 27 -
.../db/integration/IoTDBCreateStorageGroupIT.java | 131 --
.../db/integration/IoTDBDeleteStorageGroupIT.java | 183 ---
.../iotdb/db/integration/IoTDBDeletionIT.java | 529 --------
.../iotdb/db/integration/IoTDBMetadataFetchIT.java | 660 ----------
.../iotdb/db/integration/IoTDBMultiDeviceIT.java | 297 -----
.../IoTDBSameMeasurementsDifferentTypesIT.java | 182 ---
.../iotdb/db/integration/IoTDBSimpleQueryIT.java | 1258 --------------------
.../IoTDBSyntaxConventionIdentifierIT.java | 998 ----------------
.../IoTDBSyntaxConventionStringLiteralIT.java | 764 ------------
.../iotdb/db/integration/IoTDBTagAlterIT.java | 625 ----------
.../apache/iotdb/db/integration/IoTDBTagIT.java | 887 +-------------
.../db/integration/aligned/IoTDBDeletionIT.java | 554 ---------
14 files changed, 13 insertions(+), 7290 deletions(-)
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java
deleted file mode 100644
index 56235bfec1..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java
+++ /dev/null
@@ -1,208 +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.integration;
-
-import org.apache.iotdb.db.constant.TestConstant;
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.jdbc.Config;
-import org.apache.iotdb.jdbc.IoTDBSQLException;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
- * IoTDB server should be defined as integration test.
- */
-@Category({LocalStandaloneTest.class})
-public class IoTDBAutoCreateSchemaIT {
- private Statement statement;
- private Connection connection;
-
- @Before
- public void setUp() throws Exception {
- EnvironmentUtils.envSetUp();
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- statement = connection.createStatement();
- }
-
- @After
- public void tearDown() throws Exception {
- statement.close();
- connection.close();
- EnvironmentUtils.cleanEnv();
- }
-
- /** create timeseries without setting storage group */
- @Test
- public void createTimeseriesTest() throws ClassNotFoundException {
- String[] sqls = {
- "CREATE TIMESERIES root.sg0.d1.s2 WITH DATATYPE=INT32,ENCODING=RLE",
- "INSERT INTO root.sg0.d1(timestamp,s2) values(1,123)",
- };
- executeSQL(sqls);
- }
-
- /** insert data when storage group has been set but timeseries hasn't been created */
- @Test
- public void insertTest1() throws ClassNotFoundException {
- String[] sqls = {
- "SET STORAGE GROUP TO root.sg0",
- "INSERT INTO root.sg0.d1(timestamp,s2) values(1,123.123)",
- "INSERT INTO root.sg0.d1(timestamp,s3) values(1,\"abc\")",
- };
- executeSQL(sqls);
- }
-
- /** insert data when storage group hasn't been set and timeseries hasn't been created */
- @Test
- public void insertTest2() throws ClassNotFoundException {
- String[] sqls = {
- "INSERT INTO root.sg0.d1(timestamp,s2) values(1,\"abc\")",
- "INSERT INTO root.sg0.d2(timestamp,s3) values(1,123.123)",
- "INSERT INTO root.sg0.d2(timestamp,s4) values(1,123456)",
- };
- executeSQL(sqls);
- }
-
- private void executeSQL(String[] sqls) throws ClassNotFoundException {
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection =
- DriverManager.getConnection(
- Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
- String result = "";
- Long now_start = 0L;
- boolean cmp = false;
-
- for (String sql : sqls) {
- if (cmp) {
- Assert.assertEquals(sql, result);
- cmp = false;
- } else if (sql.equals("SHOW TIMESERIES")) {
- DatabaseMetaData data = connection.getMetaData();
- result = data.toString();
- cmp = true;
- } else {
- if (sql.contains("NOW()") && now_start == 0L) {
- now_start = System.currentTimeMillis();
- }
-
- statement.execute(sql);
- if (sql.split(" ")[0].equals("SELECT")) {
- ResultSet resultSet = statement.getResultSet();
- ResultSetMetaData metaData = resultSet.getMetaData();
- int count = metaData.getColumnCount();
- String[] column = new String[count];
- for (int i = 0; i < count; i++) {
- column[i] = metaData.getColumnName(i + 1);
- }
- result = "";
- while (resultSet.next()) {
- for (int i = 1; i <= count; i++) {
- if (now_start > 0L && column[i - 1].equals(TestConstant.TIMESTAMP_STR)) {
- String timestr = resultSet.getString(i);
- Long tn = Long.valueOf(timestr);
- Long now = System.currentTimeMillis();
- if (tn >= now_start && tn <= now) {
- timestr = "NOW()";
- }
- result += timestr + ',';
- } else {
- result += resultSet.getString(i) + ',';
- }
- }
- result += '\n';
- }
- cmp = true;
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * test if automatically creating a time series will cause the storage group with same name to
- * disappear
- */
- @Test
- public void testInsertAutoCreate2() throws Exception {
- String storageGroup = "root.sg2.a.b.c";
- String timeSeriesPrefix = "root.sg2.a.b";
-
- statement.execute(String.format("SET storage group TO %s", storageGroup));
- try {
- statement.execute(
- String.format("INSERT INTO %s(timestamp, c) values(123, \"aabb\")", timeSeriesPrefix));
- } catch (IoTDBSQLException ignored) {
- }
-
- // ensure that current storage group in cache is right.
- InsertAutoCreate2Tool(storageGroup, timeSeriesPrefix);
-
- statement.close();
- connection.close();
- EnvironmentUtils.stopDaemon();
- setUp();
-
- // ensure that storage group in cache is right after recovering.
- InsertAutoCreate2Tool(storageGroup, timeSeriesPrefix);
- }
-
- private void InsertAutoCreate2Tool(String storageGroup, String timeSeriesPrefix)
- throws SQLException {
- statement.execute("show timeseries");
- Set<String> resultList = new HashSet<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String str = resultSet.getString("timeseries");
- resultList.add(str);
- }
- }
- Assert.assertFalse(resultList.contains(timeSeriesPrefix + "c"));
-
- statement.execute("show storage group");
- resultList.clear();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- resultList.add(resultSet.getString("storage group"));
- }
- }
- Assert.assertTrue(resultList.contains(storageGroup));
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateAlignedTimeseriesIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateAlignedTimeseriesIT.java
index 036cd68365..b5327716e8 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateAlignedTimeseriesIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateAlignedTimeseriesIT.java
@@ -61,33 +61,6 @@ public class IoTDBCreateAlignedTimeseriesIT {
EnvironmentUtils.cleanEnv();
}
- @Test
- public void testCreateAlignedTimeseries() throws Exception {
- String[] timeSeriesArray =
- new String[] {
- "root.sg1.d1.vector1.s1,FLOAT,PLAIN,UNCOMPRESSED",
- "root.sg1.d1.vector1.s2,INT64,RLE,SNAPPY"
- };
-
- statement.execute("SET STORAGE GROUP TO root.sg1");
- try {
- statement.execute(
- "CREATE ALIGNED TIMESERIES root.sg1.d1.vector1(s1 FLOAT encoding=PLAIN compressor=UNCOMPRESSED,s2 INT64 encoding=RLE)");
- } catch (IoTDBSQLException ignored) {
- }
-
- // ensure that current storage group in cache is right.
- assertTimeseriesEquals(timeSeriesArray);
-
- statement.close();
- connection.close();
- EnvironmentUtils.stopDaemon();
- setUp();
-
- // ensure storage group in cache is right after recovering.
- assertTimeseriesEquals(timeSeriesArray);
- }
-
@Test
public void testCreateAlignedTimeseriesWithDeletion() throws Exception {
String[] timeSeriesArray =
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateStorageGroupIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateStorageGroupIT.java
deleted file mode 100644
index 4c2e5651d4..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBCreateStorageGroupIT.java
+++ /dev/null
@@ -1,131 +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.integration;
-
-import org.apache.iotdb.db.utils.EnvironmentUtils;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
- * IoTDB server should be defined as integration test.
- */
-@Category({LocalStandaloneTest.class})
-public class IoTDBCreateStorageGroupIT {
- private Statement statement;
- private Connection connection;
-
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
-
- connection = EnvFactory.getEnv().getConnection();
- statement = connection.createStatement();
- }
-
- @After
- public void tearDown() throws Exception {
- statement.close();
- connection.close();
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- /** The test creates three storage groups */
- @Test
- public void testCreateStorageGroup() throws Exception {
- String[] storageGroups = {"root.sg1", "root.sg2", "root.sg3"};
-
- for (String storageGroup : storageGroups) {
- statement.execute(String.format("create storage group %s", storageGroup));
- }
-
- // ensure that current StorageGroup in cache is right.
- createStorageGroupTool(storageGroups);
-
- statement.close();
- connection.close();
- EnvironmentUtils.stopDaemon();
- setUp();
-
- // ensure StorageGroup in cache is right after recovering.
- createStorageGroupTool(storageGroups);
- }
-
- private void createStorageGroupTool(String[] storageGroups) throws SQLException {
- boolean hasResult = statement.execute("show storage group");
- Assert.assertTrue(hasResult);
-
- List<String> resultList = new ArrayList<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String storageGroupPath = resultSet.getString("storage group");
- resultList.add(storageGroupPath);
- }
- }
- Assert.assertEquals(3, resultList.size());
-
- resultList = resultList.stream().sorted().collect(Collectors.toList());
-
- Assert.assertEquals(storageGroups[0], resultList.get(0));
- Assert.assertEquals(storageGroups[1], resultList.get(1));
- Assert.assertEquals(storageGroups[2], resultList.get(2));
- }
-
- /** Test creating a storage group that path is an existence storage group */
- @Test
- public void testCreateExistStorageGroup1() throws Exception {
- String storageGroup = "root.sg";
-
- statement.execute(String.format("set storage group to %s", storageGroup));
-
- try {
- statement.execute(String.format("create storage group %s", storageGroup));
- } catch (SQLException e) {
- Assert.assertEquals(e.getMessage(), "903: root.sg has already been set to storage group");
- }
- }
-
- /** Test the parent node has been set as a storage group */
- @Test
- public void testCreateExistStorageGroup2() throws Exception {
-
- statement.execute("create storage group root.sg");
-
- try {
- statement.execute("create storage group root.sg.`device`");
- } catch (SQLException e) {
- Assert.assertEquals(e.getMessage(), "903: root.sg has already been set to storage group");
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
deleted file mode 100644
index ac5873b0b6..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeleteStorageGroupIT.java
+++ /dev/null
@@ -1,183 +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.integration;
-
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.itbase.category.RemoteTest;
-import org.apache.iotdb.jdbc.IoTDBSQLException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-@Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
-public class IoTDBDeleteStorageGroupIT {
-
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- @Test
- public void testDeleteStorageGroup() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt01");
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt02");
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt03");
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt04");
- statement.execute("DELETE STORAGE GROUP root.ln.wf01.wt01");
- boolean hasResult = statement.execute("SHOW STORAGE GROUP");
- assertTrue(hasResult);
- String[] expected =
- new String[] {"root.ln.wf01.wt02", "root.ln.wf01.wt03", "root.ln.wf01.wt04"};
- List<String> expectedList = new ArrayList<>();
- Collections.addAll(expectedList, expected);
- List<String> result = new ArrayList<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- result.add(resultSet.getString(1));
- }
- }
- assertEquals(expected.length, result.size());
- assertTrue(expectedList.containsAll(result));
- }
- }
-
- @Test
- public void testDeleteMultipleStorageGroupWithQuote() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt01");
- statement.execute("SET STORAGE GROUP TO root.ln1.wf01.wt02");
- statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt03");
- statement.execute("SET STORAGE GROUP TO root.ln1.wf02.wt04");
- statement.execute("DELETE STORAGE GROUP root.ln1.wf01.wt01, root.ln1.wf02.wt03");
- boolean hasResult = statement.execute("SHOW STORAGE GROUP");
- assertTrue(hasResult);
- String[] expected = new String[] {"root.ln1.wf01.wt02", "root.ln1.wf02.wt04"};
- List<String> expectedList = new ArrayList<>();
- Collections.addAll(expectedList, expected);
- List<String> result = new ArrayList<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- result.add(resultSet.getString(1));
- }
- }
- assertEquals(expected.length, result.size());
- assertTrue(expectedList.containsAll(result));
- }
- }
-
- @Test(expected = IoTDBSQLException.class)
- public void deleteNonExistStorageGroup() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln2.wf01.wt01");
- statement.execute("DELETE STORAGE GROUP root.ln2.wf01.wt02");
- }
- }
-
- @Test
- public void testDeleteStorageGroupWithStar() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln3.wf01.wt01");
- statement.execute("SET STORAGE GROUP TO root.ln3.wf01.wt02");
- statement.execute("SET STORAGE GROUP TO root.ln3.wf02.wt03");
- statement.execute("SET STORAGE GROUP TO root.ln3.wf02.wt04");
- statement.execute("DELETE STORAGE GROUP root.ln3.wf02.*");
- boolean hasResult = statement.execute("SHOW STORAGE GROUP");
- assertTrue(hasResult);
- String[] expected = new String[] {"root.ln3.wf01.wt01", "root.ln3.wf01.wt02"};
- List<String> expectedList = new ArrayList<>();
- Collections.addAll(expectedList, expected);
- List<String> result = new ArrayList<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- result.add(resultSet.getString(1));
- }
- }
- assertEquals(expected.length, result.size());
- assertTrue(expectedList.containsAll(result));
- }
- }
-
- @Test
- public void testDeleteAllStorageGroups() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln4.wf01.wt01");
- statement.execute("SET STORAGE GROUP TO root.ln4.wf01.wt02");
- statement.execute("SET STORAGE GROUP TO root.ln4.wf02.wt03");
- statement.execute("SET STORAGE GROUP TO root.ln4.wf02.wt04");
- statement.execute("DELETE STORAGE GROUP root.**");
- boolean hasResult = statement.execute("SHOW STORAGE GROUP");
- assertTrue(hasResult);
- List<String> result = new ArrayList<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- result.add(resultSet.getString(1));
- }
- }
- assertEquals(0, result.size());
- }
- }
-
- @Test
- public void testDeleteStorageGroupAndThenQuery() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("insert into root.sg1.d1(time,s1) values(1,1);");
- statement.execute("flush");
- statement.execute("select count(*) from root.**;");
- statement.execute("delete storage group root.sg1");
- statement.execute("insert into root.sg1.sdhkajhd(time,s1) values(1,1);");
- statement.execute("flush");
- boolean hasResult = statement.execute("select count(*) from root.**");
- assertTrue(hasResult);
- int count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- count++;
- assertEquals(1, resultSet.getLong("count(root.sg1.sdhkajhd.s1)"));
- }
- }
- assertEquals(1, count);
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java
deleted file mode 100644
index 64debcd50b..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java
+++ /dev/null
@@ -1,529 +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.integration;
-
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.integration.env.ConfigFactory;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Locale;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class})
-public class IoTDBDeletionIT {
-
- private static String[] creationSqls =
- new String[] {
- "SET STORAGE GROUP TO root.vehicle.d0",
- "SET STORAGE GROUP TO root.vehicle.d1",
- "CREATE TIMESERIES root.vehicle.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s2 WITH DATATYPE=FLOAT, ENCODING=RLE",
- "CREATE TIMESERIES root.vehicle.d0.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN",
- "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN",
- };
-
- private String insertTemplate =
- "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4" + ") VALUES(%d,%d,%d,%f,%s,%b)";
- private String deleteAllTemplate = "DELETE FROM root.vehicle.d0 WHERE time <= 10000";
- private long prevPartitionInterval;
-
- @Before
- public void setUp() throws Exception {
- Locale.setDefault(Locale.ENGLISH);
- prevPartitionInterval = IoTDBDescriptor.getInstance().getConfig().getPartitionInterval();
- ConfigFactory.getConfig().setPartitionInterval(1000);
- EnvFactory.getEnv().initBeforeTest();
- prepareSeries();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- ConfigFactory.getConfig().setPartitionInterval(prevPartitionInterval);
- }
-
- /**
- * Should delete this case after the deletion value filter feature be implemented
- *
- * @throws SQLException
- */
- @Test
- @Category({ClusterTest.class})
- public void testUnsupportedValueFilter() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("insert into root.vehicle.d0(time,s0) values (10,310)");
- statement.execute("insert into root.vehicle.d0(time,s3) values (10,'text')");
- statement.execute("insert into root.vehicle.d0(time,s4) values (10,true)");
-
- String errorMsg =
- "416: For delete statement, where clause can only"
- + " contain time expressions, value filter is not currently supported.";
-
- String errorMsg2 =
- "416: For delete statement, where clause can only contain"
- + " atomic expressions like : time > XXX, time <= XXX,"
- + " or two atomic expressions connected by 'AND'";
-
- try {
- statement.execute(
- "DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND time > 0 AND time < 100");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg2, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND s0 > 0");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s3 WHERE s3 = 'text'");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s4 WHERE s4 != true");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s3 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s4 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void test() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time <= 300");
- statement.execute(
- "DELETE FROM root.vehicle.d0.s1,root.vehicle.d0.s2,root.vehicle.d0.s3"
- + " WHERE time <= 350");
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time <= 150");
-
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(250, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(100, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s1,s2,s3 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(50, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testMerge() throws SQLException {
- prepareMerge();
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("merge");
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time <= 15000");
-
- // before merge completes
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(5000, cnt);
- }
-
- // after merge completes
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(5000, cnt);
- }
- cleanData();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testDelAfterFlush() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt01");
- statement.execute(
- "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN," + " ENCODING=PLAIN");
- statement.execute(
- "INSERT INTO root.ln.wf01.wt01(timestamp,status) " + "values(1509465600000,true)");
- statement.execute("INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)");
-
- statement.execute("delete from root.ln.wf01.wt01.status where time <= NOW()");
- statement.execute("flush");
- statement.execute("delete from root.ln.wf01.wt01.status where time <= NOW()");
-
- try (ResultSet resultSet = statement.executeQuery("select status from root.ln.wf01.wt01")) {
- assertFalse(resultSet.next());
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testRangeDelete() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time <= 300");
- statement.execute("DELETE FROM root.vehicle.d0.s1 WHERE time > 150");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(100, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s1 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(150, cnt);
- }
-
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time > 50 and time <= 250");
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(200, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testFullDeleteWithoutWhereClause() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("DELETE FROM root.vehicle.d0.s0");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(0, cnt);
- }
- cleanData();
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testPartialPathRangeDelete() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.* WHERE time <= 300 and time > 150");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(250, cnt);
- }
-
- statement.execute("DELETE FROM root.vehicle.*.s0 WHERE time <= 100");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(150, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- public void testDelFlushingMemtable() throws SQLException {
- long size = IoTDBDescriptor.getInstance().getConfig().getMemtableSizeThreshold();
- // Adjust memstable threshold size to make it flush automatically
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(10000);
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (int i = 1; i <= 10000; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 1500 and time <= 9000");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(2500, cnt);
- }
- cleanData();
- }
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(size);
- }
-
- @Test
- public void testDelMultipleFlushingMemtable() throws SQLException {
- long size = IoTDBDescriptor.getInstance().getConfig().getMemtableSizeThreshold();
- // Adjust memstable threshold size to make it flush automatically
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(1000000);
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (int i = 1; i <= 100000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 15000 and time <= 30000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 30000 and time <= 40000");
- for (int i = 100001; i <= 200000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 50000 and time <= 80000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 90000 and time <= 110000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 150000 and time <= 165000");
- statement.execute("flush");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(110000, cnt);
- }
- cleanData();
- }
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(size);
- }
-
- @Test
- public void testDeleteAll() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("insert into root.lz.dev.GPS(time, latitude, longitude) values(9,3.2,9.8)");
- statement.execute("insert into root.lz.dev.GPS(time, latitude) values(11,4.5)");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
- statement.execute("delete from root.lz.**");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(0, cnt);
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testDelSeriesWithSpecialSymbol() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "CREATE TIMESERIES root.ln.d1.`status,01` WITH DATATYPE=BOOLEAN, ENCODING=PLAIN");
- statement.execute("INSERT INTO root.ln.d1(timestamp,`status,01`) VALUES(300, true)");
- statement.execute("INSERT INTO root.ln.d1(timestamp,`status,01`) VALUES(500, false)");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
- statement.execute("DELETE FROM root.ln.d1.`status,01` WHERE time <= 400");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
-
- statement.execute("DELETE FROM root.ln.d1.`status,01`");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(0, cnt);
- }
- }
- }
-
- private static void prepareSeries() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (String sql : creationSqls) {
- statement.execute(sql);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void prepareData() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- // prepare BufferWrite file
- for (int i = 201; i <= 300; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.execute("merge");
- // prepare Unseq-File
- for (int i = 1; i <= 100; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.execute("merge");
- // prepare BufferWrite cache
- for (int i = 301; i <= 400; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- // prepare Overflow cache
- for (int i = 101; i <= 200; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- }
- }
-
- private void cleanData() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(deleteAllTemplate);
- }
- }
-
- public void prepareMerge() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- // prepare BufferWrite data
- for (int i = 10001; i <= 20000; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- // prepare Overflow data
- for (int i = 1; i <= 10000; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMetadataFetchIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMetadataFetchIT.java
deleted file mode 100644
index e6b0e5aee8..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMetadataFetchIT.java
+++ /dev/null
@@ -1,660 +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.integration;
-
-import org.apache.iotdb.commons.conf.IoTDBConstant;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.itbase.category.RemoteTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
- * IoTDB server should be defined as integration test.
- */
-public class IoTDBMetadataFetchIT {
-
- private DatabaseMetaData databaseMetaData;
- private static final Logger logger = LoggerFactory.getLogger(IoTDBMetadataFetchIT.class);
-
- private static void insertSQL() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- String[] insertSqls =
- new String[] {
- "SET STORAGE GROUP TO root.ln.wf01.wt01",
- "SET STORAGE GROUP TO root.ln.wf01.wt02",
- "SET STORAGE GROUP TO root.ln1.wf01.wt01",
- "SET STORAGE GROUP TO root.ln2.wf01.wt01",
- "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE = BOOLEAN, ENCODING = PLAIN",
- "CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE = FLOAT, ENCODING = RLE, "
- + "compressor = SNAPPY, 'MAX_POINT_NUMBER' = '3' ",
- "CREATE ALIGNED TIMESERIES root.ln.wf01.wt02(s1 INT32, s2 DOUBLE)",
- "CREATE TIMESERIES root.ln1.wf01.wt01.status WITH DATATYPE = BOOLEAN, ENCODING = PLAIN",
- "CREATE TIMESERIES root.ln1.wf01.wt01.temperature WITH DATATYPE = FLOAT, ENCODING = RLE, "
- + "compressor = SNAPPY, 'MAX_POINT_NUMBER' = '3'",
- "CREATE TIMESERIES root.ln2.wf01.wt01.status WITH DATATYPE = BOOLEAN, ENCODING = PLAIN",
- "CREATE TIMESERIES root.ln2.wf01.wt01.temperature WITH DATATYPE = FLOAT, ENCODING = RLE, "
- + "compressor = SNAPPY, 'MAX_POINT_NUMBER' = '3'"
- };
-
- for (String sql : insertSqls) {
- statement.execute(sql);
- }
- } catch (Exception e) {
- logger.error("insertSQL() failed", e);
- fail(e.getMessage());
- }
- }
-
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
-
- insertSQL();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showTimeseriesTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- String[] sqls =
- new String[] {
- "show timeseries root.ln.wf01.wt01.status", // full seriesPath
- "show timeseries root.ln.**", // prefix seriesPath
- "show timeseries root.ln.*.wt01.*", // seriesPath with stars
- "show timeseries", // the same as root
- "show timeseries root.a.b", // nonexistent timeseries, thus returning ""
- };
- Set<String>[] standards =
- new Set[] {
- new HashSet<>(
- Collections.singletonList(
- "root.ln.wf01.wt01.status,null,root.ln.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,")),
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01.status,null,root.ln.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,",
- "root.ln.wf01.wt01.temperature,null,root.ln.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,",
- "root.ln.wf01.wt02.s1,null,root.ln.wf01.wt02,INT32,RLE,SNAPPY,null,null,",
- "root.ln.wf01.wt02.s2,null,root.ln.wf01.wt02,DOUBLE,GORILLA,SNAPPY,null,null,")),
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01.status,null,root.ln.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,",
- "root.ln.wf01.wt01.temperature,null,root.ln.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,")),
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01.status,null,root.ln.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,",
- "root.ln.wf01.wt01.temperature,null,root.ln.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,",
- "root.ln.wf01.wt02.s1,null,root.ln.wf01.wt02,INT32,RLE,SNAPPY,null,null,",
- "root.ln.wf01.wt02.s2,null,root.ln.wf01.wt02,DOUBLE,GORILLA,SNAPPY,null,null,",
- "root.ln1.wf01.wt01.status,null,root.ln1.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,",
- "root.ln1.wf01.wt01.temperature,null,root.ln1.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,",
- "root.ln2.wf01.wt01.status,null,root.ln2.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,",
- "root.ln2.wf01.wt01.temperature,null,root.ln2.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,")),
- new HashSet<>()
- };
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- Set<String> standard = standards[n];
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- String string = builder.toString();
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showTimeseriesTest() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showStorageGroupTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "show storage group",
- "show storage group root.ln.wf01.**",
- "show storage group root.ln.wf01.wt01.status"
- };
- Set<String>[] standards =
- new Set[] {
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01,",
- "root.ln.wf01.wt02,",
- "root.ln1.wf01.wt01,",
- "root.ln2.wf01.wt01,")),
- new HashSet<>(Arrays.asList("root.ln.wf01.wt01,", "root.ln.wf01.wt02,")),
- new HashSet<>()
- };
-
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- Set<String> standard = standards[n];
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- Assert.assertTrue(standard.contains(builder.toString()));
- String string = builder.toString();
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showStorageGroupTest() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class})
- public void showVersionTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String sql = "show version";
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- resultSet.next();
- Assert.assertEquals(IoTDBConstant.VERSION, resultSet.getString(1));
- }
- }
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showDevicesWithSgTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "show devices root.ln.** with storage group",
- "show devices root.ln.wf01.wt01.temperature"
- };
- Set<String>[] standards =
- new Set[] {
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01,root.ln.wf01.wt01,false,",
- "root.ln.wf01.wt02,root.ln.wf01.wt02,true,")),
- new HashSet<>()
- };
-
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- Set<String> standard = standards[n];
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- String string = builder.toString();
- System.out.println(string);
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showDevicesTest() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showDevicesTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {"show devices root.ln.**", "show devices root.ln.wf01.wt01.temperature"};
- Set<String>[] standards =
- new Set[] {
- new HashSet<>(Arrays.asList("root.ln.wf01.wt01,false,", "root.ln.wf01.wt02,true,")),
- new HashSet<>()
- };
-
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- Set<String> standard = standards[n];
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- String string = builder.toString();
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showDevicesTest() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showChildPaths() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls = new String[] {"show child paths root.ln"};
- String[] standards = new String[] {"root.ln.wf01,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showChildPaths() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showChildNodes() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls = new String[] {"show child nodes root.ln"};
- String[] standards = new String[] {"wf01,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showChildNodes() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showCountTimeSeries() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls = new String[] {"COUNT TIMESERIES root.ln.**", "COUNT TIMESERIES"};
- String[] standards = new String[] {"4,\n", "8,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showCountTimeSeries() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showCountDevices() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "COUNT DEVICES root.ln.**",
- "COUNT DEVICES",
- "COUNT DEVICES root.ln.wf01.wt01.temperature"
- };
- String[] standards = new String[] {"2,\n", "4,\n", "0,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showCountDevices() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showCountStorageGroup() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "count storage group root.ln.**",
- "count storage group",
- "count storage group root.ln.wf01.wt01.status"
- };
- String[] standards = new String[] {"2,\n", "4,\n", "0,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showCountStorageGroup() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showCountTimeSeriesGroupBy() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "COUNT TIMESERIES root.** group by level=1",
- "COUNT TIMESERIES root.** group by level=3",
- "COUNT TIMESERIES root.**.status group by level=2"
- };
- Set<String>[] standards =
- new Set[] {
- new HashSet<>(Arrays.asList("root.ln,4,", "root.ln1,2,", "root.ln2,2,")),
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01,2,",
- "root.ln.wf01.wt02,2,",
- "root.ln1.wf01.wt01,2,",
- "root.ln2.wf01.wt01,2,")),
- new HashSet<>(Arrays.asList("root.ln.wf01,1,", "root.ln1.wf01,1,", "root.ln2.wf01,1,")),
- };
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- Set<String> standard = standards[n];
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String string = resultSet.getString(1) + "," + resultSet.getInt(2) + ",";
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showCountTimeSeriesGroupBy() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showCountNodes() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] sqls =
- new String[] {
- "COUNT NODES root.** level=1",
- "COUNT NODES root.ln level=1",
- "COUNT NODES root.ln.wf01.** level=1",
- "COUNT NODES root.ln.wf01.* level=2",
- "COUNT NODES root.ln.wf01.* level=3",
- "COUNT NODES root.ln.wf01.* level=4"
- };
- String[] standards = new String[] {"3,\n", "1,\n", "1,\n", "1,\n", "2,\n", "0,\n"};
- for (int n = 0; n < sqls.length; n++) {
- String sql = sqls[n];
- String standard = standards[n];
- StringBuilder builder = new StringBuilder();
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- builder.append("\n");
- }
- }
- }
- Assert.assertEquals(standard, builder.toString());
- } catch (SQLException e) {
- logger.error("showCountNodes() failed", e);
- fail(e.getMessage());
- }
- }
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showAlignedTimeseriesWithAliasAndTags() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create aligned timeseries root.sg.d(s1(alias1) int32 tags('tag1'='v1', 'tag2'='v2'), s2 double attributes('attr3'='v3'))");
- String[] expected =
- new String[] {
- "root.sg.d.s1,alias1,root.sg,INT32,RLE,SNAPPY,{\"tag1\":\"v1\",\"tag2\":\"v2\"},null,",
- "root.sg.d.s2,null,root.sg,DOUBLE,GORILLA,SNAPPY,null,{\"attr3\":\"v3\"},"
- };
-
- int num = 0;
- boolean hasResultSet = statement.execute("show timeseries root.sg.d.*");
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- Assert.assertEquals(expected[num++], builder.toString());
- }
- }
- }
- Assert.assertEquals(2, num);
- }
- }
-
- @Test
- @Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
- public void showLatestTimeseriesTest() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("insert into root.ln.wf01.wt01(time, status) values(1, 1)");
- statement.execute("insert into root.ln.wf01.wt01(time, temperature) values(2, 1)");
- String sql = "show latest timeseries root.ln.wf01.wt01.*";
- Set<String> standard =
- new HashSet<>(
- Arrays.asList(
- "root.ln.wf01.wt01.temperature,null,root.ln.wf01.wt01,FLOAT,RLE,SNAPPY,null,null,",
- "root.ln.wf01.wt01.status,null,root.ln.wf01.wt01,BOOLEAN,PLAIN,SNAPPY,null,null,"));
- try {
- boolean hasResultSet = statement.execute(sql);
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i)).append(",");
- }
- String string = builder.toString();
- Assert.assertTrue(standard.contains(string));
- standard.remove(string);
- }
- assertEquals(0, standard.size());
- }
- }
- } catch (SQLException e) {
- logger.error("showTimeseriesTest() failed", e);
- fail(e.getMessage());
- }
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiDeviceIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiDeviceIT.java
deleted file mode 100644
index 6a77c28d2d..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiDeviceIT.java
+++ /dev/null
@@ -1,297 +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.integration;
-
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.constant.TestConstant;
-import org.apache.iotdb.integration.env.ConfigFactory;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
-import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
- * IoTDB server should be defined as integration test.
- */
-@Category({LocalStandaloneTest.class, ClusterTest.class})
-public class IoTDBMultiDeviceIT {
-
- private static TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig();
- private static int maxNumberOfPointsInPage;
- private static int pageSizeInByte;
- private static int groupSizeInByte;
- private static long prevPartitionInterval;
-
- @Before
- public void setUp() throws Exception {
- // use small page setting
- // origin value
- maxNumberOfPointsInPage = tsFileConfig.getMaxNumberOfPointsInPage();
- pageSizeInByte = tsFileConfig.getPageSizeInByte();
- groupSizeInByte = tsFileConfig.getGroupSizeInByte();
-
- // new value
- tsFileConfig.setMaxNumberOfPointsInPage(1000);
- tsFileConfig.setPageSizeInByte(1024 * 150);
- tsFileConfig.setGroupSizeInByte(1024 * 1000);
- ConfigFactory.getConfig().setMemtableSizeThreshold(1024 * 1000);
- prevPartitionInterval = IoTDBDescriptor.getInstance().getConfig().getPartitionInterval();
- ConfigFactory.getConfig().setPartitionInterval(100);
- ConfigFactory.getConfig().setCompressor("LZ4");
-
- EnvFactory.getEnv().initBeforeTest();
-
- insertData();
- }
-
- @After
- public void tearDown() throws Exception {
- // recovery value
- ConfigFactory.getConfig().setMaxNumberOfPointsInPage(maxNumberOfPointsInPage);
- ConfigFactory.getConfig().setPageSizeInByte(pageSizeInByte);
- ConfigFactory.getConfig().setGroupSizeInByte(groupSizeInByte);
-
- EnvFactory.getEnv().cleanAfterTest();
-
- ConfigFactory.getConfig().setPartitionInterval(prevPartitionInterval);
- ConfigFactory.getConfig().setMemtableSizeThreshold(groupSizeInByte);
- ConfigFactory.getConfig().setCompressor("SNAPPY");
- }
-
- private static void insertData() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (String sql : TestConstant.createSql) {
- statement.execute(sql);
- }
-
- statement.execute("SET STORAGE GROUP TO root.fans");
- statement.execute("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT32, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.fans.d2.s0 WITH DATATYPE=INT32, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.fans.d3.s0 WITH DATATYPE=INT32, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.car.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.car.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.car.d2.s1 WITH DATATYPE=INT64, ENCODING=RLE");
-
- // insert of data time range :0-1000 into fans
- for (int time = 0; time < 1000; time++) {
-
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- }
- statement.executeBatch();
-
- // insert large amount of data time range : 13700 ~ 24000
- for (int time = 13700; time < 24000; time++) {
-
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- }
- statement.executeBatch();
-
- // insert large amount of data time range : 3000 ~ 13600
- for (int time = 3000; time < 13600; time++) {
- // System.out.println("===" + time);
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- }
- statement.executeBatch();
-
- statement.execute("flush");
- statement.execute("merge");
-
- // unsequential data, memory data
- for (int time = 10000; time < 11000; time++) {
-
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- }
- statement.executeBatch();
-
- // sequential data, memory data
- for (int time = 200000; time < 201000; time++) {
-
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d2(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql =
- String.format("insert into root.fans.d3(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d0(timestamp,s0) values(%s,%s)", time, time % 70);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d1(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- sql = String.format("insert into root.car.d2(timestamp,s0) values(%s,%s)", time, time % 40);
- statement.addBatch(sql);
- }
- statement.executeBatch();
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void selectAllTest() {
- String selectSql = "select * from root.**";
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(selectSql);
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- long before = -1;
- while (resultSet.next()) {
- long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR));
- if (cur <= before) {
- fail("time order wrong!");
- }
- before = cur;
- cnt++;
- }
- assertEquals(22900, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void selectAfterDeleteTest() {
- String selectSql = "select * from root.**";
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.fans.** WHERE time <= 1000");
- statement.execute("DELETE FROM root.car.** WHERE time <= 1000");
- statement.execute("DELETE FROM root.fans.** WHERE time >= 200500 and time < 201000");
- statement.execute("DELETE FROM root.car.** WHERE time >= 200500 and time < 201000");
-
- boolean hasResultSet = statement.execute(selectSql);
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- long before = -1;
- while (resultSet.next()) {
- long cur = Long.parseLong(resultSet.getString(TestConstant.TIMESTAMP_STR));
- if (cur <= before) {
- fail("time order wrong!");
- }
- before = cur;
- cnt++;
- }
- assertEquals(21400, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSameMeasurementsDifferentTypesIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSameMeasurementsDifferentTypesIT.java
deleted file mode 100644
index adc436a718..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSameMeasurementsDifferentTypesIT.java
+++ /dev/null
@@ -1,182 +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.integration;
-
-import org.apache.iotdb.db.constant.TestConstant;
-import org.apache.iotdb.integration.env.ConfigFactory;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
-import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
-
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import static org.junit.Assert.fail;
-
-/**
- * Notice that, all test begins with "IoTDB" is integration test. All test which will start the
- * IoTDB server should be defined as integration test.
- */
-@Category({LocalStandaloneTest.class, ClusterTest.class})
-public class IoTDBSameMeasurementsDifferentTypesIT {
-
- private static TSFileConfig tsFileConfig = TSFileDescriptor.getInstance().getConfig();
- private static int maxNumberOfPointsInPage;
- private static int pageSizeInByte;
- private static int groupSizeInByte;
-
- @BeforeClass
- public static void setUp() throws Exception {
-
- // use small page setting
- // origin value
- maxNumberOfPointsInPage = tsFileConfig.getMaxNumberOfPointsInPage();
- pageSizeInByte = tsFileConfig.getPageSizeInByte();
- groupSizeInByte = tsFileConfig.getGroupSizeInByte();
-
- // new value
- ConfigFactory.getConfig()
- .setMaxNumberOfPointsInPage(1000)
- .setPageSizeInByte(1024 * 150)
- .setGroupSizeInByte(1024 * 1000)
- .setMemtableSizeThreshold(1024 * 1000);
-
- EnvFactory.getEnv().initBeforeClass();
-
- insertData();
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- // recovery value
- ConfigFactory.getConfig()
- .setMaxNumberOfPointsInPage(maxNumberOfPointsInPage)
- .setPageSizeInByte(pageSizeInByte)
- .setGroupSizeInByte(groupSizeInByte)
- .setMemtableSizeThreshold(groupSizeInByte);
- EnvFactory.getEnv().cleanAfterClass();
- }
-
- private static void insertData() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (String sql : TestConstant.createSql) {
- statement.execute(sql);
- }
-
- statement.execute("SET STORAGE GROUP TO root.fans");
- statement.execute("CREATE TIMESERIES root.fans.d0.s0 WITH DATATYPE=INT32, ENCODING=RLE");
- statement.execute("CREATE TIMESERIES root.fans.d1.s0 WITH DATATYPE=INT64, ENCODING=RLE");
-
- for (int time = 1; time < 10; time++) {
-
- String sql =
- String.format("insert into root.fans.d0(timestamp,s0) values(%s,%s)", time, time % 10);
- statement.execute(sql);
- sql = String.format("insert into root.fans.d1(timestamp,s0) values(%s,%s)", time, time % 5);
- statement.execute(sql);
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void selectAllTest() {
- String[] retArray =
- new String[] {
- "1,1,1", "2,2,2", "3,3,3", "4,4,4", "5,5,0", "6,6,1", "7,7,2", "8,8,3", "9,9,4"
- };
-
- String selectSql = "select * from root.**";
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement1 = connection.createStatement();
- Statement statement2 = connection.createStatement()) {
- statement1.setFetchSize(10);
- boolean hasResultSet1 = statement1.execute(selectSql);
- Assert.assertTrue(hasResultSet1);
- ResultSet resultSet1 = statement1.getResultSet();
- int cnt1 = 0;
- while (resultSet1.next() && cnt1 < 5) {
- StringBuilder builder = new StringBuilder();
- builder
- .append(resultSet1.getString(TestConstant.TIMESTAMP_STR))
- .append(",")
- .append(resultSet1.getString("root.fans.d0.s0"))
- .append(",")
- .append(resultSet1.getString("root.fans.d1.s0"));
- Assert.assertEquals(retArray[cnt1], builder.toString());
- cnt1++;
- }
-
- statement2.setFetchSize(10);
- boolean hasResultSet2 = statement2.execute(selectSql);
- Assert.assertTrue(hasResultSet2);
- ResultSet resultSet2 = statement2.getResultSet();
- int cnt2 = 0;
- while (resultSet2.next()) {
- StringBuilder builder = new StringBuilder();
- builder
- .append(resultSet2.getString(TestConstant.TIMESTAMP_STR))
- .append(",")
- .append(resultSet2.getString("root.fans.d0.s0"))
- .append(",")
- .append(resultSet2.getString("root.fans.d1.s0"));
- Assert.assertEquals(retArray[cnt2], builder.toString());
- cnt2++;
- }
- Assert.assertEquals(9, cnt2);
-
- // use do-while instead of while because in the previous while loop, we have executed the next
- // function,
- // and the cursor has been moved to the next position, so we should fetch that value first.
- do {
- StringBuilder builder = new StringBuilder();
- builder
- .append(resultSet1.getString(TestConstant.TIMESTAMP_STR))
- .append(",")
- .append(resultSet1.getString("root.fans.d0.s0"))
- .append(",")
- .append(resultSet1.getString("root.fans.d1.s0"));
- Assert.assertEquals(retArray[cnt1], builder.toString());
- cnt1++;
- } while (resultSet1.next());
- // Although the statement2 has the same sql as statement1, they shouldn't affect each other.
- // So the statement1's ResultSet should also have 9 rows in total.
- Assert.assertEquals(9, cnt1);
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
deleted file mode 100644
index 9ad510a17d..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSimpleQueryIT.java
+++ /dev/null
@@ -1,1258 +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.integration;
-
-import org.apache.iotdb.commons.exception.MetadataException;
-import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.db.metadata.LocalSchemaProcessor;
-import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.jdbc.IoTDBSQLException;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class})
-public class IoTDBSimpleQueryIT {
-
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- @Test
- public void testCreateTimeseries1() throws MetadataException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- IMeasurementMNode mNode =
- LocalSchemaProcessor.getInstance().getMeasurementMNode(new PartialPath("root.sg1.d0.s1"));
- assertEquals("PLAIN", mNode.getSchema().getEncodingType().toString().toUpperCase());
- }
-
- @Test
- public void testCreateTimeseriesSDTProperties() throws MetadataException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN,"
- + "'LOSS'='SDT','COMPDEV'='2'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- IMeasurementMNode mNode =
- LocalSchemaProcessor.getInstance().getMeasurementMNode(new PartialPath("root.sg1.d0.s1"));
-
- // check if SDT property is set
- assertEquals(2, mNode.getSchema().getProps().size());
- }
-
- @Test
- public void testCreateTimeseriesWithSDTProperties2() throws MetadataException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN,"
- + "'LOSS'='SDT','COMPDEV'='2','COMPMINTIME'='2','COMPMAXTIME'='10'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- IMeasurementMNode mNode =
- LocalSchemaProcessor.getInstance().getMeasurementMNode(new PartialPath("root.sg1.d0.s1"));
-
- // check if SDT property is set
- assertEquals(4, mNode.getSchema().getProps().size());
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testFailedToCreateTimeseriesSDTProperties() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- try {
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN,'LOSS'='SDT','COMPDEV'='-2'");
- } catch (Exception e) {
- assertEquals(
- "318: SDT compression deviation cannot be negative. Failed to create timeseries for path root.sg1.d0.s1",
- e.getMessage());
- }
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries")) {
- while (resultSet.next()) {
- count++;
- }
- }
- assertEquals(0, count);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testLastQueryNonCached() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.turbine.d1.s1 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
- statement.execute(
- "create timeseries root.turbine.d1.s2 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
- statement.execute(
- "create timeseries root.turbine.d2.s1 with datatype=FLOAT, encoding=GORILLA, compression=SNAPPY");
- statement.execute("insert into root.turbine.d1(timestamp,s1,s2) values(1,1,2)");
-
- String[] results = {"root.turbine.d1.s1", "root.turbine.d1.s2"};
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("select last ** from root")) {
- while (resultSet.next()) {
- String path = resultSet.getString("timeseries");
- assertEquals(results[count], path);
- count++;
- }
- }
-
- assertEquals(2, count);
-
- try (ResultSet resultSet = statement.executeQuery("select last * from root")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingSeq() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=DOUBLE,ENCODING=PLAIN,LOSS=SDT,COMPDEV=0.01");
-
- int degree = 0;
- for (int time = 0; time < 100; time++) {
- // generate data in sine wave pattern
- double value = 10 * Math.sin(degree++ * 3.141592653589793D / 180.0D);
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + "," + value + ")";
- statement.execute(sql);
- }
-
- // before SDT encoding
- ResultSet resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- int count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(count, 100);
-
- // after flush and SDT encoding
- statement.execute("flush");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(15, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingCompDev() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN,LOSS=SDT,COMPDEV=2");
-
- for (int time = 1; time < 8; time++) {
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + ",1)";
- statement.execute(sql);
- }
- statement.execute("flush");
-
- String sql = "insert into root.sg1.d0(timestamp,s0) values(15,10)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(16,20)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(17,1)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(18,30)";
- statement.execute(sql);
- statement.execute("flush");
-
- ResultSet resultSet = statement.executeQuery("select * from root.**");
- int count = 0;
-
- String[] timestamps = {"1", "7", "15", "16", "17", "18"};
- String[] values = {"1", "1", "10", "20", "1", "30"};
-
- while (resultSet.next()) {
- assertEquals(timestamps[count], resultSet.getString("Time"));
- assertEquals(values[count], resultSet.getString("root.sg1.d0.s0"));
- count++;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingSelectFill() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- double compDev = 2;
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN,'LOSS'='SDT','COMPDEV'="
- + "'"
- + compDev
- + "'");
-
- int[] originalValues = new int[1000];
-
- Map<String, Integer> map = new HashMap<>();
-
- Random rand = new Random();
- for (int i = 1; i < originalValues.length; i++) {
- originalValues[i] = rand.nextInt(500);
- String sql =
- "insert into root.sg1.d0(timestamp,s0) values(" + i + "," + originalValues[i] + ")";
- statement.execute(sql);
- map.put(i + "", originalValues[i]);
- }
- statement.execute("flush");
-
- for (int i = 1; i < originalValues.length; i++) {
- String sql =
- "select * from root.** where time = " + i + " fill(int32 [linear, 20ms, 20ms])";
- ResultSet resultSet = statement.executeQuery(sql);
-
- while (resultSet.next()) {
- String time = resultSet.getString("Time");
- String value = resultSet.getString("root.sg1.d0.s0");
- // last value is not stored, cannot linear fill
- if (value == null) {
- continue;
- }
- // sdt parallelogram's height is 2 * compDev, so after linear fill, the values will fall
- // inside
- // the parallelogram of two stored points
- assertTrue(Math.abs(Integer.parseInt(value) - map.get(time)) <= 2 * compDev);
- }
- }
- } catch (SQLException e) {
- fail();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingCompMin() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN,LOSS=SDT,COMPDEV=2, COMPMINTIME=1");
-
- for (int time = 1; time < 8; time++) {
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + ",1)";
- statement.execute(sql);
- }
- statement.execute("flush");
-
- String sql = "insert into root.sg1.d0(timestamp,s0) values(15,10)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(16,20)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(17,1)";
- statement.execute(sql);
- sql = "insert into root.sg1.d0(timestamp,s0) values(18,30)";
- statement.execute(sql);
- statement.execute("flush");
-
- ResultSet resultSet = statement.executeQuery("select * from root.**");
- int count = 0;
-
- // will not store time = 16 since time distance to last stored time 15 is within compMinTime
- String[] timestamps = {"1", "7", "15", "17", "18"};
- String[] values = {"1", "1", "10", "1", "30"};
-
- while (resultSet.next()) {
- assertEquals(timestamps[count], resultSet.getString("Time"));
- assertEquals(values[count], resultSet.getString("root.sg1.d0.s0"));
- count++;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingCompMax() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN,LOSS=SDT,COMPDEV=2, COMPMAXTIME=20");
-
- for (int time = 1; time < 50; time++) {
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + ",1)";
- statement.execute(sql);
- }
- statement.execute("flush");
-
- ResultSet resultSet = statement.executeQuery("select * from root.**");
- int count = 0;
-
- String[] timestamps = {"1", "21", "41", "49"};
- String[] values = {"1", "1", "1", "1"};
-
- while (resultSet.next()) {
- assertEquals(timestamps[count], resultSet.getString("Time"));
- assertEquals(values[count], resultSet.getString("root.sg1.d0.s0"));
- count++;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingUnseq() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=DOUBLE,ENCODING=PLAIN,LOSS=SDT,COMPDEV=0.01");
-
- int degree = 0;
- for (int time = 0; time < 100; time++) {
- // generate data in sine wave pattern
- double value = 10 * Math.sin(degree++ * 3.141592653589793D / 180.0D);
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + "," + value + ")";
- statement.execute(sql);
- }
-
- // insert unseq
- String sql = "insert into root.sg1.d0(timestamp,s0) values(2,19)";
- statement.execute(sql);
-
- // before SDT encoding
- ResultSet resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- int count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(count, 100);
-
- // after flush and SDT encoding
- statement.execute("flush");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(18, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingMergeSeq() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=DOUBLE,ENCODING=PLAIN,LOSS=SDT,COMPDEV=0.01");
-
- int degree = 0;
- for (int time = 0; time < 100; time++) {
- // generate data in sine wave pattern
- double value = 10 * Math.sin(degree++ * 3.141592653589793D / 180.0D);
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + "," + value + ")";
- statement.execute(sql);
- }
-
- // before SDT encoding
- ResultSet resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- int count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(100, count);
-
- // after flush and SDT encoding
- statement.execute("flush");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(15, count);
-
- // no sdt encoding when merging
- statement.execute("merge");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(15, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testSDTEncodingMergeUnseq() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- // test set sdt property
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=DOUBLE,ENCODING=PLAIN,LOSS=SDT,COMPDEV=0.01");
-
- int degree = 0;
- for (int time = 0; time < 100; time++) {
- // generate data in sine wave pattern
- double value = 10 * Math.sin(degree++ * 3.141592653589793D / 180.0D);
- String sql = "insert into root.sg1.d0(timestamp,s0) values(" + time + "," + value + ")";
- statement.execute(sql);
- }
-
- // insert unseq
- String sql = "insert into root.sg1.d0(timestamp,s0) values(2,19)";
- statement.execute(sql);
-
- // before SDT encoding
- ResultSet resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- int count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(100, count);
-
- // after flush and SDT encoding
- statement.execute("flush");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(18, count);
-
- // no sdt encoding when merging
- statement.execute("merge");
- resultSet = statement.executeQuery("select s0 from root.sg1.d0");
- count = 0;
- while (resultSet.next()) {
- count++;
- }
- assertEquals(18, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testEmptyDataSet() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- ResultSet resultSet = statement.executeQuery("select * from root.**");
- // has an empty time column
- Assert.assertEquals(1, resultSet.getMetaData().getColumnCount());
- try {
- while (resultSet.next()) {
- fail();
- }
-
- resultSet =
- statement.executeQuery(
- "select count(*) from root where time >= 1 and time <= 100 group by ([0, 100), 20ms, 20ms)");
- // has an empty time column
- Assert.assertEquals(1, resultSet.getMetaData().getColumnCount());
- while (resultSet.next()) {
- fail();
- }
-
- resultSet = statement.executeQuery("select count(*) from root");
- // has no column
- Assert.assertEquals(0, resultSet.getMetaData().getColumnCount());
- while (resultSet.next()) {
- fail();
- }
-
- resultSet = statement.executeQuery("select * from root.** align by device");
- // has time and device columns
- Assert.assertEquals(3, resultSet.getMetaData().getColumnCount());
- while (resultSet.next()) {
- fail();
- }
-
- resultSet = statement.executeQuery("select count(*) from root align by device");
- // has device column
- Assert.assertEquals(2, resultSet.getMetaData().getColumnCount());
- while (resultSet.next()) {
- fail();
- }
-
- resultSet =
- statement.executeQuery(
- "select count(*) from root where time >= 1 and time <= 100 "
- + "group by ([0, 100), 20ms, 20ms) align by device");
- // has time and device columns
- Assert.assertEquals(3, resultSet.getMetaData().getColumnCount());
- while (resultSet.next()) {
- fail();
- }
- } finally {
- resultSet.close();
- }
-
- resultSet.close();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testOrderByTimeDesc() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (1, 1)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (2, 2)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (3, 3)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (4, 4)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s1) VALUES (3, 3)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s1) VALUES (1, 1)");
- statement.execute("flush");
-
- String[] ret =
- new String[] {
- "4,4,null", "3,3,3", "2,2,null", "1,1,1",
- };
-
- int cur = 0;
- try (ResultSet resultSet =
- statement.executeQuery("select * from root.** order by time desc")) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("Time")
- + ","
- + resultSet.getString("root.sg1.d0.s0")
- + ","
- + resultSet.getString("root.sg1.d0.s1");
- assertEquals(ret[cur], ans);
- cur++;
- }
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowTimeseriesDataSet1() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s2 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s3 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s4 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s5 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s6 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s7 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s8 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s9 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s10 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- statement.execute("flush");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(10, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowTimeseriesDataSet2() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(10);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s2 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s3 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s4 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s5 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s6 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s7 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s8 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s9 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s10 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- statement.execute("flush");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(10, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowTimeseriesDataSet3() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(15);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s2 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s3 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s4 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s5 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s6 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s7 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s8 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s9 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s10 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- statement.execute("flush");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(10, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowTimeseriesDataSet4() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s2 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s3 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s4 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s5 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s6 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s7 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s8 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s9 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s10 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- statement.execute("flush");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries limit 8")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(8, count);
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowTimeseriesWithLimitOffset() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- List<String> exps =
- Arrays.asList("root.sg1.d0.s1", "root.sg1.d0.s2", "root.sg1.d0.s3", "root.sg1.d0.s4");
-
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s1) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s2) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s3) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s4) VALUES (5, 5)");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show timeseries limit 2 offset 1")) {
- while (resultSet.next()) {
- Assert.assertTrue(exps.contains(resultSet.getString(1)));
- ++count;
- }
- }
- Assert.assertEquals(2, count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowDevicesWithLimitOffset() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- List<String> exps = Arrays.asList("root.sg1.d1,false", "root.sg1.d2,false");
-
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s1) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d1(timestamp, s2) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d2(timestamp, s3) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d3(timestamp, s4) VALUES (5, 5)");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show devices limit 2 offset 1")) {
- while (resultSet.next()) {
- Assert.assertEquals(
- exps.get(count), resultSet.getString(1) + "," + resultSet.getString(2));
- ++count;
- }
- }
- Assert.assertEquals(2, count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testShowDevicesWithLimit() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- List<String> exps = Arrays.asList("root.sg1.d0,false", "root.sg1.d1,false");
-
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s1) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d1(timestamp, s2) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d2(timestamp, s3) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d3(timestamp, s4) VALUES (5, 5)");
-
- int count = 0;
- try (ResultSet resultSet = statement.executeQuery("show devices limit 2")) {
- while (resultSet.next()) {
- Assert.assertEquals(
- exps.get(count), resultSet.getString(1) + "," + resultSet.getString(2));
- ++count;
- }
- }
- Assert.assertEquals(2, count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testFirstOverlappedPageFiltered() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- // seq chunk : [1,10]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (1, 1)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (10, 10)");
-
- statement.execute("flush");
-
- // seq chunk : [13,20]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (13, 13)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (20, 20)");
-
- statement.execute("flush");
-
- // unseq chunk : [5,15]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (15, 15)");
-
- statement.execute("flush");
-
- long count = 0;
- try (ResultSet resultSet =
- statement.executeQuery("select s0 from root.sg1.d0 where s0 > 18")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(1, count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testPartialInsertion() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- try {
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0, s1) VALUES (1, 1, 2.2)");
- fail();
- } catch (IoTDBSQLException e) {
- assertTrue(e.getMessage().contains("s1"));
- }
-
- try (ResultSet resultSet = statement.executeQuery("select s0, s1 from root.sg1.d0")) {
- while (resultSet.next()) {
- assertEquals(1, resultSet.getInt("root.sg1.d0.s0"));
- assertEquals(null, resultSet.getString("root.sg1.d0.s1"));
- }
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testOverlappedPagesMerge() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- // seq chunk : start-end [1000, 1000]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (1000, 0)");
-
- statement.execute("flush");
-
- // unseq chunk : [1,10]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (1, 1)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (10, 10)");
-
- statement.execute("flush");
-
- // usneq chunk : [5,15]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (5, 5)");
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (15, 15)");
-
- statement.execute("flush");
-
- // unseq chunk : [15,15]
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (15, 150)");
-
- statement.execute("flush");
-
- long count = 0;
-
- try (ResultSet resultSet =
- statement.executeQuery("select s0 from root.sg1.d0 where s0 < 100")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- Assert.assertEquals(4, count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testUnseqUnsealedDeleteQuery() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute("CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT32,ENCODING=PLAIN");
-
- // seq data
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (1000, 1)");
- statement.execute("flush");
-
- for (int i = 1; i <= 10; i++) {
- statement.execute(
- String.format("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (%d, %d)", i, i));
- }
-
- statement.execute("flush");
-
- // unseq data
- for (int i = 11; i <= 20; i++) {
- statement.execute(
- String.format("INSERT INTO root.sg1.d0(timestamp, s0) VALUES (%d, %d)", i, i));
- }
-
- statement.execute("delete from root.sg1.d0.s0 where time <= 15");
-
- long count = 0;
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.**")) {
- while (resultSet.next()) {
- count++;
- }
- }
-
- System.out.println(count);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testTimeseriesMetadataCache() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- for (int i = 0; i < 10000; i++) {
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s" + i + " WITH DATATYPE=INT32,ENCODING=PLAIN");
- }
- for (int i = 1; i < 10000; i++) {
- statement.execute("INSERT INTO root.sg1.d0(timestamp, s" + i + ") VALUES (1000, 1)");
- }
- statement.execute("flush");
- statement.executeQuery("select s0 from root.sg1.d0");
- } catch (SQLException e) {
- fail();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testInvalidSchema() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- try {
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s1 with datatype=BOOLEAN, encoding=TS_2DIFF");
- } catch (Exception e) {
- Assert.assertEquals("303: encoding TS_2DIFF does not support BOOLEAN", e.getMessage());
- }
-
- try {
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s3 with datatype=DOUBLE, encoding=REGULAR");
- } catch (Exception e) {
- Assert.assertEquals("303: encoding REGULAR does not support DOUBLE", e.getMessage());
- }
-
- try {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s4 with datatype=TEXT, encoding=TS_2DIFF");
- } catch (Exception e) {
- Assert.assertEquals("303: encoding TS_2DIFF does not support TEXT", e.getMessage());
- }
-
- } catch (SQLException e) {
- fail();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testUseSameStatement() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s0 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d0.s1 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s0 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
-
- statement.execute("insert into root.sg1.d0(timestamp,s0,s1) values(1,1,1)");
- statement.execute("insert into root.sg1.d1(timestamp,s0,s1) values(1000,1000,1000)");
- statement.execute("insert into root.sg1.d0(timestamp,s0,s1) values(10,10,10)");
-
- List<ResultSet> resultSetList = new ArrayList<>();
-
- ResultSet r1 = statement.executeQuery("select * from root.sg1.d0 where time <= 1");
- resultSetList.add(r1);
-
- ResultSet r2 = statement.executeQuery("select * from root.sg1.d1 where s0 == 1000");
- resultSetList.add(r2);
-
- ResultSet r3 = statement.executeQuery("select * from root.sg1.d0 where s1 == 10");
- resultSetList.add(r3);
-
- r1.next();
- Assert.assertEquals(r1.getLong(1), 1L);
- Assert.assertEquals(r1.getLong(2), 1L);
- Assert.assertEquals(r1.getLong(3), 1L);
-
- r2.next();
- Assert.assertEquals(r2.getLong(1), 1000L);
- Assert.assertEquals(r2.getLong(2), 1000L);
- Assert.assertEquals(r2.getLong(3), 1000L);
-
- r3.next();
- Assert.assertEquals(r3.getLong(1), 10L);
- Assert.assertEquals(r3.getLong(2), 10L);
- Assert.assertEquals(r3.getLong(3), 10L);
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testInvalidMaxPointNumber() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s1 with datatype=FLOAT, encoding=TS_2DIFF, "
- + "'max_point_number'='4'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s2 with datatype=FLOAT, encoding=TS_2DIFF, "
- + "'max_point_number'='2.5'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s3 with datatype=FLOAT, encoding=RLE, "
- + "'max_point_number'='q'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s4 with datatype=FLOAT, encoding=RLE, "
- + "'max_point_number'='-1'");
- statement.execute(
- "insert into root.sg1.d1(timestamp,s1,s2,s3,s4) values(1,1.1234,1.1234,1.1234,1.1234)");
-
- try (ResultSet r1 = statement.executeQuery("select s1 from root.sg1.d1")) {
- r1.next();
- Assert.assertEquals(1.1234f, r1.getFloat(2), 0);
- }
-
- try (ResultSet r2 = statement.executeQuery("select s3 from root.sg1.d1")) {
- r2.next();
- Assert.assertEquals(1.12f, r2.getFloat(2), 0);
- }
-
- try (ResultSet r3 = statement.executeQuery("select s3 from root.sg1.d1")) {
- r3.next();
- Assert.assertEquals(1.12f, r3.getFloat(2), 0);
- }
-
- try (ResultSet r4 = statement.executeQuery("select s4 from root.sg1.d1")) {
- r4.next();
- Assert.assertEquals(1.12f, r4.getFloat(2), 0);
- }
-
- } catch (SQLException e) {
- fail();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testStorageGroupWithHyphenInName() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.setFetchSize(5);
- statement.execute("SET STORAGE GROUP TO root.group_with_hyphen");
- } catch (SQLException e) {
- fail();
- }
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute("SHOW STORAGE GROUP");
- if (hasResultSet) {
- try (ResultSet resultSet = statement.getResultSet()) {
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder builder = new StringBuilder();
- for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- builder.append(resultSet.getString(i));
- }
- Assert.assertEquals(builder.toString(), "root.group_with_hyphen");
- }
- }
- }
- } catch (SQLException e) {
- fail();
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testDisableAlign() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT32");
- statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=BOOLEAN");
- ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg1.d1 disable align");
- ResultSetMetaData metaData = resultSet.getMetaData();
- int[] types = {Types.TIMESTAMP, Types.INTEGER, Types.BIGINT, Types.BOOLEAN};
- int columnCount = metaData.getColumnCount();
- for (int i = 0; i < columnCount; i++) {
- Assert.assertEquals(types[i], metaData.getColumnType(i + 1));
- }
- }
- }
-
- @Test
- @Category({ClusterTest.class})
- public void testEnableAlign() throws Exception {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT32");
- statement.execute("CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=BOOLEAN");
- ResultSet resultSet = statement.executeQuery("select s1, s2 from root.sg1.d1");
- ResultSetMetaData metaData = resultSet.getMetaData();
- int[] types = {Types.TIMESTAMP, Types.INTEGER, Types.BOOLEAN};
- int columnCount = metaData.getColumnCount();
- for (int i = 0; i < columnCount; i++) {
- Assert.assertEquals(types[i], metaData.getColumnType(i + 1));
- }
- }
- }
-
- @Test
- public void testFromFuzzyMatching() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.sg1");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s1 with datatype=FLOAT, encoding=TS_2DIFF, "
- + "'max_point_number'='4'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s2 with datatype=FLOAT, encoding=TS_2DIFF, "
- + "'max_point_number'='2.5'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s3 with datatype=FLOAT, encoding=RLE, "
- + "'max_point_number'='q'");
- statement.execute(
- "CREATE TIMESERIES root.sg1.d1.s4 with datatype=FLOAT, encoding=RLE, "
- + "'max_point_number'='-1'");
- statement.execute(
- "insert into root.sg1.da1cb(timestamp,s1,s2,s3,s4) values(1,1.1234,1.1234,1.1234,1.1234)");
- statement.execute(
- "insert into root.sg1.da1ce(timestamp,s1,s2,s3,s4) values(1,1.1234,1.1234,1.1234,1.1234)");
-
- try (ResultSet r1 = statement.executeQuery("select s1 from root.sg1.*a*")) {
- while (r1.next()) {
- Assert.assertEquals(1.1234f, r1.getFloat(2), 0);
- }
- Assert.assertEquals(3, r1.getMetaData().getColumnCount());
- }
-
- } catch (SQLException e) {
- fail();
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java
deleted file mode 100644
index c962703832..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionIdentifierIT.java
+++ /dev/null
@@ -1,998 +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.integration;
-
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.itbase.category.RemoteTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
-public class IoTDBSyntaxConventionIdentifierIT {
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- @Test
- public void testKeyWord() {
- String[] createNodeNames = {
- "add",
- "as",
- "select",
- "drop_trigger",
- "REVOKE_USER_ROLE",
- "pipesink",
- "boolean",
- "datatype",
- "device",
- };
-
- String[] resultTimeseries = {
- "root.sg1.d1.add",
- "root.sg1.d1.as",
- "root.sg1.d1.select",
- "root.sg1.d1.drop_trigger",
- "root.sg1.d1.REVOKE_USER_ROLE",
- "root.sg1.d1.pipesink",
- "root.sg1.d1.boolean",
- "root.sg1.d1.datatype",
- "root.sg1.d1.device",
- };
-
- String[] selectNodeNames = {
- "add",
- "as",
- "select",
- "drop_trigger",
- "REVOKE_USER_ROLE",
- "pipesink",
- "boolean",
- "datatype",
- "device",
- };
-
- String[] suffixInResultColumns = {
- "add",
- "as",
- "select",
- "drop_trigger",
- "REVOKE_USER_ROLE",
- "pipesink",
- "boolean",
- "datatype",
- "device",
- };
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (int i = 0; i < createNodeNames.length; i++) {
- String createSql =
- String.format("CREATE TIMESERIES root.sg1.d1.%s INT32", createNodeNames[i]);
- String insertSql =
- String.format("INSERT INTO root.sg1.d1(time, %s) VALUES(1, 1)", createNodeNames[i]);
- statement.execute(createSql);
- statement.execute(insertSql);
- }
-
- boolean hasResult = statement.execute("SHOW TIMESERIES");
- Assert.assertTrue(hasResult);
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultTimeseries));
-
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertTrue(expectedResult.contains(resultSet.getString("timeseries")));
- expectedResult.remove(resultSet.getString("timeseries"));
- }
- Assert.assertEquals(0, expectedResult.size());
-
- for (int i = 0; i < selectNodeNames.length; i++) {
- String selectSql =
- String.format("SELECT %s FROM root.sg1.d1 WHERE time = 1", selectNodeNames[i]);
- hasResult = statement.execute(selectSql);
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- Assert.assertTrue(resultSet.next());
- Assert.assertEquals(1, resultSet.getInt("root.sg1.d1." + suffixInResultColumns[i]));
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testNodeName() {
- String[] createNodeNames = {
- "a_1",
- "aaa",
- "`select`",
- "`a.b`",
- "`111`",
- "`a``b`",
- "`a.\"b`",
- "`a.'b`",
- "````",
- "`c.d.```",
- "`abc`",
- };
-
- String[] resultTimeseries = {
- "root.sg1.d1.a_1",
- "root.sg1.d1.aaa",
- "root.sg1.d1.select",
- "root.sg1.d1.`a.b`",
- "root.sg1.d1.`111`",
- "root.sg1.d1.`a``b`",
- "root.sg1.d1.`a.\"b`",
- "root.sg1.d1.`a.'b`",
- "root.sg1.d1.````",
- "root.sg1.d1.`c.d.```",
- "root.sg1.d1.abc",
- };
-
- String[] selectNodeNames = {
- "a_1",
- "aaa",
- "`select`",
- "`a.b`",
- "`111`",
- "`a``b`",
- "`a.\"b`",
- "`a.'b`",
- "````",
- "`c.d.```",
- "abc",
- };
-
- String[] suffixInResultColumns = {
- "a_1",
- "aaa",
- "select",
- "`a.b`",
- "`111`",
- "`a``b`",
- "`a.\"b`",
- "`a.'b`",
- "````",
- "`c.d.```",
- "abc",
- };
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (int i = 0; i < createNodeNames.length; i++) {
- String createSql =
- String.format("CREATE TIMESERIES root.sg1.d1.%s INT32", createNodeNames[i]);
- String insertSql =
- String.format("INSERT INTO root.sg1.d1(time, %s) VALUES(1, 1)", createNodeNames[i]);
- statement.execute(createSql);
- statement.execute(insertSql);
- }
-
- boolean hasResult = statement.execute("SHOW TIMESERIES");
- Assert.assertTrue(hasResult);
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultTimeseries));
-
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertTrue(expectedResult.contains(resultSet.getString("timeseries")));
- expectedResult.remove(resultSet.getString("timeseries"));
- }
- Assert.assertEquals(0, expectedResult.size());
-
- for (int i = 0; i < selectNodeNames.length; i++) {
- String selectSql =
- String.format("SELECT %s FROM root.sg1.d1 WHERE time = 1", selectNodeNames[i]);
- hasResult = statement.execute(selectSql);
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- Assert.assertTrue(resultSet.next());
- Assert.assertEquals(1, resultSet.getInt("root.sg1.d1." + suffixInResultColumns[i]));
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testNodeNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- // nodeName with special characters should be quoted with '`'
- try {
- statement.execute("create timeseries root.sg1.d1.`a INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.[a INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.a! INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.a\" INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.a' INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- // nodeName consists of numbers should be quoted with '`'
- try {
- statement.execute("create timeseries root.sg1.d1.111 INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.012 INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- // shouled use double '`' in a quoted nodeName
- try {
- statement.execute("create timeseries root.sg1.d1.`a`` INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.``a` INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- // unsupported
- try {
- statement.execute("create timeseries root.sg1.d1.contains INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.and INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.or INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.not INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- // reserved words can not be identifier
- try {
- statement.execute("create timeseries root.sg1.d1.root INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.time INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create timeseries root.sg1.d1.timestamp INT32");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testCreateIllegalStorageGroup() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- try {
- statement.execute("create storage group root.sg1.d1.");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testExpression() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.`1` INT32");
- statement.execute("CREATE TIMESERIES root.sg1.d1.`a.b` INT32");
- statement.execute("CREATE TIMESERIES root.sg1.d1.`a.``b` INT32");
- int pointCnt = 3;
- for (int i = 0; i < pointCnt; i++) {
- statement.execute(
- String.format(
- "insert into root.sg1.d1(time,%s,%s,%s) values(%d,%d,%d,%d)",
- "`1`", "`a.b`", "`a.``b`", i, i, i, i));
- }
-
- int cnt = 0;
- boolean hasResult = statement.execute("SELECT `1` + 1 FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(pointCnt, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT (`1`*`1`)+1-`a.b` FROM root.sg1.d1 where `1` > 1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(1, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT (`1`*`1`)+1-`a.b` FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(pointCnt, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT (`1`*`1`)+1-`a.b` FROM root.sg1.d1 where `1`>0");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT avg(`1`)+1 FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(1, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT count(`1`)+1 FROM root.sg1.d1 where `1`>1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertEquals(2.0, resultSet.getDouble(1), 1e-7);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT sin(`1`) + 1 FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(pointCnt, cnt);
-
- cnt = 0;
- hasResult = statement.execute("SELECT sin(`1`) + 1 FROM root.sg1.d1 where `1`>1");
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUDFName() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] udfNames = {"udf", "`udf.test`", "`012`", "`udf```"};
-
- String[] resultNames = {"udf", "udf.test", "012", "udf`"};
-
- String createSql = "create function %s as 'org.apache.iotdb.db.query.udf.example.Adder'";
- for (int i = 0; i < udfNames.length; i++) {
- statement.execute(String.format(createSql, udfNames[i]));
- }
- statement.execute("show functions");
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultNames));
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- if (resultSet.getString(2).equals("external UDTF")) {
- String udf = resultSet.getString(1).toLowerCase();
- Assert.assertTrue(expectedResult.contains(udf));
- expectedResult.remove(udf);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUDFNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute("create function udf` as 'org.apache.iotdb.db.query.udf.example.Adder'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create function ``udf` as 'org.apache.iotdb.db.query.udf.example.Adder'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create function 111 as 'org.apache.iotdb.db.query.udf.example.Adder'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create function 'udf' as 'org.apache.iotdb.db.query.udf.example.Adder'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create function \"udf\" as 'org.apache.iotdb.db.query.udf.example.Adder'");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testTriggerName() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] timeseries = {
- "root.vehicle.d1.s1",
- "root.vehicle.d1.s2",
- "root.vehicle.d1.s3",
- "root.vehicle.d1.s4",
- "root.vehicle.d1.s5",
- };
-
- String[] triggerNames = {
- "`trigger`", "trigger1", "`test```", "`111`", "`[trigger]`",
- };
-
- String[] resultNames = {
- "trigger", "trigger1", "test`", "111", "[trigger]",
- };
- // show
- ResultSet resultSet = statement.executeQuery("show triggers");
- assertFalse(resultSet.next());
-
- String createTimeSereisSql = "CREATE TIMESERIES %s FLOAT";
- String createTriggerSql =
- "create trigger %s before insert on %s "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'";
- for (int i = 0; i < timeseries.length; ++i) {
- statement.execute(String.format(createTimeSereisSql, timeseries[i]));
- statement.execute(String.format(createTriggerSql, triggerNames[i], timeseries[i]));
- }
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultNames));
- resultSet = statement.executeQuery("show triggers");
- while (resultSet.next()) {
- String trigger = resultSet.getString(1).toLowerCase();
- Assert.assertTrue(expectedResult.contains(trigger));
- expectedResult.remove(trigger);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testTriggerNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute(
- "create trigger trigger` before insert on root.sg1.d1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create trigger `trigger`` before insert on root.sg1.d1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create trigger 111 before insert on root.sg1.d1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create trigger 'tri' before insert on root.sg1.d1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create trigger \"tri\" before insert on root.sg1.d1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testContinuousQueryNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute(
- "CREATE CONTINUOUS QUERY `cq1 "
- + "BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* "
- + "GROUP BY time(1s) END");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "CREATE CONTINUOUS QUERY 111 "
- + "BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* "
- + "GROUP BY time(1s) END");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "CREATE CONTINUOUS QUERY ``cq1` "
- + "BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* "
- + "GROUP BY time(1s) END");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "CREATE CONTINUOUS QUERY 'cq1' "
- + "BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* "
- + "GROUP BY time(1s) END");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "CREATE CONTINUOUS QUERY \"cq1\" "
- + "BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* "
- + "GROUP BY time(1s) END");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testTemplateName() {
- String[] templateNames = {
- "id",
- "ID",
- "id0",
- "_id",
- "0id",
- "`233`",
- "`ab!`",
- "`\"ab\"`",
- "`\\\"ac\\\"`",
- "`'ab'`",
- "`a.b`",
- "`a``b`"
- };
-
- String[] resultNames = {
- "id", "ID", "id0", "_id", "0id", "233", "ab!", "\"ab\"", "\\\"ac\\\"", "'ab'", "a.b", "a`b"
- };
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String templateName : templateNames) {
- String createTemplateSql =
- String.format(
- "create schema template %s (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)",
- templateName);
- statement.execute(createTemplateSql);
- }
-
- boolean hasResult = statement.execute("SHOW TEMPLATES");
- Assert.assertTrue(hasResult);
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultNames));
-
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertTrue(expectedResult.contains(resultSet.getString("template name")));
- expectedResult.remove(resultSet.getString("template name"));
- }
- Assert.assertEquals(0, expectedResult.size());
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testTemplateNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute(
- "create schema template `a`` "
- + "(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create schema template 111 "
- + "(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create schema template `a "
- + "(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create schema template 'a' "
- + "(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute(
- "create schema template \"a\" "
- + "(temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUserName() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] userNames =
- new String[] {
- "userid",
- "userid0",
- "user_id",
- "user0id",
- "`22233`",
- "`userab!`",
- "`user'ab'`",
- "`usera.b`",
- "`usera``b`"
- };
-
- String[] resultNames =
- new String[] {
- "root",
- "userid",
- "userid0",
- "user_id",
- "user0id",
- "22233",
- "userab!",
- "user'ab'",
- "usera.b",
- "usera`b"
- };
-
- String createUsersSql = "create user %s 'pwd123' ";
- for (String userName : userNames) {
- statement.execute(String.format(createUsersSql, userName));
- }
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultNames));
- ResultSet resultSet = statement.executeQuery("list user");
- while (resultSet.next()) {
- String user = resultSet.getString("user").toLowerCase();
- Assert.assertTrue(expectedResult.contains(user));
- expectedResult.remove(user);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUserNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute("create user `abcd`` 'pwd123'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create user `abcd 'pwd123'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create user 12345 'pwd123'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create user a.b.c 'pwd123'");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create user a!@bc 'pwd123'");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testRoleName() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- String[] roleNames =
- new String[] {
- "roleid",
- "roleid0",
- "role_id",
- "role0id",
- "`22233`",
- "`roleab!`",
- "`role'ab'`",
- "`rolea.b`",
- "`rolea``b`"
- };
-
- String[] resultNames =
- new String[] {
- "roleid",
- "roleid0",
- "role_id",
- "role0id",
- "22233",
- "roleab!",
- "role'ab'",
- "rolea.b",
- "rolea`b"
- };
- String createRolesSql = "create role %s";
- for (String roleName : roleNames) {
- statement.execute(String.format(createRolesSql, roleName));
- }
- Set<String> expectedResult = new HashSet<>(Arrays.asList(resultNames));
- ResultSet resultSet = statement.executeQuery("list role");
- while (resultSet.next()) {
- String role = resultSet.getString("role").toLowerCase();
- Assert.assertTrue(expectedResult.contains(role));
- expectedResult.remove(role);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testRoleNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute("create role `abcd``");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create role `abcd");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create role 123456");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create role a.b.c");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("create role a!b%c");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testPipeSinkNameIllegal() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- try {
- statement.execute("CREATE PIPESINK test` AS IoTDB (`ip` = '127.0.0.1')");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("CREATE PIPESINK ``test` AS IoTDB (`ip` = '127.0.0.1')");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("CREATE PIPESINK test.1 AS IoTDB (`ip` = '127.0.0.1')");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("CREATE PIPESINK 12345 AS IoTDB (`ip` = '127.0.0.1')");
- fail();
- } catch (Exception ignored) {
- }
-
- try {
- statement.execute("CREATE PIPESINK a!@cb AS IoTDB (`ip` = '127.0.0.1')");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java
deleted file mode 100644
index 8126369bbe..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBSyntaxConventionStringLiteralIT.java
+++ /dev/null
@@ -1,764 +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.integration;
-
-import org.apache.iotdb.commons.udf.builtin.BuiltinTimeSeriesGeneratingFunction;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.itbase.category.RemoteTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import static org.apache.iotdb.commons.conf.IoTDBConstant.FUNCTION_TYPE_NATIVE;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
-public class IoTDBSyntaxConventionStringLiteralIT {
-
- @Before
- public void setUp() throws Exception {
- EnvFactory.getEnv().initBeforeTest();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- /** Legal cases of using StringLiteral with single quote in insert and select clause. */
- @Test
- public void testStringLiteralWithSingleQuote() {
- String[] insertData = {
- "'string'",
- "'`string`'",
- "'``string'",
- "'\"string\"'",
- "'\"\"string'",
- "'\\\"string\\\"'",
- "'''string'",
- "'\\'string'",
- "'\\nstring'",
- "'\\rstring'",
- "'@#$%^&*()string'",
- };
-
- String[] resultData = {
- "string",
- "`string`",
- "``string",
- "\"string\"",
- "\"\"string",
- "\"string\"",
- "'string",
- "'string",
- "\\nstring",
- "\\rstring",
- "@#$%^&*()string",
- };
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- for (int i = 0; i < insertData.length; i++) {
- String insertSql =
- String.format("INSERT INTO root.sg1.d1(time, s1) values (%d, %s)", i, insertData[i]);
- System.out.println("INSERT STATEMENT: " + insertSql);
- statement.execute(insertSql);
- }
-
- boolean hasResult = statement.execute("SELECT s1 FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
-
- int cnt = 0;
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertEquals(resultData[cnt], resultSet.getString("root.sg1.d1.s1"));
- cnt++;
- }
- Assert.assertEquals(insertData.length, cnt);
-
- for (int i = 0; i < insertData.length; i++) {
- String querySql = String.format("SELECT s1 FROM root.sg1.d1 WHERE s1 = %s", insertData[i]);
- System.out.println("QUERY STATEMENT: " + querySql);
- hasResult = statement.execute(querySql);
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- Assert.assertTrue(resultSet.next());
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- /** Legal cases of using StringLiteral with double quote in insert and select clause. */
- @Test
- public void testStringLiteralWithDoubleQuote() {
- String[] insertData = {
- "\"string\"",
- "\"`string`\"",
- "\"``string\"",
- "\"'string'\"",
- "\"''string\"",
- "\"\\'string\\'\"",
- "\"\"\"string\"",
- "\"\\\"string\"",
- "\"\\nstring\"",
- "\"\\rstring\"",
- "\"@#$%^&*()string\"",
- };
-
- String[] resultData = {
- "string",
- "`string`",
- "``string",
- "'string'",
- "''string",
- "'string'",
- "\"string",
- "\"string",
- "\\nstring",
- "\\rstring",
- "@#$%^&*()string",
- };
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- for (int i = 0; i < insertData.length; i++) {
- String insertSql =
- String.format("INSERT INTO root.sg1.d1(time, s1) values (%d, %s)", i, insertData[i]);
- System.out.println("INSERT STATEMENT: " + insertSql);
- statement.execute(insertSql);
- }
-
- boolean hasResult = statement.execute("SELECT s1 FROM root.sg1.d1");
- Assert.assertTrue(hasResult);
-
- int cnt = 0;
- ResultSet resultSet = statement.getResultSet();
- while (resultSet.next()) {
- Assert.assertEquals(resultData[cnt], resultSet.getString("root.sg1.d1.s1"));
- cnt++;
- }
- Assert.assertEquals(insertData.length, cnt);
-
- for (int i = 0; i < insertData.length; i++) {
- String querySql = String.format("SELECT s1 FROM root.sg1.d1 WHERE s1 = %s", insertData[i]);
- System.out.println("QUERY STATEMENT: " + querySql);
- hasResult = statement.execute(querySql);
- Assert.assertTrue(hasResult);
-
- resultSet = statement.getResultSet();
- Assert.assertTrue(resultSet.next());
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testStringLiteralIllegalCase() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:45 no viable alternative at input '(1, string'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- // without ' or "
- statement.execute("INSERT INTO root.sg1.d1(time, s1) values (1, string)");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testStringLiteralIllegalCase1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:45 no viable alternative at input '(1, `string`'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- // wrap STRING_LITERAL with ``
- statement.execute("INSERT INTO root.sg1.d1(time, s1) values (1, `string`)");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testStringLiteralIllegalCase2() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:53 token recognition error at: '')'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- // single ' in ''
- statement.execute("INSERT INTO root.sg1.d1(time, s1) values (1, ''string')");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testStringLiteralIllegalCase3() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:53 token recognition error at: '\")'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
- // single " in ""
- statement.execute("INSERT INTO root.sg1.d1(time, s1) values (1, \"\"string\")");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- /**
- * LOAD/REMOVE/SETTLE use STRING_LITERAL to represent file path legal cases are in
- * IoTDBLoadExternalTsfileIT
- */
- @Test
- public void testFilePath() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("LOAD 'path'");
- fail();
- } catch (SQLException ignored) {
- }
- }
-
- @Test
- public void testFilePath1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:5 no viable alternative at input 'LOAD path'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("LOAD path");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testFilePath2() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("REMOVE 'path'");
- fail();
- } catch (SQLException ignored) {
- }
- }
-
- @Test
- public void testFilePath3() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:7 mismatched input 'path' expecting STRING_LITERAL";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("REMOVE path");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testFilePath4() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SETTLE 'path'");
- fail();
- } catch (SQLException ignored) {
- }
- }
-
- @Test
- public void testFilePath5() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:7 mismatched input 'path' expecting {ROOT, STRING_LITERAL}";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SETTLE path");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testUserPassword() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:17 mismatched input 'test' expecting STRING_LITERAL";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE USER test 'test'");
- // password should be STRING_LITERAL
- statement.execute("CREATE USER test test");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testUserPassword1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:17 mismatched input '`test`' expecting STRING_LITERAL";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE USER test \"test\"");
- // password should be STRING_LITERAL
- statement.execute("CREATE USER test `test`");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testTriggerClassName() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:64 mismatched input 'org' expecting {AS, '.'}";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- // show
- ResultSet resultSet = statement.executeQuery("show triggers");
- assertFalse(resultSet.next());
-
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s2 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s3 FLOAT");
- // create trigger, trigger class name should be STRING_LITERAL
- statement.execute(
- "create trigger trigger_1 before insert on root.vehicle.d1.s1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator'");
- statement.execute(
- "create trigger trigger_2 after insert on root.vehicle.d1.s2 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Counter'");
-
- // show
- resultSet = statement.executeQuery("show triggers");
- assertTrue(resultSet.next());
- assertTrue(resultSet.next());
- assertFalse(resultSet.next());
-
- // show
- resultSet = statement.executeQuery("show triggers");
- assertTrue(resultSet.next());
- assertTrue(resultSet.next());
- assertFalse(resultSet.next());
-
- statement.execute(
- "create trigger trigger_1 before insert on root.vehicle.d1.s3 "
- + "as org.apache.iotdb.db.engine.trigger.example.Accumulator");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testTriggerClassName1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:64 mismatched input '`org.apache.iotdb.db.engine.trigger.example.Accumulator`' "
- + "expecting {AS, '.'}";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 FLOAT");
- statement.execute(
- "create trigger trigger_1 before insert on root.vehicle.d1.s1 "
- + "as `org.apache.iotdb.db.engine.trigger.example.Accumulator`");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testUDFClassName() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:23 mismatched input 'org' expecting STRING_LITERAL";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- // udf class name should be STRING_LITERAL
- statement.execute("create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'");
-
- // executed correctly
- ResultSet resultSet = statement.executeQuery("show functions");
- assertEquals(3, resultSet.getMetaData().getColumnCount());
- int count = 0;
- while (resultSet.next()) {
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); ++i) {
- stringBuilder.append(resultSet.getString(i)).append(",");
- }
- String result = stringBuilder.toString();
- if (result.contains(FUNCTION_TYPE_NATIVE)) {
- continue;
- }
- ++count;
- }
- Assert.assertEquals(1 + BuiltinTimeSeriesGeneratingFunction.values().length, count);
- resultSet.close();
- statement.execute("drop function udf");
-
- // without '' or ""
- statement.execute("create function udf as org.apache.iotdb.db.query.udf.example.Adder");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testUDFClassName1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:23 mismatched input '`org.apache.iotdb.db.query.udf.example.Adder`' "
- + "expecting STRING_LITERAL";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- // udf class name should be STRING_LITERAL
- statement.execute("create function udf as `org.apache.iotdb.db.query.udf.example.Adder`");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- // attribute can be constant | identifier
- @Test
- public void testTriggerAttribute() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s2 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s3 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s4 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s5 FLOAT");
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s6 FLOAT");
- // trigger attribute should be STRING_LITERAL
- statement.execute(
- "create trigger trigger_1 before insert on root.vehicle.d1.s1 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with ('k1'='v1')");
-
- statement.execute(
- "create trigger trigger_2 before insert on root.vehicle.d1.s2 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with (k1='v1')");
-
- statement.execute(
- "create trigger trigger_3 before insert on root.vehicle.d1.s3 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with ('k1'=v1)");
-
- statement.execute(
- "create trigger trigger_4 before insert on root.vehicle.d1.s4 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with (k1=v1)");
-
- statement.execute(
- "create trigger trigger_5 before insert on root.vehicle.d1.s5 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with (`k1`=`v1`)");
-
- statement.execute(
- "create trigger trigger_6 before insert on root.vehicle.d1.s6 "
- + "as 'org.apache.iotdb.db.engine.trigger.example.Accumulator' with (`k1`=v1)");
-
- boolean hasResult = statement.execute("show triggers");
- assertTrue(hasResult);
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUDFAttribute() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 FLOAT");
- statement.execute("INSERT INTO root.vehicle.d1(time,s1) values (1,2.0),(2,3.0)");
-
- ResultSet resultSet =
- statement.executeQuery("select bottom_k(s1,'k' = '1') from root.vehicle.d1");
- assertTrue(resultSet.next());
- Assert.assertEquals("2.0", resultSet.getString(2));
-
- // resultSet = statement.executeQuery("select bottom_k(s1,k = 1) from root.vehicle.d1");
- // assertTrue(resultSet.next());
- // Assert.assertEquals("2.0", resultSet.getString(2));
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testUDFAttribute1() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:21 extraneous input 'k' expecting {',', ')'}";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- // UDF attribute should be STRING_LITERAL
- statement.executeQuery("select bottom_k(s1,``k` = 1) from root.vehicle.d1");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- @Test
- public void testCreateTimeSeriesAttribute() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- // besides datatype,encoding,compression,compressor, attributes in create time series clause
- // should be STRING_LITERAL
- statement.execute(
- "create timeseries root.vehicle.d1.s1 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY");
- statement.execute(
- "create timeseries root.vehicle.d1.s2 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY, max_point_number = 5");
- statement.execute(
- "create timeseries root.vehicle.d1.s3 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY, 'max_point_number' = '5'");
- statement.execute(
- "create timeseries root.vehicle.d1.s4 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY, max_point_number = '5'");
- statement.execute(
- "create timeseries root.vehicle.d1.s5 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY, `max_point_number` = 5");
- statement.execute(
- "create timeseries root.vehicle.d1.s6 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY, `max_point_number` = `5`");
- ResultSet resultSet = statement.executeQuery("show timeseries");
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(6, cnt);
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testCreateTimeSeriesTags() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.vehicle.d1.s1 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(tag1=v1)");
- statement.execute(
- "create timeseries root.vehicle.d1.s2 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(`tag1`=v1)");
- statement.execute(
- "create timeseries root.vehicle.d1.s3 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags('tag1'=v1)");
- statement.execute(
- "create timeseries root.vehicle.d1.s4 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(\"tag1\"=v1)");
- statement.execute(
- "create timeseries root.vehicle.d1.s5 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(tag1=`v1`)");
- statement.execute(
- "create timeseries root.vehicle.d1.s6 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(tag1='v1')");
- statement.execute(
- "create timeseries root.vehicle.d1.s7 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(tag1=\"v1\")");
- statement.execute(
- "create timeseries root.vehicle.d1.s8 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "tags(tag1=v1)");
- boolean hasResult = statement.execute("show timeseries");
- Assert.assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(8, cnt);
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testCreateTimeSeriesAttributeClause() {
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.vehicle.d1.s1 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "attributes('attr1'='v1', 'attr2'='v2')");
- statement.execute(
- "create timeseries root.vehicle.d1.s2 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "attributes(attr1=v1, attr2=v2)");
- statement.execute(
- "create timeseries root.vehicle.d1.s3 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "attributes(`attr1`=`v1`, `attr2`=v2)");
- statement.execute(
- "create timeseries root.vehicle.d1.s4 "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY "
- + "attributes('attr1'=v1, attr2=v2)");
- ResultSet resultSet = statement.executeQuery("show timeseries");
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(4, cnt);
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testPipeSinkAttribute() {
- String errorMsg =
- "401: Error occurred while parsing SQL to physical plan: "
- + "line 1:40 token recognition error at: '` = '127.0.0.1')'";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("CREATE PIPESINK `test.*1` AS IoTDB (``ip` = '127.0.0.1')");
- fail();
- } catch (SQLException e) {
- Assert.assertEquals(errorMsg, e.getMessage());
- }
- }
-
- // alias can be identifier or STRING_LITERAL
- @Test
- public void testAliasInResultColumn() {
- String[] alias = {
- "b", "test", "`test.1`", "`1``1`", "'test'", "\"test\"", "\"\\\\test\"",
- };
-
- String[] res = {
- "b", "test", "test.1", "1`1", "test", "test", "\\\\test",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.sg.a "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY ");
- statement.execute("insert into root.sg(time, a) values (1,1)");
-
- String selectSql = "select a as %s from root.sg";
- for (int i = 0; i < alias.length; i++) {
- boolean hasResult = statement.execute(String.format(selectSql, alias[i]));
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- Assert.assertEquals(res[i], resultSet.getMetaData().getColumnName(2));
- }
-
- try {
- statement.execute("select a as test.b from root.sg");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void testAliasInAlterClause() {
- String[] alias = {
- "b", "test", "`test.1`", "`1``1`", "'test'", "\"test\"", "\"\\\\test\"",
- };
-
- String[] res = {
- "b", "test", "test.1", "1`1", "test", "test", "\\\\test",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.sg.a "
- + "with datatype=INT64, encoding=PLAIN, compression=SNAPPY ");
-
- String alterSql = "ALTER timeseries root.sg.a UPSERT alias = %s";
- for (int i = 0; i < alias.length; i++) {
- statement.execute(String.format(alterSql, alias[i]));
- statement.execute("show timeseries");
- ResultSet resultSet = statement.getResultSet();
- resultSet.next();
- Assert.assertEquals(res[i], resultSet.getString("alias"));
- }
-
- try {
- statement.execute("ALTER timeseries root.sg.a UPSERT alias = test.a");
- fail();
- } catch (Exception ignored) {
- }
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java
deleted file mode 100644
index 4bee6635c8..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagAlterIT.java
+++ /dev/null
@@ -1,625 +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.integration;
-
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.ClusterTest;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.itbase.category.RemoteTest;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class, ClusterTest.class, RemoteTest.class})
-public class IoTDBTagAlterIT {
-
- @Before
- public void setUp() throws InterruptedException {
- EnvFactory.getEnv().initBeforeTest();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- }
-
- @Test
- public void renameTest() {
- String[] ret1 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag2\":\"v2\",\"tagNew1\":\"v1\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT,"
- + " encoding=RLE, compression=SNAPPY tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret1[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret1.length, count);
-
- try {
- statement.execute("ALTER timeseries root.turbine.d1.s1 RENAME tag3 TO 'tagNew3'");
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains("TimeSeries [root.turbine.d1.s1] does not have tag/attribute [tag3]."));
- }
-
- try {
- statement.execute("ALTER timeseries root.turbine.d1.s1 RENAME 'tag1' TO 'tag2'");
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains(
- "TimeSeries [root.turbine.d1.s1] already has a tag/attribute named [tag2]."));
- }
-
- statement.execute("ALTER timeseries root.turbine.d1.s1 RENAME 'tag1' TO 'tagNew1'");
- hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void setTest() {
- String[] ret = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"newV1\",\"tag2\":\"v2\"},{\"attr2\":\"newV2\",\"attr1\":\"v1\"}"
- };
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.length, count);
-
- try {
- statement.execute("ALTER timeseries root.turbine.d1.s1 SET 'tag3'='v3'");
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains("TimeSeries [root.turbine.d1.s1] does not have tag/attribute [tag3]."));
- }
-
- statement.execute("ALTER timeseries root.turbine.d1.s1 SET 'tag1'='newV1', 'attr2'='newV2'");
- hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void dropTest() {
- String[] ret = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"tag2\":\"v2\"},{\"attr2\":\"v2\"}"
- };
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.length, count);
-
- statement.execute("ALTER timeseries root.turbine.d1.s1 DROP attr1,'tag1'");
- hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
-
- try (ResultSet rs = statement.executeQuery("show timeseries where 'tag1'='v1'")) {
- assertFalse(rs.next());
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void addTagTest() {
- String[] ret = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag4\":\"v4\",\"tag2\":\"v2\",\"tag3\":\"v3\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.length, count);
-
- statement.execute("ALTER timeseries root.turbine.d1.s1 ADD TAGS 'tag3'='v3', 'tag4'='v4'");
- hasResult = statement.execute("show timeseries where 'tag3'='v3'");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void addAttributeTest() {
- String[] ret = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\",\"attr4\":\"v4\",\"attr3\":\"v3\"}"
- };
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.length, count);
-
- statement.execute(
- "ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES 'attr3'='v3', 'attr4'='v4'");
- hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void upsertTest() {
- String[] ret = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret2 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"tag1\":\"v1\",\"tag2\":\""
- + "newV2\",\"tag3\":\"v3\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}"
- };
- String[] ret3 = {
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"tag1\":\"newV1\",\"tag2\":\""
- + "newV2\",\"tag3\":\"newV3\"},{\"attr2\":\"v2\",\"attr1\":\"newA1\",\"attr3\":\"v3\"}"
- };
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.length, count);
-
- statement.execute(
- "ALTER timeseries root.turbine.d1.s1 UPSERT TAGS('tag3'='v3', 'tag2'='newV2')");
- hasResult = statement.execute("show timeseries where 'tag3'='v3'");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret2[count], ans);
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret2.length, count);
-
- statement.execute(
- "ALTER timeseries root.turbine.d1.s1 UPSERT TAGS('tag1'='newV1', 'tag3'='newV3') "
- + "ATTRIBUTES('attr1'='newA1', 'attr3'='v3')");
- hasResult = statement.execute("show timeseries where 'tag3'='newV3'");
- assertTrue(hasResult);
- resultSet = statement.getResultSet();
- count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertEquals(ret3[count], ans);
- count++;
- }
- assertEquals(ret3.length, count);
-
- statement.execute("show timeseries where 'tag3'='v3'");
- resultSet = statement.getResultSet();
- assertFalse(resultSet.next());
- } finally {
- resultSet.close();
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
index 7ff6f085ba..14a1df0d8f 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/IoTDBTagIT.java
@@ -38,7 +38,6 @@ import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -55,344 +54,6 @@ public class IoTDBTagIT {
EnvFactory.getEnv().cleanAfterTest();
}
- @Test
- public void createOneTimeseriesTest() {
- List<String> ret =
- Collections.singletonList(
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}");
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertTrue(ret.contains(ans));
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void createMultiTimeseriesTest() {
- List<String> ret =
- Arrays.asList(
- "root.turbine.d2.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"tag1\":\"t1\","
- + "\"tag2\":\"t2\"},{\"attr2\":\"a2\",\"attr1\":\"a1\"}",
- "root.turbine.d2.s2,status,root.turbine,INT32,RLE,SNAPPY,{\"tag2\":\"t2\","
- + "\"tag3\":\"t3\"},{\"attr4\":\"a4\",\"attr3\":\"a3\"}");
- String sql1 =
- "create timeseries root.turbine.d2.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='t1', 'tag2'='t2') "
- + "attributes('attr1'='a1', 'attr2'='a2')";
- String sql2 =
- "create timeseries root.turbine.d2.s2(status) with datatype=INT32, encoding=RLE "
- + "tags('tag2'='t2', 'tag3'='t3') "
- + "attributes('attr3'='a3', 'attr4'='a4')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql1);
- statement.execute(sql2);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- assertTrue(ret.contains(ans));
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void showTimeseriesTest() {
- List<String> ret =
- Arrays.asList(
- "root.turbine.d2.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"tag1\":\"t1\",\""
- + "tag2\":\"t2\"},{\"attr2\":\"a2\",\"attr1\":\"a1\"}",
- "root.turbine.d2.s2,status,root.turbine,INT32,RLE,SNAPPY,{\"tag2\":\"t2\",\"tag3\""
- + ":\"t3\"},{\"attr4\":\"a4\",\"attr3\":\"a3\"}");
- String sql1 =
- "create timeseries root.turbine.d2.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='t1', 'tag2'='t2') "
- + "attributes('attr1'='a1', 'attr2'='a2')";
- String sql2 =
- "create timeseries root.turbine.d2.s2(status) with datatype=INT32, encoding=RLE "
- + "tags('tag2'='t2', 'tag3'='t3') "
- + "attributes('attr3'='a3', 'attr4'='a4')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql1);
- statement.execute(sql2);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- ResultSet resultSet = statement.getResultSet();
- int count = 0;
- try {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertTrue(ret.contains(ans));
- count++;
- }
- } finally {
- resultSet.close();
- }
- assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void createDuplicateAliasTimeseriesTest1() {
- String sql1 =
- "create timeseries root.turbine.d3.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='t1', 'tag2'='t2') "
- + "attributes('attr1'='a1', 'attr2'='a2')";
- String sql2 =
- "create timeseries root.turbine.d3.s2(temperature) with datatype=INT32, encoding=RLE "
- + "tags('tag2'='t2', 'tag3'='t3') "
- + "attributes('attr3'='a3', 'attr4'='a4')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql1);
- try {
- statement.execute(sql2);
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage()
- .contains("Alias [temperature] for Path [root.turbine.d3.s2] already exist"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void createDuplicateAliasTimeseriesTest2() {
- String sql1 =
- "create timeseries root.turbine.d4.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='t1', 'tag2'='t2') "
- + "attributes('attr1'='a1', 'attr2'='a2')";
- String sql2 =
- "create timeseries root.turbine.d4.temperature with datatype=INT32, encoding=RLE "
- + "tags('tag2'='t2', 'tag3'='t3') "
- + "attributes('attr3'='a3', 'attr4'='a4')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql1);
- try {
- statement.execute(sql2);
- fail();
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("Path [root.turbine.d4.temperature] already exist"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void createDuplicateAliasTimeseriesTest3() {
- String sql1 =
- "create timeseries root.turbine.d5.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='t1', 'tag2'='t2') "
- + "attributes('attr1'='a1', 'attr2'='a2')";
- String sql2 =
- "create timeseries root.turbine.d5.s2(s1) with datatype=INT32, encoding=RLE "
- + "tags('tag2'='t2', 'tag3'='t3') "
- + "attributes('attr3'='a3', 'attr4'='a4')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql1);
- try {
- statement.execute(sql2);
- fail();
- } catch (Exception e) {
- assertTrue(
- e.getMessage().contains("Alias [s1] for Path [root.turbine.d5.s2] already exist"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void queryWithAliasTest() {
- List<String> ret =
- Collections.singletonList(
- "root.turbine.d6.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}");
- String sql =
- "create timeseries root.turbine.d6.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries root.turbine.d6.temperature");
- assertTrue(hasResult);
- int count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertTrue(ret.contains(ans));
- count++;
- }
- }
- assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void queryWithLimitTest() {
- List<String> ret =
- Arrays.asList(
- "root.turbine.d1.s2,temperature2,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}",
- "root.turbine.d1.s3,temperature3,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}");
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "create timeseries root.turbine.d1.s1(temperature1) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')");
- statement.execute(
- "create timeseries root.turbine.d1.s2(temperature2) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')");
- statement.execute(
- "create timeseries root.turbine.d1.s3(temperature3) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')");
- boolean hasResult =
- statement.execute(
- "show timeseries root.turbine.d1.** where 'tag1'='v1' limit 2 offset 1");
- assertTrue(hasResult);
- int count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertTrue(ret.contains(ans));
- count++;
- }
- }
- assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
@Test
public void deleteTest() {
List<String> ret1 =
@@ -568,35 +229,14 @@ public class IoTDBTagIT {
}
@Test
- public void queryWithWhereTest1() {
- List<String> ret1 =
- Arrays.asList(
- "root.turbine.d0.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "this is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"100\",\"M_Alarm\":\"50\"}",
- "root.turbine.d0.s1,power,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine this "
- + "is a test2\",\"unit\":\"kw\"},{\"H_Alarm\":\"99.9\",\"M_Alarm\":\"44.4\"}",
- "root.turbine.d1.s0,status,root.turbine,INT32,RLE,SNAPPY,{\"description\":\"turbine this "
- + "is a test3\"},{\"H_Alarm\":\"9\",\"M_Alarm\":\"5\"}",
- "root.turbine.d2.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "d2 this is a test1\",\"unit\":\"f\"},{\"MinValue\":\"1\",\"MaxValue\":\"100\"}",
- "root.turbine.d2.s1,power,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine d2 this"
- + " is a test2\",\"unit\":\"kw\"},{\"MinValue\":\"44.4\",\"MaxValue\":\"99.9\"}",
- "root.turbine.d2.s3,status,root.turbine,INT32,RLE,SNAPPY,{\"description\":\"turbine d2 "
- + "this is a test3\"},{\"MinValue\":\"5\",\"MaxValue\":\"9\"}",
- "root.ln.d0.s0,temperature,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this is a "
- + "test1\",\"unit\":\"c\"},{\"H_Alarm\":\"1000\",\"M_Alarm\":\"500\"}",
- "root.ln.d0.s1,power,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this is a "
- + "test2\",\"unit\":\"w\"},{\"H_Alarm\":\"9.9\",\"M_Alarm\":\"4.4\"}",
- "root.ln.d1.s0,status,root.ln,INT32,RLE,SNAPPY,{\"description\":\"ln this is a test3\"},"
- + "{\"H_Alarm\":\"90\",\"M_Alarm\":\"50\"}");
-
- Set<String> ret2 = new HashSet<>();
- ret2.add(
- "root.turbine.d2.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "d2 this is a test1\",\"unit\":\"f\"},{\"MinValue\":\"1\",\"MaxValue\":\"100\"}");
- ret2.add(
+ public void queryWithWhereAndDeleteTest() {
+ Set<String> ret = new HashSet<>();
+ ret.add(
"root.turbine.d0.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\""
+ "turbine this is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"100\",\"M_Alarm\":\"50\"}");
+ ret.add(
+ "root.ln.d0.s0,temperature,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this "
+ + "is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"1000\",\"M_Alarm\":\"500\"}");
String[] sqls = {
"create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
@@ -618,7 +258,7 @@ public class IoTDBTagIT {
+ "tags('description'='turbine d2 this is a test3') "
+ "attributes('MaxValue'='9', 'MinValue'='5')",
"create timeseries root.ln.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='c', 'description'='ln this is a test1') "
+ + "tags('unit'='f', 'description'='ln this is a test1') "
+ "attributes('H_Alarm'='1000', 'M_Alarm'='500')",
"create timeseries root.ln.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
+ "tags('unit'='w', 'description'='ln this is a test2') "
@@ -632,117 +272,14 @@ public class IoTDBTagIT {
for (String sql : sqls) {
statement.execute(sql);
}
- boolean hasResult = statement.execute("show timeseries");
+
+ statement.execute("delete timeseries root.turbine.d2.s0");
+
+ // with *
+ boolean hasResult = statement.execute("show timeseries where 'unit'='f'");
assertTrue(hasResult);
int count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- assertTrue(ret1.contains(ans));
- count++;
- }
- assertEquals(ret1.size(), count);
- }
- hasResult = statement.execute("show timeseries where 'unit'='f'");
- assertTrue(hasResult);
- count = 0;
- Set<String> res = new HashSet<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- res.add(ans);
- count++;
- }
- assertEquals(ret2, res);
- assertEquals(ret2.size(), count);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void queryWithWhereTest2() {
- Set<String> ret = new HashSet<>();
- ret.add(
- "root.turbine.d2.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "d2 this is a test1\",\"unit\":\"f\"},{\"MinValue\":\"1\",\"MaxValue\":\"100\"}");
- ret.add(
- "root.turbine.d0.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "this is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"100\",\"M_Alarm\":\"50\"}");
-
- String[] sqls = {
- "create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine this is a test1') "
- + "attributes('H_Alarm'='100', 'M_Alarm'='50')",
- "create timeseries root.turbine.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine this is a test2') "
- + "attributes('H_Alarm'='99.9', 'M_Alarm'='44.4')",
- "create timeseries root.turbine.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine this is a test3') "
- + "attributes('H_Alarm'='9', 'M_Alarm'='5')",
- "create timeseries root.turbine.d2.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine d2 this is a test1') "
- + "attributes('MaxValue'='100', 'MinValue'='1')",
- "create timeseries root.turbine.d2.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine d2 this is a test2') "
- + "attributes('MaxValue'='99.9', 'MinValue'='44.4')",
- "create timeseries root.turbine.d2.s3(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine d2 this is a test3') "
- + "attributes('MaxValue'='9', 'MinValue'='5')",
- "create timeseries root.ln.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='ln this is a test1') "
- + "attributes('H_Alarm'='1000', 'M_Alarm'='500')",
- "create timeseries root.ln.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='w', 'description'='ln this is a test2') "
- + "attributes('H_Alarm'='9.9', 'M_Alarm'='4.4')",
- "create timeseries root.ln.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='ln this is a test3') "
- + "attributes('H_Alarm'='90', 'M_Alarm'='50')",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String sql : sqls) {
- statement.execute(sql);
- }
-
- // with *
- boolean hasResult = statement.execute("show timeseries root.turbine.** where 'unit'='f'");
- assertTrue(hasResult);
- int count = 0;
- Set<String> res = new HashSet<>();
+ Set<String> res = new HashSet<>();
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ans =
@@ -769,407 +306,9 @@ public class IoTDBTagIT {
assertEquals(ret, res);
assertEquals(ret.size(), count);
- // no *
- hasResult = statement.execute("show timeseries root.turbine.** where 'unit'='f'");
- assertTrue(hasResult);
- count = 0;
- res.clear();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- res.add(ans);
- count++;
- }
- assertEquals(ret, res);
- assertEquals(ret.size(), count);
- }
-
- statement.execute("show timeseries root.turbine where 'unit'='c'");
- count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- count++;
- }
- assertEquals(0, count);
- }
-
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
-
- @Test
- public void queryWithWhereAndDeleteTest() {
- Set<String> ret = new HashSet<>();
- ret.add(
- "root.turbine.d0.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\""
- + "turbine this is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"100\",\"M_Alarm\":\"50\"}");
- ret.add(
- "root.ln.d0.s0,temperature,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this "
- + "is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"1000\",\"M_Alarm\":\"500\"}");
-
- String[] sqls = {
- "create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine this is a test1') "
- + "attributes('H_Alarm'='100', 'M_Alarm'='50')",
- "create timeseries root.turbine.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine this is a test2') "
- + "attributes('H_Alarm'='99.9', 'M_Alarm'='44.4')",
- "create timeseries root.turbine.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine this is a test3') "
- + "attributes('H_Alarm'='9', 'M_Alarm'='5')",
- "create timeseries root.turbine.d2.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine d2 this is a test1') "
- + "attributes('MaxValue'='100', 'MinValue'='1')",
- "create timeseries root.turbine.d2.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine d2 this is a test2') "
- + "attributes('MaxValue'='99.9', 'MinValue'='44.4')",
- "create timeseries root.turbine.d2.s3(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine d2 this is a test3') "
- + "attributes('MaxValue'='9', 'MinValue'='5')",
- "create timeseries root.ln.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='ln this is a test1') "
- + "attributes('H_Alarm'='1000', 'M_Alarm'='500')",
- "create timeseries root.ln.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='w', 'description'='ln this is a test2') "
- + "attributes('H_Alarm'='9.9', 'M_Alarm'='4.4')",
- "create timeseries root.ln.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='ln this is a test3') "
- + "attributes('H_Alarm'='90', 'M_Alarm'='50')",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String sql : sqls) {
- statement.execute(sql);
- }
-
- statement.execute("delete timeseries root.turbine.d2.s0");
-
- // with *
- boolean hasResult = statement.execute("show timeseries where 'unit'='f'");
- assertTrue(hasResult);
- int count = 0;
- Set<String> res = new HashSet<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- res.add(ans);
- count++;
- }
- }
- assertEquals(ret, res);
- assertEquals(ret.size(), count);
-
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void queryWithWhereContainsTest() {
- Set<String> ret = new HashSet<>();
- ret.add(
- "root.turbine.d2.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "d2 this is a test1\",\"unit\":\"f\"},{\"MinValue\":\"1\",\"MaxValue\":\"100\"}");
- ret.add(
- "root.turbine.d0.s0,temperature,root.turbine,FLOAT,RLE,SNAPPY,{\"description\":\"turbine "
- + "this is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"100\",\"M_Alarm\":\"50\"}");
- ret.add(
- "root.ln.d0.s0,temperature,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this "
- + "is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"1000\",\"M_Alarm\":\"500\"}");
-
- Set<String> ret2 = new HashSet<>();
- ret2.add(
- "root.ln.d0.s0,temperature,root.ln,FLOAT,RLE,SNAPPY,{\"description\":\"ln this"
- + " is a test1\",\"unit\":\"f\"},{\"H_Alarm\":\"1000\",\"M_Alarm\":\"500\"}");
-
- String[] sqls = {
- "create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine this is a test1') "
- + "attributes('H_Alarm'='100', 'M_Alarm'='50')",
- "create timeseries root.turbine.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine this is a test2') "
- + "attributes('H_Alarm'='99.9', 'M_Alarm'='44.4')",
- "create timeseries root.turbine.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine this is a test3') "
- + "attributes('H_Alarm'='9', 'M_Alarm'='5')",
- "create timeseries root.turbine.d2.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine d2 this is a test1') "
- + "attributes('MaxValue'='100', 'MinValue'='1')",
- "create timeseries root.turbine.d2.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine d2 this is a test2') "
- + "attributes('MaxValue'='99.9', 'MinValue'='44.4')",
- "create timeseries root.turbine.d2.s3(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine d2 this is a test3') "
- + "attributes('MaxValue'='9', 'MinValue'='5')",
- "create timeseries root.ln.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='ln this is a test1') "
- + "attributes('H_Alarm'='1000', 'M_Alarm'='500')",
- "create timeseries root.ln.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='w', 'description'='ln this is a test2') "
- + "attributes('H_Alarm'='9.9', 'M_Alarm'='4.4')",
- "create timeseries root.ln.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='ln this is a test3') "
- + "attributes('H_Alarm'='90', 'M_Alarm'='50')",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String sql : sqls) {
- statement.execute(sql);
- }
-
- boolean hasResult = statement.execute("show timeseries where 'description' contains 'test1'");
- assertTrue(hasResult);
- int count = 0;
- Set<String> res = new HashSet<>();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- System.out.println(ans);
- res.add(ans);
- count++;
- }
- }
- assertEquals(ret, res);
- assertEquals(ret.size(), count);
-
- hasResult =
- statement.execute("show timeseries root.ln.** where 'description' contains 'test1'");
- assertTrue(hasResult);
- count = 0;
- res.clear();
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
-
- res.add(ans);
- count++;
- }
- }
- assertEquals(ret2, res);
- assertEquals(ret2.size(), count);
-
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void queryWithWhereOnNoneTagTest() {
- String[] sqls = {
- "create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine this is a test1') "
- + "attributes('H_Alarm'='100', 'M_Alarm'='50')",
- "create timeseries root.turbine.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine this is a test2') "
- + "attributes('H_Alarm'='99.9', 'M_Alarm'='44.4')",
- "create timeseries root.turbine.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine this is a test3') "
- + "attributes('H_Alarm'='9', 'M_Alarm'='5')",
- "create timeseries root.turbine.d2.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='f', 'description'='turbine d2 this is a test1') "
- + "attributes('MaxValue'='100', 'MinValue'='1')",
- "create timeseries root.turbine.d2.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='kw', 'description'='turbine d2 this is a test2') "
- + "attributes('MaxValue'='99.9', 'MinValue'='44.4')",
- "create timeseries root.turbine.d2.s3(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='turbine d2 this is a test3') "
- + "attributes('MaxValue'='9', 'MinValue'='5')",
- "create timeseries root.ln.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='c', 'description'='ln this is a test1') "
- + "attributes('H_Alarm'='1000', 'M_Alarm'='500')",
- "create timeseries root.ln.d0.s1(power) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('unit'='w', 'description'='ln this is a test2') "
- + "attributes('H_Alarm'='9.9', 'M_Alarm'='4.4')",
- "create timeseries root.ln.d1.s0(status) with datatype=INT32, encoding=RLE "
- + "tags('description'='ln this is a test3') "
- + "attributes('H_Alarm'='90', 'M_Alarm'='50')",
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String sql : sqls) {
- statement.execute(sql);
- }
-
- try (ResultSet rs = statement.executeQuery("show timeseries where 'H_Alarm'='90'")) {
- assertFalse(rs.next());
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void sameNameTest() {
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('tag1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- fail();
- } catch (Exception e) {
- assertTrue(e.getMessage().contains("Tag and attribute shouldn't have the same property key"));
- }
- }
-
- @Test
- public void deleteStorageGroupTest() {
- List<String> ret =
- Collections.singletonList(
- "root.turbine.d1.s1,temperature,root.turbine,FLOAT,RLE,SNAPPY,"
- + "{\"tag1\":\"v1\",\"tag2\":\"v2\"},{\"attr2\":\"v2\",\"attr1\":\"v1\"}");
-
- String sql =
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY "
- + "tags('tag1'='v1', 'tag2'='v2') "
- + "attributes('attr1'='v1', 'attr2'='v2')";
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(sql);
- boolean hasResult = statement.execute("show timeseries");
- assertTrue(hasResult);
- int count = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString("timeseries")
- + ","
- + resultSet.getString("alias")
- + ","
- + resultSet.getString("storage group")
- + ","
- + resultSet.getString("dataType")
- + ","
- + resultSet.getString("encoding")
- + ","
- + resultSet.getString("compression")
- + ","
- + resultSet.getString("tags")
- + ","
- + resultSet.getString("attributes");
- assertTrue(ret.contains(ans));
- count++;
- }
- }
- assertEquals(ret.size(), count);
-
- statement.execute("delete storage group root.turbine");
- try (ResultSet rs = statement.executeQuery("show timeseries where 'tag1'='v1'")) {
- assertFalse(rs.next());
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
-
- @Test
- public void insertWithAliasTest() {
- List<String> ret = Collections.singletonList("1,36.5,36.5");
- String[] sqls = {
- "create timeseries root.turbine.d1.s1(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY",
- "insert into root.turbine.d1(timestamp, temperature) values(1,36.5)"
- };
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- for (String sql : sqls) {
- statement.execute(sql);
- }
- boolean hasResult = statement.execute("select s1, temperature from root.turbine.d1");
- assertTrue(hasResult);
- // FIXME should use the same reader for measurement and its alias
-
- // ResultSet resultSet = statement.getResultSet();
- // int count = 0;
- // try {
- // while (resultSet.next()) {
- // String ans =
- // resultSet.getString("Time")
- // + ","
- // + resultSet.getString("root.turbine.d1.s1")
- // + ","
- // + resultSet.getString("root.turbine.d1.s1");
- // assertTrue(ret.contains(ans));
- // count++;
- // }
- // } finally {
- // resultSet.close();
- // }
- // assertEquals(ret.size(), count);
- } catch (Exception e) {
- e.printStackTrace();
- assertEquals(
- "411: Error occurred in query process: Query for measurement and its alias at the same time!",
- e.getMessage());
- }
- }
}
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java
deleted file mode 100644
index b9474d546a..0000000000
--- a/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java
+++ /dev/null
@@ -1,554 +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.integration.aligned;
-
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.integration.env.ConfigFactory;
-import org.apache.iotdb.integration.env.EnvFactory;
-import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Locale;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-@Category({LocalStandaloneTest.class})
-public class IoTDBDeletionIT {
-
- private static String[] creationSqls =
- new String[] {
- "SET STORAGE GROUP TO root.vehicle",
- "CREATE ALIGNED TIMESERIES root.vehicle.d0(s0 INT32 ENCODING=RLE, s1 INT64 ENCODING=RLE, s2 FLOAT ENCODING=RLE, s3 TEXT ENCODING=PLAIN, s4 BOOLEAN ENCODING=PLAIN)",
- };
-
- private String insertTemplate =
- "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4"
- + ") ALIGNED VALUES(%d,%d,%d,%f,%s,%b)";
- private String deleteAllTemplate = "DELETE FROM root.vehicle.d0 WHERE time <= 10000";
- private long prevPartitionInterval;
-
- @Before
- public void setUp() throws Exception {
- Locale.setDefault(Locale.ENGLISH);
- prevPartitionInterval = IoTDBDescriptor.getInstance().getConfig().getPartitionInterval();
- ConfigFactory.getConfig().setPartitionInterval(1000);
- EnvFactory.getEnv().initBeforeTest();
- prepareSeries();
- }
-
- @After
- public void tearDown() throws Exception {
- EnvFactory.getEnv().cleanAfterTest();
- ConfigFactory.getConfig().setPartitionInterval(prevPartitionInterval);
- }
-
- /**
- * Should delete this case after the deletion value filter feature be implemented
- *
- * @throws SQLException
- */
- @Test
- public void testUnsupportedValueFilter() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("insert into root.vehicle.d0(time,s0) aligned values (10,310)");
- statement.execute("insert into root.vehicle.d0(time,s3) aligned values (10,'text')");
- statement.execute("insert into root.vehicle.d0(time,s4) aligned values (10,true)");
-
- String errorMsg =
- "416: For delete statement, where clause can only"
- + " contain time expressions, value filter is not currently supported.";
-
- String errorMsg2 =
- "416: For delete statement, where clause can only contain"
- + " atomic expressions like : time > XXX, time <= XXX,"
- + " or two atomic expressions connected by 'AND'";
-
- try {
- statement.execute(
- "DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND time > 0 AND time < 100");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg2, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE s0 <= 300 AND s0 > 0");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s3 WHERE s3 = 'text'");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try {
- statement.execute("DELETE FROM root.vehicle.d0.s4 WHERE s4 != true");
- fail("should not reach here!");
- } catch (SQLException e) {
- assertEquals(errorMsg, e.getMessage());
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s3 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s4 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(1, cnt);
- }
- }
- }
-
- @Test
- public void test() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time <= 300");
- statement.execute(
- "DELETE FROM root.vehicle.d0.s1,root.vehicle.d0.s2,root.vehicle.d0.s3"
- + " WHERE time <= 350");
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time <= 150");
-
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(250, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(100, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s1,s2,s3 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(50, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- public void testMerge() throws SQLException {
- prepareMerge();
-
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("merge");
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time <= 15000");
-
- // before merge completes
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(5000, cnt);
- }
-
- // after merge completes
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(5000, cnt);
- }
- cleanData();
- }
- }
-
- @Test
- public void testDelAfterFlush() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SET STORAGE GROUP TO root.ln.wf01.wt01");
- statement.execute(
- "CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN," + " ENCODING=PLAIN");
- statement.execute(
- "INSERT INTO root.ln.wf01.wt01(timestamp,status) " + "values(1509465600000,true)");
- statement.execute("INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)");
-
- statement.execute("delete from root.ln.wf01.wt01.status where time <= NOW()");
- statement.execute("flush");
- statement.execute("delete from root.ln.wf01.wt01.status where time <= NOW()");
-
- try (ResultSet resultSet = statement.executeQuery("select status from root.ln.wf01.wt01")) {
- assertFalse(resultSet.next());
- }
- }
- }
-
- @Test
- public void testRangeDelete() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time <= 300");
- statement.execute("DELETE FROM root.vehicle.d0.s1 WHERE time > 150");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(100, cnt);
- }
-
- try (ResultSet set = statement.executeQuery("SELECT s1 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(150, cnt);
- }
-
- statement.execute("DELETE FROM root.vehicle.d0.** WHERE time > 50 and time <= 250");
- try (ResultSet set = statement.executeQuery("SELECT * FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(200, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- public void testFullDeleteWithoutWhereClause() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("DELETE FROM root.vehicle.d0.s0");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(0, cnt);
- }
- cleanData();
- }
- }
-
- @Test
- public void testPartialPathRangeDelete() throws SQLException {
- prepareData();
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- statement.execute("DELETE FROM root.vehicle.d0.* WHERE time <= 300 and time > 150");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(250, cnt);
- }
-
- statement.execute("DELETE FROM root.vehicle.*.s0 WHERE time <= 100");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(150, cnt);
- }
- }
- cleanData();
- }
-
- @Test
- public void testDelFlushingMemtable() throws SQLException {
- long size = IoTDBDescriptor.getInstance().getConfig().getMemtableSizeThreshold();
- // Adjust memstable threshold size to make it flush automatically
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(10000);
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (int i = 1; i <= 10000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 1500 and time <= 9000");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(2500, cnt);
- }
- cleanData();
- }
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(size);
- }
-
- @Test
- public void testDelMultipleFlushingMemtable() throws SQLException {
- long size = IoTDBDescriptor.getInstance().getConfig().getMemtableSizeThreshold();
- // Adjust memstable threshold size to make it flush automatically
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(1000000);
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (int i = 1; i <= 100000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 15000 and time <= 30000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 30000 and time <= 40000");
- for (int i = 100001; i <= 200000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 50000 and time <= 80000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 90000 and time <= 110000");
- statement.execute("DELETE FROM root.vehicle.d0.s0 WHERE time > 150000 and time <= 165000");
- statement.execute("flush");
- try (ResultSet set = statement.executeQuery("SELECT s0 FROM root.vehicle.d0")) {
- int cnt = 0;
- while (set.next()) {
- cnt++;
- }
- assertEquals(110000, cnt);
- }
- cleanData();
- }
- IoTDBDescriptor.getInstance().getConfig().setMemtableSizeThreshold(size);
- }
-
- @Test
- public void testDelSeriesWithSpecialSymbol() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "CREATE TIMESERIES root.ln.d1.`status,01` WITH DATATYPE=BOOLEAN, ENCODING=PLAIN");
- statement.execute("INSERT INTO root.ln.d1(timestamp,`status,01`) VALUES(300, true)");
- statement.execute("INSERT INTO root.ln.d1(timestamp,`status,01`) VALUES(500, false)");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
- statement.execute("DELETE FROM root.ln.d1.`status,01` WHERE time <= 400");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
-
- statement.execute("DELETE FROM root.ln.d1.`status,01`");
-
- try (ResultSet resultSet = statement.executeQuery("select `status,01` from root.ln.d1")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(0, cnt);
- }
- }
- }
-
- @Test
- public void testInsertDuplicatedTimeThenDel() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)");
- statement.execute(
- "insert into root.lz.dev.GPS(time, latitude, longitude) aligned values(9,3.2,9.8)");
- statement.execute("insert into root.lz.dev.GPS(time, latitude) aligned values(11,4.5)");
- statement.execute("insert into root.lz.dev.GPS(time, longitude) aligned values(11,6.7)");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
- statement.execute("delete from root.lz.dev.GPS.latitude");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
- }
- }
-
- @Test
- public void testDeleteAll() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(
- "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)");
- statement.execute(
- "insert into root.lz.dev.GPS(time, latitude, longitude) aligned values(9,3.2,9.8)");
- statement.execute("insert into root.lz.dev.GPS(time, latitude) aligned values(11,4.5)");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
- statement.execute("delete from root.lz.**");
-
- try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) {
- int cnt = 0;
- while (resultSet.next()) {
- cnt++;
- }
- Assert.assertEquals(0, cnt);
- }
- statement.execute("flush");
- }
- }
-
- private static void prepareSeries() {
- String sq = null;
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- for (String sql : creationSqls) {
- sq = sql;
- statement.execute(sql);
- }
- } catch (Exception e) {
- System.out.println(sq);
- e.printStackTrace();
- }
- }
-
- private void prepareData() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- // prepare BufferWrite file
- for (int i = 201; i <= 300; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- // TODO: merge
- // statement.execute("merge");
- // prepare Unseq-File
- for (int i = 1; i <= 100; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- // TODO: merge
- // statement.execute("merge");
- // prepare BufferWrite cache
- for (int i = 301; i <= 400; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- // prepare Overflow cache
- for (int i = 101; i <= 200; i++) {
- statement.execute(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- }
- }
-
- private void cleanData() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute(deleteAllTemplate);
- }
- }
-
- public void prepareMerge() throws SQLException {
- try (Connection connection = EnvFactory.getEnv().getConnection();
- Statement statement = connection.createStatement()) {
-
- // prepare BufferWrite data
- for (int i = 10001; i <= 20000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- // prepare Overflow data
- for (int i = 1; i <= 10000; i++) {
- statement.addBatch(
- String.format(insertTemplate, i, i, i, (double) i, "'" + i + "'", i % 2 == 0));
- }
- statement.executeBatch();
- }
- }
-}