This is an automated email from the ASF dual-hosted git repository. lta pushed a commit to branch fix_jira_100 in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit f632513637c3a7e0dc58b9cb8fb426831c60e8be Author: lta <[email protected]> AuthorDate: Fri May 24 19:34:47 2019 +0800 fix jira issue 100 --- .../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 | 99 ++++++++++++++++++++-- 4 files changed, 110 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..2b637fd 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"; @@ -483,6 +484,86 @@ public class IoTDBAggregationIT { } Assert.assertEquals(2, cnt); statement.close(); + + + statement = connection.createStatement(); + try { + hasResultSet = statement.execute("select sum(s3),mean(s2)" + + "from root.vehicle.d0 where time >= 6000 and time <= 9000"); + Assert.assertTrue(hasResultSet); + } catch (Exception e) { + Assert.assertEquals("Unsupported data type in aggregation SUM : BOOLEAN", e.getMessage()); + System.out.println(e.getMessage()); + System.out.println(); + } + statement.close(); + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } finally { + if (connection != null) { + connection.close(); + } + } + } + + @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()); @@ -512,30 +593,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();
