You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/12/17 11:49:35 UTC
[iotdb] branch master updated: Arrange query test (#2245)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin 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 07a7689 Arrange query test (#2245)
07a7689 is described below
commit 07a7689177f01702d128ef0a6670a516e74d2926
Author: Xiangwei Wei <34...@users.noreply.github.com>
AuthorDate: Thu Dec 17 19:49:23 2020 +0800
Arrange query test (#2245)
---
.../iotdb/db/query/control/TracingManager.java | 2 +-
.../apache/iotdb/db/engine/merge/MergeTest.java | 2 +-
.../iotdb/db/integration/IoTDBAddSubDeviceIT.java | 15 +-
.../iotdb/db/integration/IoTDBAlignByDeviceIT.java | 31 +--
.../org/apache/iotdb/db/integration/IoTDBAsIT.java | 10 +
.../db/integration/IoTDBAutoCreateSchemaIT.java | 19 +-
.../IoTDBAggregationByLevelIT.java | 9 +-
.../IoTDBAggregationDeleteIT.java | 16 +-
.../{ => aggregation}/IoTDBAggregationIT.java | 2 +-
.../IoTDBAggregationLargeDataIT.java | 247 +++------------------
.../IoTDBAggregationSmallDataIT.java | 179 ++++++++-------
.../{ => auth}/IoTDBAuthorizationIT.java | 2 +-
.../db/query/aggregation/AggregateResultTest.java | 19 +-
.../query/aggregation/DescAggregateResultTest.java | 126 +++++++++++
.../iotdb/db/query/control/TracingManagerTest.java | 111 +++++++++
.../db/query/dataset/ShowTimeSeriesResultTest.java | 57 +++++
.../groupby}/GroupByEngineDataSetTest.java | 94 +++++---
.../{ => groupby}/GroupByFillDataSetTest.java | 2 +-
.../{ => groupby}/GroupByLevelDataSetTest.java | 2 +-
.../{ => groupby}/GroupByTimeDataSetTest.java | 2 +-
20 files changed, 559 insertions(+), 388 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java b/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
index 03a01e1..e6b9811 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
@@ -131,7 +131,7 @@ public class TracingManager {
.append("[").append(tsFileResource.getStartTime(device))
.append(", ").append(tsFileResource.getEndTime(device)).append("]");
if (deviceIter.hasNext()) {
- builder.append(", ");
+ builder.append(",");
}
}
}
diff --git a/server/src/test/java/org/apache/iotdb/db/engine/merge/MergeTest.java b/server/src/test/java/org/apache/iotdb/db/engine/merge/MergeTest.java
index 8753972..139ac70 100644
--- a/server/src/test/java/org/apache/iotdb/db/engine/merge/MergeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/engine/merge/MergeTest.java
@@ -97,7 +97,7 @@ abstract class MergeTest {
MergeManager.getINSTANCE().stop();
}
- private void prepareSeries() throws MetadataException, MetadataException {
+ private void prepareSeries() throws MetadataException {
measurementSchemas = new MeasurementSchema[measurementNum];
for (int i = 0; i < measurementNum; i++) {
measurementSchemas[i] = new MeasurementSchema("sensor" + i, TSDataType.DOUBLE,
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAddSubDeviceIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAddSubDeviceIT.java
index 586537e..b51cde6 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAddSubDeviceIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAddSubDeviceIT.java
@@ -36,6 +36,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+/**
+ * Test if measurement is also a sub device.
+ */
public class IoTDBAddSubDeviceIT {
private static String[] sqls = new String[]{
@@ -50,7 +53,6 @@ public class IoTDBAddSubDeviceIT {
EnvironmentUtils.envSetUp();
insertData();
-
}
@AfterClass
@@ -83,8 +85,7 @@ public class IoTDBAddSubDeviceIT {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(
- "SHOW DEVICES");
+ boolean hasResultSet = statement.execute("SHOW DEVICES");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -125,8 +126,7 @@ public class IoTDBAddSubDeviceIT {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(
- "SHOW TIMESERIES");
+ boolean hasResultSet = statement.execute("SHOW TIMESERIES");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -135,7 +135,8 @@ public class IoTDBAddSubDeviceIT {
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
header.append(resultSetMetaData.getColumnName(i)).append(",");
}
- Assert.assertEquals("timeseries,alias,storage group,dataType,encoding,compression,tags,attributes,",
+ Assert.assertEquals(
+ "timeseries,alias,storage group,dataType,encoding,compression,tags,attributes,",
header.toString());
Assert.assertEquals(Types.VARCHAR, resultSetMetaData.getColumnType(1));
@@ -171,8 +172,6 @@ public class IoTDBAddSubDeviceIT {
statement.execute("INSERT INTO root.sg1.d1.s1 (timestamp, s1) VALUES(0, 2)");
statement.execute("INSERT INTO root.sg1.d1.s1 (timestamp, s2) VALUES(0, 3)");
- // assertEquals(1, statement.getUpdateCount());
-
boolean hasResultSet = statement.execute(
"SELECT * FROM root.sg1.d1");
Assert.assertTrue(hasResultSet);
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
index 467754a..4369ffa 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
@@ -586,8 +586,7 @@ public class IoTDBAlignByDeviceIT {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(
- "select d0.s1, d0.s2, d1.s0 from root.vehicle align by device");
+ statement.execute("select d0.s1, d0.s2, d1.s0 from root.vehicle align by device");
fail("No exception thrown.");
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains(
@@ -602,8 +601,7 @@ public class IoTDBAlignByDeviceIT {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(
- "select s0 from root.*.* align by device");
+ statement.execute("select s0 from root.*.* align by device");
fail("No exception thrown.");
} catch (Exception e) {
// root.vehicle.d0.s0 INT32
@@ -615,6 +613,15 @@ public class IoTDBAlignByDeviceIT {
}
}
+ /**
+ * root.vehicle.d0.s0 INT32
+ * root.vehicle.d1.s0 INT32
+ * root.other.d1.s0 FLOAT
+ * but
+ * count(root.vehicle.d0.s0) INT64
+ * count(root.vehicle.d1.s0) INT64
+ * count(root.other.d1.s0) INT64
+ */
@Test
public void unusualCaseTest1() throws ClassNotFoundException {
String[] retArray = new String[]{
@@ -627,13 +634,7 @@ public class IoTDBAlignByDeviceIT {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- // root.vehicle.d0.s0 INT32
- // root.vehicle.d1.s0 INT32
- // root.other.d1.s0 FLOAT
- // but
- // count(root.vehicle.d0.s0) INT64
- // count(root.vehicle.d1.s0) INT64
- // count(root.other.d1.s0) INT64
+
boolean hasResultSet = statement.execute(
"select count(s0) from root.*.* align by device");
Assert.assertTrue(hasResultSet);
@@ -834,7 +835,7 @@ public class IoTDBAlignByDeviceIT {
@Test
- public void selectConstantTestUnorder() throws ClassNotFoundException {
+ public void selectUnorderedConstantTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"1,root.vehicle.d0,101,1101,'11',null,'22',null,null,",
"2,root.vehicle.d0,10000,40000,'11',2.22,'22',null,null,",
@@ -893,7 +894,7 @@ public class IoTDBAlignByDeviceIT {
}
@Test
- public void selectConstantAndNonExistTestUnorder() throws ClassNotFoundException {
+ public void selectUnorderedConstantAndNonExistTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"1,root.vehicle.d0,101,1101,'11',null,'22',null,null,null,",
"2,root.vehicle.d0,10000,40000,'11',2.22,'22',null,null,null,",
@@ -955,7 +956,7 @@ public class IoTDBAlignByDeviceIT {
}
@Test
- public void selectConstantAndNonExistTestWithUnorderedDevice() throws ClassNotFoundException {
+ public void selectConstantAndNonExistTestWithUnorderedDevice() throws ClassNotFoundException {
String[] retArray = new String[]{
"1,root.vehicle.d1,null,999,null,'11',null,'11','22',null,null,999,",
"1000,root.vehicle.d1,null,888,null,'11',null,'11','22',null,null,888,",
@@ -1036,7 +1037,7 @@ public class IoTDBAlignByDeviceIT {
}
@Test
- public void selectWithStarTest() throws ClassNotFoundException {
+ public void selectWithRegularExpressionTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"1,root.vehicle.d0,101,1101,null,null,null,",
"2,root.vehicle.d0,10000,40000,2.22,null,null,",
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAsIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAsIT.java
index 4236f5a..9f8e66f 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAsIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAsIT.java
@@ -125,6 +125,9 @@ public class IoTDBAsIT {
}
}
+ /**
+ * Test some time series use alias while others stay unchanged.
+ */
@Test
public void selectWithAsMixedTest() throws ClassNotFoundException {
String[] retArray = new String[]{
@@ -166,6 +169,10 @@ public class IoTDBAsIT {
}
}
+ /**
+ * When one alias is used but wildcard is corresponding to multi time series,
+ * it should throw one exception.
+ */
@Test
public void selectWithAsFailTest() throws ClassNotFoundException {
Class.forName(Config.JDBC_DRIVER_NAME);
@@ -181,6 +188,9 @@ public class IoTDBAsIT {
}
}
+ /**
+ * When wild is exactly corresponding to one time series, the result will be correct.
+ */
@Test
public void selectWithAsSingleTest() throws ClassNotFoundException {
String[] retArray = new String[]{
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java
index ef4d813..2453171 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAutoCreateSchemaIT.java
@@ -19,8 +19,12 @@
package org.apache.iotdb.db.integration;
-import org.apache.iotdb.db.conf.IoTDBConfig;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.Statement;
import org.apache.iotdb.db.constant.TestConstant;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.jdbc.Config;
@@ -29,21 +33,12 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
-
/**
* 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 IoTDBAutoCreateSchemaIT {
- private static IoTDBConfig conf = IoTDBDescriptor.getInstance().getConfig();
-
@Before
public void setUp() throws Exception {
EnvironmentUtils.closeStatMonitor();
@@ -124,7 +119,7 @@ public class IoTDBAutoCreateSchemaIT {
result = "";
while (resultSet.next()) {
for (int i = 1; i <= count; i++) {
- if (now_start > 0L && column[i - 1] == TestConstant.TIMESTAMP_STR) {
+ 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();
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationByLevelIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
similarity index 97%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationByLevelIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
index 92c5cdc..3de0898 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationByLevelIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.aggregation;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -31,7 +31,8 @@ import org.junit.Before;
import org.junit.Test;
public class IoTDBAggregationByLevelIT {
- private Planner processor = new Planner();
+
+ private Planner planner = new Planner();
private static final String[] dataSet = new String[]{
"SET STORAGE GROUP TO root.sg1",
"SET STORAGE GROUP TO root.sg2",
@@ -293,13 +294,13 @@ public class IoTDBAggregationByLevelIT {
}
try {
- processor.parseSQLToPhysicalPlan("select avg(status) from root.sg2.* GROUP BY level=1");
+ planner.parseSQLToPhysicalPlan("select avg(status) from root.sg2.* GROUP BY level=1");
} catch (Exception e) {
Assert.assertEquals("Aggregate among unmatched data types", e.getMessage());
}
try {
- processor.parseSQLToPhysicalPlan("select avg(status), sum(temperature) from root.sg2.* GROUP BY level=1");
+ planner.parseSQLToPhysicalPlan("select avg(status), sum(temperature) from root.sg2.* GROUP BY level=1");
} catch (Exception e) {
Assert.assertEquals("Aggregation function is restricted to one if group by level clause exists", e.getMessage());
}
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationDeleteIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationDeleteIT.java
similarity index 89%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationDeleteIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationDeleteIT.java
index d3751c2..1ec4cae 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationDeleteIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationDeleteIT.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.aggregation;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.utils.EnvironmentUtils;
@@ -61,12 +61,11 @@ public class IoTDBAggregationDeleteIT {
}
@Test
- public void countAfterDeleteTest() {
+ public void countAfterDeleteTest() throws SQLException {
try (Connection connection =
DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet =
- statement.execute("select count(*) from root");
+ boolean hasResultSet = statement.execute("select count(*) from root");
assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -74,14 +73,10 @@ public class IoTDBAggregationDeleteIT {
assertEquals("3", resultSet.getString(count("root.turbine.d1.s1")));
}
}
-
- } catch (SQLException e) {
- e.printStackTrace();
- fail();
}
}
- private void prepareData() {
+ private void prepareData() throws SQLException {
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
"root");
@@ -90,9 +85,6 @@ public class IoTDBAggregationDeleteIT {
for (String sql : dataSet) {
statement.execute(sql);
}
-
- } catch (Exception e) {
- e.printStackTrace();
}
}
}
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationIT.java
similarity index 99%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationIT.java
index b00fc64..a1295e4 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationIT.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.aggregation;
import static org.apache.iotdb.db.constant.TestConstant.avg;
import static org.apache.iotdb.db.constant.TestConstant.count;
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationLargeDataIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationLargeDataIT.java
similarity index 77%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationLargeDataIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationLargeDataIT.java
index 95fd267..70a7192 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationLargeDataIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationLargeDataIT.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.aggregation;
import static org.apache.iotdb.db.constant.TestConstant.avg;
import static org.apache.iotdb.db.constant.TestConstant.count;
@@ -135,30 +135,23 @@ public class IoTDBAggregationLargeDataIT {
public void test() throws ClassNotFoundException, SQLException {
insertSQL();
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root")) {
- lastValueAggreWithSingleFilterTest();
- avgAggreWithSingleFilterTest();
- sumAggreWithSingleFilterTest();
- firstAggreWithSingleFilterTest();
- countAggreWithSingleFilterTest();
- minMaxTimeAggreWithSingleFilterTest();
- minValueAggreWithSingleFilterTest();
- maxValueAggreWithSingleFilterTest();
-
- lastValueAggreWithMultiFilterTest();
- countAggreWithMultiFilterTest();
- minTimeAggreWithMultiFilterTest();
- maxTimeAggreWithMultiFilterTest();
- minValueAggreWithMultiFilterTest();
- maxValueAggreWithMultiFilterTest();
- avgAggreWithMultiFilterTest();
- sumAggreWithMultiFilterTest();
- firstAggreWithMultiFilterTest();
- }
+ lastValueAggreWithSingleFilterTest();
+ avgAggreWithSingleFilterTest();
+ sumAggreWithSingleFilterTest();
+ firstAggreWithSingleFilterTest();
+ countAggreWithSingleFilterTest();
+ minTimeAggreWithSingleFilterTest();
+ minValueAggreWithSingleFilterTest();
+ maxValueAggreWithSingleFilterTest();
+
+ countAggreWithMultiFilterTest();
+ maxTimeAggreWithMultiFilterTest();
+ avgAggreWithMultiFilterTest();
+ sumAggreWithMultiFilterTest();
+ firstAggreWithMultiFilterTest();
}
- private void lastValueAggreWithMultiFilterTest() throws SQLException {
+ private void lastValueAggreWithSingleFilterTest() {
String[] retArray = new String[]{
"0,9,39,63.0,E,true"
};
@@ -179,53 +172,25 @@ public class IoTDBAggregationLargeDataIT {
+ "," + resultSet.getString(last_value(d0s2)) + "," +
resultSet.getString(last_value(d0s3)) + "," + resultSet
.getString(last_value(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- private void lastValueAggreWithSingleFilterTest() throws SQLException {
- String[] retArray = new String[]{
- "0,9,39,63.0"
- };
-
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement
- .execute("select last_value(s0),last_value(s1),last_value(s2)" +
- " from root.vehicle.d0 where s1 >= 0");
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- while (resultSet.next()) {
- String ans = resultSet.getString(TIMESTAMP_STR) + "," +
- resultSet.getString(last_value(d0s0)) + ","
- + resultSet.getString(last_value(d0s1)) + "," +
- resultSet.getString(last_value(d0s2));
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
Assert.assertEquals(1, cnt);
}
- hasResultSet = statement
- .execute("select last_value(s0),last_value(s1),last_value(s2)" +
+ hasResultSet = statement.execute(
+ "select last_value(s0),last_value(s1),last_value(s2),last_value(s3),last_value(s4)" +
" from root.vehicle.d0 where s1 >= 0 order by time desc");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
int cnt = 0;
while (resultSet.next()) {
String ans = resultSet.getString(TIMESTAMP_STR) + "," +
- resultSet.getString(last_value(d0s0)) + ","
- + resultSet.getString(last_value(d0s1)) + "," +
- resultSet.getString(last_value(d0s2));
+ resultSet.getString(last_value(d0s0)) + "," + resultSet
+ .getString(last_value(d0s1))
+ + "," + resultSet.getString(last_value(d0s2)) + "," +
+ resultSet.getString(last_value(d0s3)) + "," + resultSet
+ .getString(last_value(d0s4));
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -381,7 +346,7 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void countAggreWithSingleFilterTest() throws SQLException {
+ private void countAggreWithSingleFilterTest() {
String[] retArray = new String[]{
"0,733,740,734"
};
@@ -405,7 +370,7 @@ public class IoTDBAggregationLargeDataIT {
}
hasResultSet = statement.execute(
- "select count(s0),count(s1),count(s2) from root.vehicle.d0 where s1 >= 0 order by time desc ");
+ "select count(s0),count(s1),count(s2) from root.vehicle.d0 where s1 >= 0 order by time desc");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
int cnt = 0;
@@ -423,13 +388,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void minMaxTimeAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ private void minTimeAggreWithSingleFilterTest() {
String[] retArray = new String[]{
- "0,104,1,2,101,100",
- "0,3999,3999,3999,3599,100"
+ "0,104,1,2,101,100"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -454,24 +417,6 @@ public class IoTDBAggregationLargeDataIT {
Assert.assertEquals(1, cnt);
}
- hasResultSet = statement.execute("select max_time(s0),max_time(s1),max_time(s2),"
- + "max_time(s3),max_time(s4) from root.vehicle.d0 " +
- "where s1 < 50000 and s1 != 100");
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(max_time(d0s0))
- + "," + resultSet.getString(max_time(d0s1)) + "," + resultSet
- .getString(max_time(d0s2))
- + "," + resultSet.getString(max_time(d0s3)) + "," + resultSet
- .getString(max_time(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
-
// keep the correctness of `order by time desc`
hasResultSet = statement.execute(
"select min_time(s0),min_time(s1),min_time(s2),min_time(s3),min_time(s4)" +
@@ -491,36 +436,17 @@ public class IoTDBAggregationLargeDataIT {
}
Assert.assertEquals(1, cnt);
}
-
- hasResultSet = statement.execute("select max_time(s0),max_time(s1),max_time(s2),"
- + "max_time(s3),max_time(s4) from root.vehicle.d0 " +
- "where s1 < 50000 and s1 != 100 order by time desc");
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(max_time(d0s0))
- + "," + resultSet.getString(max_time(d0s1)) + "," + resultSet
- .getString(max_time(d0s2))
- + "," + resultSet.getString(max_time(d0s3)) + "," + resultSet
- .getString(max_time(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(2, cnt);
- }
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
- private void minValueAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ private void minValueAggreWithSingleFilterTest() {
String[] retArray = new String[]{
"0,0,0,0.0,B,true"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager
.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -571,12 +497,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void maxValueAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ private void maxValueAggreWithSingleFilterTest() {
String[] retArray = new String[]{
"0,99,40000,122.0,fffff,true"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -628,12 +553,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void avgAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
+ private void avgAggreWithMultiFilterTest() {
String[] retArray = new String[]{
"0,55061.0,733,75,212,28"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -662,12 +586,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void sumAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
+ private void sumAggreWithMultiFilterTest() {
String[] retArray = new String[]{
"0,55061.0,156752.0,20262"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -707,12 +630,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void firstAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
+ private void firstAggreWithMultiFilterTest() {
String[] retArray = new String[]{
"0,90,1101,2.22,ddddd,true"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -761,12 +683,11 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void countAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
+ private void countAggreWithMultiFilterTest() {
String[] retArray = new String[]{
"0,733,740,736,482,1"
};
- Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -791,39 +712,6 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void minTimeAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
- String[] retArray = new String[]{
- "0,104,1,2,101,100"
- };
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- boolean hasResultSet = statement.execute("select min_time(s0),min_time(s1),min_time(s2),"
- + "min_time(s3),min_time(s4) from root.vehicle.d0 where s1 >= 0");
- Assert.assertTrue(hasResultSet);
- int cnt = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans = resultSet.getString(TIMESTAMP_STR) + "," +
- resultSet.getString(min_time(d0s0)) + "," +
- resultSet.getString(min_time(d0s1)) + "," +
- resultSet.getString(min_time(d0s2)) + "," +
- resultSet.getString(min_time(d0s3)) + "," +
- resultSet.getString(min_time(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
private void maxTimeAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
String[] retArray = new String[]{
"0,3999,3999,3999,3599,100"
@@ -877,76 +765,9 @@ public class IoTDBAggregationLargeDataIT {
}
}
- private void minValueAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
- String[] retArray = new String[]{
- "0,0,0,0.0,B,true"
- };
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- boolean hasResultSet = statement.execute("select min_value(s0),min_value(s1),min_value(s2),"
- + "min_value(s3),min_value(s4) from root.vehicle.d0 " +
- "where s1 < 50000 and s1 != 100");
- Assert.assertTrue(hasResultSet);
- int cnt = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(min_value(d0s0))
- + "," + resultSet.getString(min_value(d0s1)) + "," + resultSet
- .getString(min_value(d0s2))
- + "," + resultSet.getString(min_value(d0s3)) + "," + resultSet
- .getString(min_value(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- private void maxValueAggreWithMultiFilterTest() throws ClassNotFoundException, SQLException {
- String[] retArray = new String[]{
- "0,99,40000,122.0,fffff,true"
- };
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
-
- boolean hasResultSet = statement.execute("select max_value(s0),max_value(s1),max_value(s2),"
- + "max_value(s3),max_value(s4) from root.vehicle.d0 where s1 < 50000 and s1 != 100");
- Assert.assertTrue(hasResultSet);
- int cnt = 0;
- try (ResultSet resultSet = statement.getResultSet()) {
- while (resultSet.next()) {
- String ans =
- resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(max_value(d0s0))
- + "," + resultSet.getString(max_value(d0s1)) + "," + resultSet
- .getString(max_value(d0s2))
- + "," + resultSet.getString(max_value(d0s3)) + "," + resultSet
- .getString(max_value(d0s4));
- Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
private static String[] stringValue = new String[]{"A", "B", "C", "D", "E"};
- public static void insertSQL() throws ClassNotFoundException, SQLException {
+ public static void insertSQL() throws ClassNotFoundException {
Class.forName(Config.JDBC_DRIVER_NAME);
double d0s0sum = 0.0, d0s1sum = 0.0, d0s2sum = 0.0;
int cnt = 0;
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
similarity index 87%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
index 3564027..65d25c1 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationSmallDataIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.aggregation;
import static org.apache.iotdb.db.constant.TestConstant.avg;
import static org.apache.iotdb.db.constant.TestConstant.count;
@@ -127,7 +127,6 @@ public class IoTDBAggregationSmallDataIT {
EnvironmentUtils.envSetUp();
IoTDBDescriptor.getInstance().getConfig()
.setCompactionStrategy(CompactionStrategy.NO_COMPACTION);
- //Thread.sleep(5000);
insertSQL();
}
@@ -139,7 +138,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void countOnlyTimeFilterTest() throws ClassNotFoundException, SQLException {
+ public void countWithTimeFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,3,7,4,5,1"
};
@@ -171,13 +170,9 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void functionsNoFilterTest() throws ClassNotFoundException, SQLException {
+ public void countWithoutFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
- "0,4,0,6,1",
- "0,22222,null",
- "0,90,null,aaaaa",
- "0,22222,null,good",
- "0,22610.0,0.0"
+ "0,4,0,6,1"
};
Class.forName(Config.JDBC_DRIVER_NAME);
@@ -190,9 +185,8 @@ public class IoTDBAggregationSmallDataIT {
"SELECT count(d0.s0),count(d1.s1),count(d0.s3),count(d0.s4) FROM root.vehicle");
Assert.assertTrue(hasResultSet);
- int cnt;
+ int cnt = 0;
try (ResultSet resultSet = statement.getResultSet()) {
- cnt = 0;
while (resultSet.next()) {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(d0s0))
+ "," + resultSet.getString(count(d1s1)) + "," + resultSet.getString(count(d0s3))
@@ -202,8 +196,22 @@ public class IoTDBAggregationSmallDataIT {
}
Assert.assertEquals(1, cnt);
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
- //select max_value(d0.s0),max_value(d1.s1),max_value(d0.s3) from root.vehicle
+ @Test
+ public void maxValueWithoutFilterTest() throws ClassNotFoundException {
+ String[] retArray = new String[]{
+ "0,22222,null"
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager.
+ getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
try {
statement.execute(
@@ -213,9 +221,10 @@ public class IoTDBAggregationSmallDataIT {
Assert.assertEquals("500: Binary statistics does not support: max", e.getMessage());
}
- hasResultSet = statement.execute(
+ boolean hasResultSet = statement.execute(
"SELECT max_value(d0.s0),max_value(d1.s1) FROM root.vehicle");
Assert.assertTrue(hasResultSet);
+ int cnt = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ans =
@@ -224,13 +233,30 @@ public class IoTDBAggregationSmallDataIT {
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
- Assert.assertEquals(2, cnt);
+ Assert.assertEquals(1, cnt);
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void firstValueWithoutFilterTest() throws ClassNotFoundException {
+ String[] retArray = new String[]{
+ "0,90,null,aaaaa"
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager.
+ getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
//select first_value(d0.s0),first_value(d1.s1),first_value(d0.s3) from root.vehicle
- hasResultSet = statement.execute(
+ boolean hasResultSet = statement.execute(
"SELECT first_value(d0.s0),first_value(d1.s1),first_value(d0.s3) FROM root.vehicle");
Assert.assertTrue(hasResultSet);
+ int cnt = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ans =
@@ -240,13 +266,30 @@ public class IoTDBAggregationSmallDataIT {
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
- Assert.assertEquals(3, cnt);
+ Assert.assertEquals(1, cnt);
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void lastValueWithoutFilterTest() throws ClassNotFoundException {
+ String[] retArray = new String[]{
+ "0,22222,null,good"
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager.
+ getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
//select last_value(d0.s0),last_value(d1.s1),last_value(d0.s3) from root.vehicle
- hasResultSet = statement.execute(
+ boolean hasResultSet = statement.execute(
"SELECT last_value(d0.s0),last_value(d1.s1),last_value(d0.s3) FROM root.vehicle");
Assert.assertTrue(hasResultSet);
+ int cnt = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ans =
@@ -256,12 +299,29 @@ public class IoTDBAggregationSmallDataIT {
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
- Assert.assertEquals(4, cnt);
+ Assert.assertEquals(1, cnt);
}
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void sumWithoutFilterTest() throws ClassNotFoundException {
+ String[] retArray = new String[]{
+ "0,22610.0,0.0"
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection = DriverManager.
+ getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
//select sum(d0.s0),sum(d1.s1),sum(d0.s3) from root.vehicle
- hasResultSet = statement.execute("SELECT sum(d0.s0),sum(d1.s1) FROM root.vehicle");
+ boolean hasResultSet = statement.execute("SELECT sum(d0.s0),sum(d1.s1) FROM root.vehicle");
Assert.assertTrue(hasResultSet);
+ int cnt = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(sum(d0s0))
@@ -269,9 +329,8 @@ public class IoTDBAggregationSmallDataIT {
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
- Assert.assertEquals(5, cnt);
+ Assert.assertEquals(1, cnt);
}
-
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
@@ -279,7 +338,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void lastAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void lastValueWithSingleValueFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,22222,55555"
};
@@ -297,7 +356,6 @@ public class IoTDBAggregationSmallDataIT {
String ans =
resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(last_value(d0s0)) + ","
+ resultSet.getString(last_value(d0s1));
- //System.out.println("!!!!!============ " + ans);
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -310,7 +368,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void firstAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void firstValueWithSingleValueFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,99,180"
};
@@ -329,7 +387,6 @@ public class IoTDBAggregationSmallDataIT {
resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(first_value(d0s0))
+ ","
+ resultSet.getString(first_value(d0s1));
- //System.out.println("!!!!!============ " + ans);
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -342,7 +399,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void sumAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void sumWithSingleValueFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,22321.0,55934.0,1029"
};
@@ -359,7 +416,6 @@ public class IoTDBAggregationSmallDataIT {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(sum(d0s0))
+ "," + resultSet.getString(sum(d0s1)) + "," + Math
.round(resultSet.getDouble(sum(d0s2)));
- //System.out.println("!!!!!============ " + ans);
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -372,7 +428,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void avgAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void avgWithSingleValueFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,11160.5,18645,206"
};
@@ -389,7 +445,6 @@ public class IoTDBAggregationSmallDataIT {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(avg(d0s0))
+ "," + Math.round(resultSet.getDouble(avg(d0s1))) + ","
+ Math.round(resultSet.getDouble(avg(d0s2)));
- //System.out.println("!!!!!============ " + ans);
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -402,7 +457,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void countAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void countWithSingleValueFilterTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,2,3,5,1,0"
};
@@ -413,7 +468,6 @@ public class IoTDBAggregationSmallDataIT {
Statement statement = connection.createStatement()) {
boolean hasResultSet = statement.execute("SELECT count(s0),count(s1),count(s2),count(s3),"
+ "count(s4) FROM root.vehicle.d0 WHERE s2 >= 3.33");
- // System.out.println(hasResultSet + "...");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
int cnt = 0;
@@ -421,7 +475,6 @@ public class IoTDBAggregationSmallDataIT {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(d0s0))
+ "," + resultSet.getString(count(d0s1)) + "," + resultSet.getString(count(d0s2))
+ "," + resultSet.getString(count(d0s3)) + "," + resultSet.getString(count(d0s4));
- // System.out.println("============ " + ans);
Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
@@ -434,7 +487,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void minTimeAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void minTimeWithMultiValueFiltersTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,104,1,2,101,100"
};
@@ -444,8 +497,7 @@ public class IoTDBAggregationSmallDataIT {
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
boolean hasResultSet = statement.execute("SELECT min_time(s0),min_time(s1),min_time(s2)"
- + ",min_time(s3),min_time(s4) FROM root.vehicle.d0 " +
- "WHERE s1 < 50000 AND s1 != 100");
+ + ",min_time(s3),min_time(s4) FROM root.vehicle.d0 WHERE s1 < 50000 AND s1 != 100");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -457,7 +509,6 @@ public class IoTDBAggregationSmallDataIT {
.getString(min_time(d0s2))
+ "," + resultSet.getString(min_time(d0s3)) + "," + resultSet
.getString(min_time(d0s4));
- // System.out.println("============ " + ans);
Assert.assertEquals(ans, retArray[cnt]);
cnt++;
Assert.assertEquals(1, cnt);
@@ -470,7 +521,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void maxTimeAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void maxTimeWithMultiValueFiltersTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,105,105,105,102,100"
};
@@ -480,8 +531,7 @@ public class IoTDBAggregationSmallDataIT {
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
boolean hasResultSet = statement.execute("SELECT max_time(s0),max_time(s1),max_time(s2)"
- + ",max_time(s3),max_time(s4) FROM root.vehicle.d0 " +
- "WHERE s1 < 50000 AND s1 != 100");
+ + ",max_time(s3),max_time(s4) FROM root.vehicle.d0 WHERE s1 < 50000 AND s1 != 100");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -493,7 +543,6 @@ public class IoTDBAggregationSmallDataIT {
.getString(max_time(d0s2))
+ "," + resultSet.getString(max_time(d0s3)) + "," + resultSet
.getString(max_time(d0s4));
- // System.out.println("============ " + ans);
Assert.assertEquals(ans, retArray[cnt]);
cnt++;
}
@@ -506,7 +555,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void minValueAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void minValueWithMultiValueFiltersTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"0,90,180,2.22,ddddd,true"
};
@@ -515,9 +564,8 @@ public class IoTDBAggregationSmallDataIT {
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute("SELECT min_value(s0),min_value(s1),min_value(s2)"
- + ",min_value(s3),min_value(s4) FROM root.vehicle.d0 " +
- "WHERE s1 < 50000 AND s1 != 100");
+ boolean hasResultSet = statement.execute("SELECT min_value(s0),min_value(s1),min_value(s2),"
+ + "min_value(s3),min_value(s4) FROM root.vehicle.d0 WHERE s1 < 50000 AND s1 != 100");
Assert.assertTrue(hasResultSet);
try (ResultSet resultSet = statement.getResultSet()) {
@@ -529,7 +577,6 @@ public class IoTDBAggregationSmallDataIT {
"," + resultSet.getString(min_value(d0s2))
+ "," + resultSet.getString(min_value(d0s3)) + ","
+ resultSet.getString(min_value(d0s4));
- // System.out.println("============ " + ans);
Assert.assertEquals(ans, retArray[cnt]);
cnt++;
}
@@ -543,9 +590,9 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void maxValueAggreWithSingleFilterTest() throws ClassNotFoundException, SQLException {
+ public void maxValueWithMultiValueFiltersTest() throws ClassNotFoundException {
String[] retArray = new String[]{
- "0,99,50000,11.11,fffff,true"
+ "0,99,40000,11.11,fffff,true"
};
Class.forName(Config.JDBC_DRIVER_NAME);
@@ -566,38 +613,7 @@ public class IoTDBAggregationSmallDataIT {
.getString(max_value(d0s2))
+ "," + resultSet.getString(max_value(d0s3)) + "," + resultSet
.getString(max_value(d0s4));
- //System.out.println("============ " + ans);
- //Assert.assertEquals(ans, retArray[cnt]);
- cnt++;
- }
- Assert.assertEquals(1, cnt);
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
-
- @Test
- public void countAggreWithMultiMultiFilterTest() throws ClassNotFoundException, SQLException {
- String[] retArray = new String[]{
- "0,2",
- };
-
- Class.forName(Config.JDBC_DRIVER_NAME);
- try (Connection connection = DriverManager.
- getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
- Statement statement = connection.createStatement()) {
- boolean hasResultSet = statement.execute(
- "SELECT count(s0) FROM root.vehicle.d0 WHERE s2 >= 3.33");
- // System.out.println(hasResultSet + "...");
- Assert.assertTrue(hasResultSet);
- try (ResultSet resultSet = statement.getResultSet()) {
- int cnt = 0;
- while (resultSet.next()) {
- String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(count(d0s0));
- //System.out.println("============ " + ans);
- Assert.assertEquals(ans, retArray[cnt]);
+ Assert.assertEquals(retArray[cnt], ans);
cnt++;
}
Assert.assertEquals(1, cnt);
@@ -609,8 +625,7 @@ public class IoTDBAggregationSmallDataIT {
}
@Test
- public void selectAllSQLTest() throws ClassNotFoundException, SQLException {
- //d0s0,d0s1,d0s2,d0s3,d1s0
+ public void selectAllSQLTest() throws ClassNotFoundException {
String[] retArray = new String[]{
"1,null,1101,null,null,999",
"2,null,40000,2.22,null,null",
@@ -636,7 +651,6 @@ public class IoTDBAggregationSmallDataIT {
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
boolean hasResultSet = statement.execute("SELECT * FROM root");
- // System.out.println(hasResultSet + "...");
if (hasResultSet) {
try (ResultSet resultSet = statement.getResultSet()) {
int cnt = 0;
@@ -644,7 +658,6 @@ public class IoTDBAggregationSmallDataIT {
String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet.getString(d0s0) + ","
+ resultSet.getString(d0s1) + "," + resultSet.getString(d0s2) + "," +
resultSet.getString(d0s3) + "," + resultSet.getString(d1s0);
- // System.out.println(ans);
Assert.assertEquals(ans, retArray[cnt]);
cnt++;
}
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAuthorizationIT.java b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
similarity index 99%
rename from server/src/test/java/org/apache/iotdb/db/integration/IoTDBAuthorizationIT.java
rename to server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
index 67e99ff..dc84963 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAuthorizationIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/auth/IoTDBAuthorizationIT.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.integration;
+package org.apache.iotdb.db.integration.auth;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java b/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
index cffedf3..d2519fa 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
@@ -31,6 +31,9 @@ import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.junit.Assert;
import org.junit.Test;
+/**
+ * Unit tests of AggregateResult without desc aggregate result.
+ */
public class AggregateResultTest {
@Test
@@ -190,26 +193,26 @@ public class AggregateResultTest {
@Test
public void sumAggrResultTest() throws QueryProcessException, IOException {
AggregateResult sumAggrResult1 = AggregateResultFactory
- .getAggrResultByName(SQLConstant.SUM, TSDataType.DOUBLE, true);
+ .getAggrResultByName(SQLConstant.SUM, TSDataType.INT32, true);
AggregateResult sumAggrResult2 = AggregateResultFactory
- .getAggrResultByName(SQLConstant.SUM, TSDataType.DOUBLE, true);
+ .getAggrResultByName(SQLConstant.SUM, TSDataType.INT32, true);
- Statistics statistics1 = Statistics.getStatsByType(TSDataType.DOUBLE);
- Statistics statistics2 = Statistics.getStatsByType(TSDataType.DOUBLE);
- statistics1.update(1L, 1d);
- statistics2.update(1L, 2d);
+ Statistics statistics1 = Statistics.getStatsByType(TSDataType.INT32);
+ Statistics statistics2 = Statistics.getStatsByType(TSDataType.INT32);
+ statistics1.update(1L, 1);
+ statistics2.update(1L, 2);
sumAggrResult1.updateResultFromStatistics(statistics1);
sumAggrResult2.updateResultFromStatistics(statistics2);
sumAggrResult1.merge(sumAggrResult2);
- Assert.assertEquals(3d, (double) sumAggrResult1.getResult(), 0.01);
+ Assert.assertEquals(3.0, sumAggrResult1.getResult());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
sumAggrResult1.serializeTo(outputStream);
ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
AggregateResult result = AggregateResult.deserializeFrom(byteBuffer);
- Assert.assertEquals(3d, (double) result.getResult(), 0.01);
+ Assert.assertEquals(3.0, result.getResult());
}
@Test
diff --git a/server/src/test/java/org/apache/iotdb/db/query/aggregation/DescAggregateResultTest.java b/server/src/test/java/org/apache/iotdb/db/query/aggregation/DescAggregateResultTest.java
new file mode 100644
index 0000000..93b5952
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/query/aggregation/DescAggregateResultTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.query.aggregation;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.query.factory.AggregateResultFactory;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
+import org.apache.iotdb.tsfile.utils.Binary;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Unit tests of desc aggregate result.
+ */
+public class DescAggregateResultTest {
+
+ @Test
+ public void maxTimeDescAggrResultTest() throws QueryProcessException, IOException {
+ AggregateResult maxTimeDescAggrResult = AggregateResultFactory
+ .getAggrResultByName(SQLConstant.MAX_TIME, TSDataType.FLOAT, false);
+
+ Statistics statistics1 = Statistics.getStatsByType(TSDataType.FLOAT);
+ Statistics statistics2 = Statistics.getStatsByType(TSDataType.FLOAT);
+ statistics1.update(10L, 10.0f);
+ statistics2.update(1L, 1.0f);
+
+ maxTimeDescAggrResult.updateResultFromStatistics(statistics1);
+ Assert.assertEquals(10L, (long) maxTimeDescAggrResult.getResult());
+ maxTimeDescAggrResult.updateResultFromStatistics(statistics2);
+ Assert.assertEquals(10L, (long) maxTimeDescAggrResult.getResult());
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ maxTimeDescAggrResult.serializeTo(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
+ AggregateResult result = AggregateResult.deserializeFrom(byteBuffer);
+ Assert.assertEquals(10L, (long) result.getResult());
+ }
+
+ @Test
+ public void minTimeDescAggrResultTest() throws QueryProcessException, IOException {
+ AggregateResult minTimeDescAggrResult = AggregateResultFactory
+ .getAggrResultByName(SQLConstant.MIN_TIME, TSDataType.FLOAT, false);
+
+ Statistics statistics1 = Statistics.getStatsByType(TSDataType.FLOAT);
+ Statistics statistics2 = Statistics.getStatsByType(TSDataType.FLOAT);
+ statistics1.update(10L, 10.0f);
+ statistics2.update(1L, 1.0f);
+
+ minTimeDescAggrResult.updateResultFromStatistics(statistics1);
+ Assert.assertEquals(10L, (long) minTimeDescAggrResult.getResult());
+ minTimeDescAggrResult.updateResultFromStatistics(statistics2);
+ Assert.assertEquals(1L, (long) minTimeDescAggrResult.getResult());
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ minTimeDescAggrResult.serializeTo(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
+ AggregateResult result = AggregateResult.deserializeFrom(byteBuffer);
+ Assert.assertEquals(1L, (long) result.getResult());
+ }
+
+ @Test
+ public void firstValueDescAggrResultTest() throws QueryProcessException, IOException {
+ AggregateResult firstValueDescAggrResult = AggregateResultFactory
+ .getAggrResultByName(SQLConstant.FIRST_VALUE, TSDataType.BOOLEAN, false);
+
+ Statistics statistics1 = Statistics.getStatsByType(TSDataType.BOOLEAN);
+ Statistics statistics2 = Statistics.getStatsByType(TSDataType.BOOLEAN);
+ statistics1.update(10L, true);
+ statistics2.update(1L, false);
+
+ firstValueDescAggrResult.updateResultFromStatistics(statistics1);
+ Assert.assertEquals(true, firstValueDescAggrResult.getResult());
+ firstValueDescAggrResult.updateResultFromStatistics(statistics2);
+ Assert.assertEquals(false, firstValueDescAggrResult.getResult());
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ firstValueDescAggrResult.serializeTo(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
+ AggregateResult result = AggregateResult.deserializeFrom(byteBuffer);
+ Assert.assertEquals(false, result.getResult());
+ }
+
+ @Test
+ public void lastValueDescAggrResultTest() throws QueryProcessException, IOException {
+ AggregateResult lastValueDescAggrResult = AggregateResultFactory
+ .getAggrResultByName(SQLConstant.LAST_VALUE, TSDataType.TEXT, false);
+
+ Statistics statistics1 = Statistics.getStatsByType(TSDataType.TEXT);
+ Statistics statistics2 = Statistics.getStatsByType(TSDataType.TEXT);
+ statistics1.update(10L, new Binary("last"));
+ statistics2.update(1L, new Binary("first"));
+
+ lastValueDescAggrResult.updateResultFromStatistics(statistics1);
+ Assert.assertEquals("last", String.valueOf(lastValueDescAggrResult.getResult()));
+ lastValueDescAggrResult.updateResultFromStatistics(statistics2);
+ Assert.assertEquals("last", String.valueOf(lastValueDescAggrResult.getResult()));
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ lastValueDescAggrResult.serializeTo(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
+ AggregateResult result = AggregateResult.deserializeFrom(byteBuffer);
+ Assert.assertEquals("last", String.valueOf(result.getResult()));
+ }
+}
diff --git a/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java b/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java
new file mode 100644
index 0000000..25aa325
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.query.control;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.io.FileUtils;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.constant.TestConstant;
+import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
+import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TracingManagerTest {
+
+ private final String tracingDir = IoTDBDescriptor.getInstance().getConfig().getTracingDir();
+ File tracingFile = SystemFileFactory.INSTANCE.getFile(tracingDir, IoTDBConstant.TRACING_LOG);
+ private TracingManager tracingManager;
+ private BufferedReader bufferedReader;
+ private final String sql = "select * from root.sg.device1 where time > 10";
+ private final long queryId = 10;
+
+ private Set<TsFileResource> seqResources = new HashSet<>();
+
+ @Before
+ public void setUp() throws Exception {
+ tracingManager = TracingManager.getInstance();
+ bufferedReader = new BufferedReader(new FileReader(tracingFile));
+ prepareTsFileResources();
+ }
+
+ @After
+ public void tearDown() throws IOException, StorageEngineException {
+ tracingManager.close();
+ bufferedReader.close();
+ FileUtils.deleteDirectory(new File(tracingDir));
+ EnvironmentUtils.cleanAllDir();
+ }
+
+ @Test
+ public void tracingQueryTest() throws IOException {
+ String[] ans = {
+ "Query Id: 10 - Query Statement: " + sql,
+ "Query Id: 10 - Start time: 2020-12-",
+ "Query Id: 10 - Number of series paths: 3",
+ "Query Id: 10 - Query Statement: " + sql,
+ "Query Id: 10 - Start time: 2020-12-",
+ "Query Id: 10 - Number of series paths: 3",
+ "Query Id: 10 - Number of sequence files: 1",
+ "Query Id: 10 - SeqFile_1-1-0.tsfile root.sg.d1[1, 999], root.sg.d2[2, 998]",
+ "Query Id: 10 - Number of unSequence files: 0",
+ "Query Id: 10 - Number of chunks: 3",
+ "Query Id: 10 - Average size of chunks: 1371",
+ "Query Id: 10 - Total cost time: "
+ };
+ tracingManager.writeQueryInfo(queryId, sql, 1607529600000L);
+ tracingManager.writePathsNum(queryId, 3);
+ tracingManager.writeQueryInfo(queryId, sql, 1607529600000L, 3);
+ tracingManager.writeTsFileInfo(queryId, seqResources, Collections.EMPTY_SET);
+ tracingManager.writeChunksInfo(queryId, 3, 4113L);
+ tracingManager.writeEndTime(queryId);
+
+ String str;
+ int cnt = 0;
+ while ((str = bufferedReader.readLine()) != null) {
+ Assert.assertTrue(str.contains(ans[cnt++]));
+ }
+ }
+
+ void prepareTsFileResources() throws IOException {
+ Map<String, Integer> deviceToIndex = new HashMap<>();
+ deviceToIndex.put("root.sg.d1", 0);
+ deviceToIndex.put("root.sg.d2", 1);
+ long[] startTimes = {1, 2};
+ long[] endTimes = {999, 998};
+ File file1 = new File(TestConstant.OUTPUT_DATA_DIR.concat("1-1-0.tsfile"));
+ TsFileResource tsFileResource1 = new TsFileResource(file1, deviceToIndex, startTimes, endTimes,
+ null, null, null);
+ tsFileResource1.setClosed(true);
+ seqResources.add(tsFileResource1);
+ }
+}
diff --git a/server/src/test/java/org/apache/iotdb/db/query/dataset/ShowTimeSeriesResultTest.java b/server/src/test/java/org/apache/iotdb/db/query/dataset/ShowTimeSeriesResultTest.java
new file mode 100644
index 0000000..e3a3d00
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/query/dataset/ShowTimeSeriesResultTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.query.dataset;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ShowTimeSeriesResultTest {
+
+ @Test
+ public void serializeTest() throws IOException {
+ Map<String, String> tag = Collections.singletonMap("tag1", "this is the first tag");
+ Map<String, String> attribute = Collections
+ .singletonMap("attribute1", "this is the first attribute");
+ ShowTimeSeriesResult showTimeSeriesResult = new ShowTimeSeriesResult("root.sg1.d1.s1",
+ "temperature", "root.sg1", TSDataType.DOUBLE, TSEncoding.GORILLA, CompressionType.SNAPPY,
+ tag, attribute);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ showTimeSeriesResult.serialize(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(outputStream.toByteArray());
+ ShowTimeSeriesResult result = ShowTimeSeriesResult.deserialize(byteBuffer);
+
+ Assert.assertEquals("root.sg1.d1.s1", result.getName());
+ Assert.assertEquals("temperature", result.getAlias());
+ Assert.assertEquals("root.sg1", result.getSgName());
+ Assert.assertEquals(TSDataType.DOUBLE, result.getDataType());
+ Assert.assertEquals(TSEncoding.GORILLA, result.getEncoding());
+ Assert.assertEquals(CompressionType.SNAPPY, result.getCompressor());
+ Assert.assertEquals(tag, result.getTag());
+ Assert.assertEquals(attribute, result.getAttribute());
+ }
+}
diff --git a/server/src/test/java/org/apache/iotdb/db/query/executor/GroupByEngineDataSetTest.java b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSetTest.java
similarity index 87%
rename from server/src/test/java/org/apache/iotdb/db/query/executor/GroupByEngineDataSetTest.java
rename to server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSetTest.java
index 2ec5d04..6471b06 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/executor/GroupByEngineDataSetTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSetTest.java
@@ -16,8 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.query.executor;
-
+package org.apache.iotdb.db.query.dataset.groupby;
import java.io.IOException;
import java.text.DateFormat;
@@ -27,16 +26,17 @@ import java.util.Date;
import java.util.TimeZone;
import org.apache.iotdb.db.qp.physical.crud.GroupByTimePlan;
import org.apache.iotdb.db.query.aggregation.impl.CountAggrResult;
-import org.apache.iotdb.db.query.dataset.groupby.GroupByEngineDataSet;
-import org.apache.iotdb.db.query.dataset.groupby.GroupByWithValueFilterDataSet;
import org.apache.iotdb.tsfile.utils.Pair;
import org.junit.Assert;
import org.junit.Test;
public class GroupByEngineDataSetTest {
+ /**
+ * Sliding step > unit && last time interval = unit
+ */
@Test
- public void test1() throws IOException {
+ public void calNextTimePartitionTest1() throws IOException {
long queryId = 1000L;
long unit = 3;
long slidingStep = 5;
@@ -57,7 +57,6 @@ public class GroupByEngineDataSetTest {
int cnt = 0;
while (groupByEngine.hasNext()) {
Pair pair = groupByEngine.nextTimePartition();
- Assert.assertTrue(cnt < startTimeArray.length);
Assert.assertEquals(startTimeArray[cnt], pair.left);
Assert.assertEquals(endTimeArray[cnt], pair.right);
cnt++;
@@ -65,16 +64,19 @@ public class GroupByEngineDataSetTest {
Assert.assertEquals(startTimeArray.length, cnt);
}
+ /**
+ * Sliding step = unit && last time interval = unit
+ */
@Test
- public void test2() throws IOException {
+ public void calNextTimePartitionTest2() throws IOException {
long queryId = 1000L;
long unit = 3;
- long slidingStep = 5;
+ long slidingStep = 3;
long startTime = 8;
- long endTime = 8 + 4 * 5 + 3;
+ long endTime = 8 + 5 * 3;
- long[] startTimeArray = {8, 13, 18, 23, 28};
- long[] endTimeArray = {11, 16, 21, 26, 31};
+ long[] startTimeArray = {8, 11, 14, 17, 20};
+ long[] endTimeArray = {11, 14, 17, 20, 23};
GroupByTimePlan groupByTimePlan = new GroupByTimePlan();
groupByTimePlan.setInterval(unit);
@@ -86,7 +88,6 @@ public class GroupByEngineDataSetTest {
int cnt = 0;
while (groupByEngine.hasNext()) {
Pair pair = groupByEngine.nextTimePartition();
- Assert.assertTrue(cnt < startTimeArray.length);
Assert.assertEquals(startTimeArray[cnt], pair.left);
Assert.assertEquals(endTimeArray[cnt], pair.right);
cnt++;
@@ -94,28 +95,29 @@ public class GroupByEngineDataSetTest {
Assert.assertEquals(startTimeArray.length, cnt);
}
+ /**
+ * Sliding step = unit && last time interval < unit
+ */
@Test
- public void test3() throws IOException {
+ public void calNextTimePartitionTest3() throws IOException {
long queryId = 1000L;
long unit = 3;
long slidingStep = 3;
long startTime = 8;
- long endTime = 8 + 5 * 3;
+ long endTime = 8 + 5 * 3 + 2;
- long[] startTimeArray = {8, 11, 14, 17, 20};
- long[] endTimeArray = {11, 14, 17, 20, 23};
+ long[] startTimeArray = {8, 11, 14, 17, 20, 23};
+ long[] endTimeArray = {11, 14, 17, 20, 23, 25};
GroupByTimePlan groupByTimePlan = new GroupByTimePlan();
groupByTimePlan.setInterval(unit);
groupByTimePlan.setSlidingStep(slidingStep);
groupByTimePlan.setStartTime(startTime);
groupByTimePlan.setEndTime(endTime);
- GroupByEngineDataSet groupByEngine = new GroupByWithValueFilterDataSet(queryId,
- groupByTimePlan);
+ GroupByEngineDataSet groupByEngine = new GroupByWithValueFilterDataSet(queryId, groupByTimePlan);
int cnt = 0;
while (groupByEngine.hasNext()) {
Pair pair = groupByEngine.nextTimePartition();
- Assert.assertTrue(cnt < startTimeArray.length);
Assert.assertEquals(startTimeArray[cnt], pair.left);
Assert.assertEquals(endTimeArray[cnt], pair.right);
cnt++;
@@ -123,18 +125,54 @@ public class GroupByEngineDataSetTest {
Assert.assertEquals(startTimeArray.length, cnt);
}
+ /**
+ * Desc query && sliding step > unit && last time interval = unit
+ */
@Test
- public void test4() throws IOException {
+ public void calNextTimePartitionDescTest1() throws IOException {
+ long queryId = 1000L;
+ long unit = 3;
+ long slidingStep = 5;
+ long startTime = 8;
+ long endTime = 8 + 4 * 5 + 3;
+
+ long[] startTimeArray = {28, 23, 18, 13, 8};
+ long[] endTimeArray = {31, 26, 21, 16, 11};
+
+ GroupByTimePlan groupByTimePlan = new GroupByTimePlan();
+ groupByTimePlan.setAscending(false);
+ groupByTimePlan.setInterval(unit);
+ groupByTimePlan.setSlidingStep(slidingStep);
+ groupByTimePlan.setStartTime(startTime);
+ groupByTimePlan.setEndTime(endTime);
+
+ GroupByEngineDataSet groupByEngine = new GroupByWithValueFilterDataSet(queryId, groupByTimePlan);
+ int cnt = 0;
+ while (groupByEngine.hasNext()) {
+ Pair pair = groupByEngine.nextTimePartition();
+ Assert.assertEquals(startTimeArray[cnt], pair.left);
+ Assert.assertEquals(endTimeArray[cnt], pair.right);
+ cnt++;
+ }
+ Assert.assertEquals(startTimeArray.length, cnt);
+ }
+
+ /**
+ * Desc query && Sliding step = unit && last time interval = unit
+ */
+ @Test
+ public void calNextTimePartitionDescTest2() throws IOException {
long queryId = 1000L;
long unit = 3;
long slidingStep = 3;
long startTime = 8;
long endTime = 8 + 5 * 3;
- long[] startTimeArray = {8, 11, 14, 17, 20};
- long[] endTimeArray = {11, 14, 17, 20, 23};
+ long[] startTimeArray = {20, 17, 14, 11, 8};
+ long[] endTimeArray = {23, 20, 17, 14, 11};
GroupByTimePlan groupByTimePlan = new GroupByTimePlan();
+ groupByTimePlan.setAscending(false);
groupByTimePlan.setInterval(unit);
groupByTimePlan.setSlidingStep(slidingStep);
groupByTimePlan.setStartTime(startTime);
@@ -144,7 +182,6 @@ public class GroupByEngineDataSetTest {
int cnt = 0;
while (groupByEngine.hasNext()) {
Pair pair = groupByEngine.nextTimePartition();
- Assert.assertTrue(cnt < startTimeArray.length);
Assert.assertEquals(startTimeArray[cnt], pair.left);
Assert.assertEquals(endTimeArray[cnt], pair.right);
cnt++;
@@ -152,22 +189,27 @@ public class GroupByEngineDataSetTest {
Assert.assertEquals(startTimeArray.length, cnt);
}
+ /**
+ * Desc query && Sliding step = unit && last time interval < unit
+ */
@Test
- public void test5() throws IOException {
+ public void calNextTimePartitionDescTest3() throws IOException {
long queryId = 1000L;
long unit = 3;
long slidingStep = 3;
long startTime = 8;
long endTime = 8 + 5 * 3 + 2;
- long[] startTimeArray = {8, 11, 14, 17, 20, 23};
- long[] endTimeArray = {11, 14, 17, 20, 23, 25};
+ long[] startTimeArray = {23, 20, 17, 14, 11, 8};
+ long[] endTimeArray = {25, 23, 20, 17, 14, 11};
GroupByTimePlan groupByTimePlan = new GroupByTimePlan();
+ groupByTimePlan.setAscending(false);
groupByTimePlan.setInterval(unit);
groupByTimePlan.setSlidingStep(slidingStep);
groupByTimePlan.setStartTime(startTime);
groupByTimePlan.setEndTime(endTime);
+
ArrayList<Object> aggrList = new ArrayList<>();
aggrList.add(new CountAggrResult());
GroupByEngineDataSet groupByEngine = new GroupByWithValueFilterDataSet(queryId,
diff --git a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByFillDataSetTest.java b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByFillDataSetTest.java
similarity index 99%
rename from server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByFillDataSetTest.java
rename to server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByFillDataSetTest.java
index 6710556..9c3bac8 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByFillDataSetTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByFillDataSetTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.iotdb.db.query.dataset;
+package org.apache.iotdb.db.query.dataset.groupby;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByLevelDataSetTest.java b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByLevelDataSetTest.java
similarity index 99%
rename from server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByLevelDataSetTest.java
rename to server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByLevelDataSetTest.java
index 3d01a87..5351d04 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByLevelDataSetTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByLevelDataSetTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.query.dataset;
+package org.apache.iotdb.db.query.dataset.groupby;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.qp.Planner;
diff --git a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByTimeDataSetTest.java b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByTimeDataSetTest.java
similarity index 99%
rename from server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByTimeDataSetTest.java
rename to server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByTimeDataSetTest.java
index babf607..f5684ed 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/dataset/GroupByTimeDataSetTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/dataset/groupby/GroupByTimeDataSetTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.db.query.dataset;
+package org.apache.iotdb.db.query.dataset.groupby;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.qp.Planner;