You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by lt...@apache.org on 2019/05/24 16:05:42 UTC
[incubator-iotdb] branch master updated: [IOTDB-100]Fix return
error message while executing sum aggregation query (#181)
This is an automated email from the ASF dual-hosted git repository.
lta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 84bdd5a [IOTDB-100]Fix return error message while executing sum aggregation query (#181)
84bdd5a is described below
commit 84bdd5a2be6609327c62d83f1ac1732a6cf7b195
Author: Tianan Li <li...@163.com>
AuthorDate: Sat May 25 00:05:38 2019 +0800
[IOTDB-100]Fix return error message while executing sum aggregation query (#181)
* fix jira issue 100
* remove useless code
---
.../db/query/aggregation/AggregateFunction.java | 1 -
.../db/query/aggregation/impl/MeanAggrFunc.java | 11 ++-
.../db/query/aggregation/impl/SumAggrFunc.java | 10 +++
.../iotdb/db/integration/IoTDBAggregationIT.java | 86 +++++++++++++++++++---
4 files changed, 97 insertions(+), 11 deletions(-)
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java
index a9bdba2..f50867f 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/AggregateFunction.java
@@ -131,5 +131,4 @@ public abstract class AggregateFunction {
public TSDataType getResultDataType() {
return resultDataType;
}
-
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java
index 5373018..5139c0b 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MeanAggrFunc.java
@@ -34,6 +34,7 @@ public class MeanAggrFunc extends AggregateFunction {
protected double sum = 0.0;
private int cnt = 0;
private TSDataType seriesDataType;
+ private static final String MEAN_AGGR_NAME = "MEAN";
public MeanAggrFunc(TSDataType seriesDataType) {
super(TSDataType.DOUBLE);
@@ -122,7 +123,8 @@ public class MeanAggrFunc extends AggregateFunction {
case TEXT:
case BOOLEAN:
default:
- throw new IOException("Unsupported data type in aggregation MEAN : " + type);
+ throw new IOException(
+ String.format("Unsupported data type in aggregation %s : %s", getAggreTypeName(), type));
}
cnt++;
}
@@ -160,4 +162,11 @@ public class MeanAggrFunc extends AggregateFunction {
public boolean isCalculatedAggregationResult() {
return false;
}
+
+ /**
+ * Return type name of aggregation
+ */
+ public String getAggreTypeName() {
+ return MEAN_AGGR_NAME;
+ }
}
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java
index 3bb8d7d..e4311e8 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/query/aggregation/impl/SumAggrFunc.java
@@ -24,6 +24,8 @@ import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
public class SumAggrFunc extends MeanAggrFunc {
+ private static final String SUM_AGGR_NAME = "SUM";
+
public SumAggrFunc(TSDataType seriesDataType) {
super(seriesDataType);
}
@@ -34,4 +36,12 @@ public class SumAggrFunc extends MeanAggrFunc {
resultData.setTimestamp(0);
return resultData;
}
+
+ /**
+ * Return type name of aggregation
+ */
+ @Override
+ public String getAggreTypeName() {
+ return SUM_AGGR_NAME;
+ }
}
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java b/iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
index 47ff18c..0a7b4c4 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/integration/IoTDBAggregationIT.java
@@ -54,7 +54,8 @@ public class IoTDBAggregationIT {
"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.s3 WITH DATATYPE=TEXT, ENCODING=PLAIN",
+ "CREATE TIMESERIES root.vehicle.d0.s4 WITH DATATYPE=BOOLEAN, ENCODING=PLAIN"
};
private static String[] dataSet2 = new String[]{
@@ -74,8 +75,8 @@ public class IoTDBAggregationIT {
+ "values(5, 5.5, false, 55)"
};
- private String insertTemplate = "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3)"
- + " VALUES(%d,%d,%d,%f,%s)";
+ private String insertTemplate = "INSERT INTO root.vehicle.d0(timestamp,s0,s1,s2,s3,s4)"
+ + " VALUES(%d,%d,%d,%f,%s,%s)";
private static final String TIMESTAMP_STR = "Time";
private final String d0s0 = "root.vehicle.d0.s0";
@@ -493,6 +494,73 @@ public class IoTDBAggregationIT {
}
}
+ @Test
+ public void meanSumErrorTest() throws SQLException {
+ Connection connection = null;
+ try {
+ connection = DriverManager.
+ getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement();
+ boolean hasResultSet = statement.execute("select mean(s3)" +
+ "from root.vehicle.d0 where time >= 6000 and time <= 9000");
+ Assert.assertTrue(hasResultSet);
+ ResultSet resultSet = statement.getResultSet();
+ try {
+ resultSet.next();
+ fail();
+ } catch (Exception e) {
+ Assert.assertEquals("Unsupported data type in aggregation MEAN : TEXT", e.getMessage());
+ }
+ statement.close();
+
+ statement = connection.createStatement();
+ hasResultSet = statement.execute("select sum(s3)" +
+ "from root.vehicle.d0 where time >= 6000 and time <= 9000");
+ Assert.assertTrue(hasResultSet);
+ resultSet = statement.getResultSet();
+ try {
+ resultSet.next();
+ fail();
+ } catch (Exception e) {
+ Assert.assertEquals("Unsupported data type in aggregation SUM : TEXT", e.getMessage());
+ }
+ statement.close();
+
+ statement = connection.createStatement();
+ hasResultSet = statement.execute("select mean(s4)" +
+ "from root.vehicle.d0 where time >= 6000 and time <= 9000");
+ Assert.assertTrue(hasResultSet);
+ resultSet = statement.getResultSet();
+ try {
+ resultSet.next();
+ fail();
+ } catch (Exception e) {
+ Assert.assertEquals("Unsupported data type in aggregation MEAN : BOOLEAN", e.getMessage());
+ }
+ statement.close();
+
+ statement = connection.createStatement();
+ hasResultSet = statement.execute("select sum(s4)" +
+ "from root.vehicle.d0 where time >= 6000 and time <= 9000");
+ Assert.assertTrue(hasResultSet);
+ resultSet = statement.getResultSet();
+ try {
+ resultSet.next();
+ fail();
+ } catch (Exception e) {
+ Assert.assertEquals("Unsupported data type in aggregation SUM : BOOLEAN", e.getMessage());
+ }
+ statement.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ } finally {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+
private void prepareData() throws SQLException {
Connection connection = null;
try {
@@ -512,30 +580,30 @@ public class IoTDBAggregationIT {
statement = connection.createStatement();
// prepare BufferWrite file
for (int i = 5000; i < 7000; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "true"));
}
statement.execute("flush");
for (int i = 7500; i < 8500; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "false"));
}
statement.execute("flush");
// prepare Unseq-File
for (int i = 500; i < 1500; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "true"));
}
statement.execute("flush");
for (int i = 3000; i < 6500; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "false"));
}
statement.execute("merge");
// prepare BufferWrite cache
for (int i = 9000; i < 10000; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "true"));
}
// prepare Overflow cache
for (int i = 2000; i < 2500; i++) {
- statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'"));
+ statement.execute(String.format(insertTemplate, i, i, i, (double) i, "\'" + i + "\'", "false"));
}
statement.close();