You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/08/26 15:40:00 UTC
[iotdb] branch rel/0.12 updated: [To rel/0.12][ISSUE-3811] Provide
a data type column for the last query dataset (#3840)
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.12 by this push:
new 227edd9 [To rel/0.12][ISSUE-3811] Provide a data type column for the last query dataset (#3840)
227edd9 is described below
commit 227edd903627099b7d8966e396098a70045142bc
Author: Steve Yurong Su (宇荣) <ro...@apache.org>
AuthorDate: Thu Aug 26 10:39:29 2021 -0500
[To rel/0.12][ISSUE-3811] Provide a data type column for the last query dataset (#3840)
---
docs/UserGuide/Appendix/SQL-Reference.md | 14 +++++------
.../DML-Data-Manipulation-Language.md | 28 ++++++++++++----------
docs/zh/UserGuide/Appendix/SQL-Reference.md | 14 +++++------
.../DML-Data-Manipulation-Language.md | 28 +++++++++++-----------
.../org/apache/iotdb/db/conf/IoTDBConstant.java | 1 +
.../iotdb/db/query/executor/LastQueryExecutor.java | 11 +++++++--
.../org/apache/iotdb/db/service/StaticResps.java | 6 +++--
.../org/apache/iotdb/db/integration/IoTDBAsIT.java | 10 ++++----
8 files changed, 63 insertions(+), 49 deletions(-)
diff --git a/docs/UserGuide/Appendix/SQL-Reference.md b/docs/UserGuide/Appendix/SQL-Reference.md
index 6897816..af0989e 100644
--- a/docs/UserGuide/Appendix/SQL-Reference.md
+++ b/docs/UserGuide/Appendix/SQL-Reference.md
@@ -633,15 +633,15 @@ Rules:
2. SELECT LAST only supports time filter that contains '>' or '>=' currently.
-3. The result set of last query will always be displayed in a fixed three column table format.
+3. The result set of last query will always be displayed in a fixed four column table format.
For example, "select last s1, s2 from root.sg.d1, root.sg.d2", the query result would be:
-| Time | Path | Value |
-| --- | ------------ | ----- |
-| 5 | root.sg.d1.s1| 100 |
-| 2 | root.sg.d1.s2| 400 |
-| 4 | root.sg.d2.s1| 250 |
-| 9 | root.sg.d2.s2| 600 |
+| Time | Path | Value | Type |
+| --- | ------------ | ----- | ----- |
+| 5 | root.sg.d1.s1| 100 | INT32 |
+| 2 | root.sg.d1.s2| 400 | INT32 |
+| 4 | root.sg.d2.s1| 250 | INT32 |
+| 9 | root.sg.d2.s2| 600 | INT32 |
4. It is not supported to use "diable align" in LAST query.
diff --git a/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md b/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
index 8780db2..f76345d 100644
--- a/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
+++ b/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
@@ -837,21 +837,23 @@ which means: Query and return the last data points of timeseries prefixPath.path
Only time filter with '>' or '>=' is supported in \<WhereClause\>. Any other filters given in the \<WhereClause\> will give an exception.
-The result will be returned in a three column table format.
+The result will be returned in a four column table format.
```
-| Time | Path | Value |
++----+----------+-----+----+
+|Time|timeseries|value|type|
++----+----------+-----+----+
```
Example 1: get the last point of root.ln.wf01.wt01.status:
```
IoTDB> select last status from root.ln.wf01.wt01
-+-----------------------------+------------------------+-----+
-| Time| timeseries|value|
-+-----------------------------+------------------------+-----+
-|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.status|false|
-+-----------------------------+------------------------+-----+
++-----------------------------+------------------------+-----+-------+
+| Time| timeseries|value| type|
++-----------------------------+------------------------+-----+-------+
+|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.status|false|BOOLEAN|
++-----------------------------+------------------------+-----+-------+
Total line number = 1
It costs 0.000s
```
@@ -861,12 +863,12 @@ whose timestamp larger or equal to 2017-11-07T23:50:00。
```
IoTDB> select last status, temperature from root.ln.wf01.wt01 where time >= 2017-11-07T23:50:00
-+-----------------------------+-----------------------------+---------+
-| Time| timeseries| value|
-+-----------------------------+-----------------------------+---------+
-|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false|
-|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368|
-+-----------------------------+-----------------------------+---------+
++-----------------------------+-----------------------------+---------+-------+
+| Time| timeseries| value| type|
++-----------------------------+-----------------------------+---------+-------+
+|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false|BOOLEAN|
+|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368| DOUBLE|
++-----------------------------+-----------------------------+---------+-------+
Total line number = 2
It costs 0.002s
```
diff --git a/docs/zh/UserGuide/Appendix/SQL-Reference.md b/docs/zh/UserGuide/Appendix/SQL-Reference.md
index 7f2eb4a..0bbb98c 100644
--- a/docs/zh/UserGuide/Appendix/SQL-Reference.md
+++ b/docs/zh/UserGuide/Appendix/SQL-Reference.md
@@ -623,15 +623,15 @@ Eg. SELECT LAST s1, s2 FROM root.sg.d1 where time >= 500
2. 当前SELECT LAST 语句只支持包含'>'或'>='的时间过滤条件
-3. 结果集以三列的表格的固定形式返回。
+3. 结果集以四列的表格的固定形式返回。
例如 "select last s1, s2 from root.sg.d1, root.sg.d2", 结果集返回如下:
-| Time | Path | Value |
-| --- | ------------ | ----- |
-| 5 | root.sg.d1.s1| 100 |
-| 2 | root.sg.d1.s2| 400 |
-| 4 | root.sg.d2.s1| 250 |
-| 9 | root.sg.d2.s2| 600 |
+| Time | Path | Value | Type |
+| --- | ------------ | ----- | ----- |
+| 5 | root.sg.d1.s1| 100 | INT32 |
+| 2 | root.sg.d1.s2| 400 | INT32 |
+| 4 | root.sg.d2.s1| 250 | INT32 |
+| 9 | root.sg.d2.s2| 600 | INT32 |
4. 注意LAST语句不支持与"disable align"关键词一起使用。
diff --git a/docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md b/docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
index 91b213d..674b2e5 100644
--- a/docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
+++ b/docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
@@ -663,20 +663,20 @@ select last <Path> [COMMA <Path>]* from < PrefixPath > [COMMA < PrefixPath >]* <
结果集为三列的结构
```
-+----+----------+-----+
-|Time|timeseries|value|
-+----+----------+-----+
++----+----------+-----+----+
+|Time|timeseries|value|type|
++----+----------+-----+----+
```
示例 1:查询 root.ln.wf01.wt01.status 的最新数据点
```
IoTDB> select last status from root.ln.wf01.wt01
-+-----------------------------+------------------------+-----+
-| Time| timeseries|value|
-+-----------------------------+------------------------+-----+
-|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.status|false|
-+-----------------------------+------------------------+-----+
++-----------------------------+------------------------+-----+-------+
+| Time| timeseries|value| type|
++-----------------------------+------------------------+-----+-------+
+|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.status|false|BOOLEAN|
++-----------------------------+------------------------+-----+-------+
Total line number = 1
It costs 0.000s
```
@@ -685,12 +685,12 @@ It costs 0.000s
```
IoTDB> select last status, temperature from root.ln.wf01.wt01 where time >= 2017-11-07T23:50:00
-+-----------------------------+-----------------------------+---------+
-| Time| timeseries| value|
-+-----------------------------+-----------------------------+---------+
-|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false|
-|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368|
-+-----------------------------+-----------------------------+---------+
++-----------------------------+-----------------------------+---------+-------+
+| Time| timeseries| value| type|
++-----------------------------+-----------------------------+---------+-------+
+|2017-11-07T23:59:00.000+08:00| root.ln.wf01.wt01.status| false|BOOLEAN|
+|2017-11-07T23:59:00.000+08:00|root.ln.wf01.wt01.temperature|21.067368| DOUBLE|
++-----------------------------+-----------------------------+---------+-------+
Total line number = 2
It costs 0.002s
```
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
index 6ef28c7..28bce70 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConstant.java
@@ -73,6 +73,7 @@ public class IoTDBConstant {
public static final String COLUMN_COUNT = "count";
public static final String COLUMN_TAGS = "tags";
public static final String COLUMN_ATTRIBUTES = "attributes";
+ public static final String COLUMN_TYPE = "type";
public static final String QUERY_ID = "queryId";
public static final String STATEMENT = "statement";
diff --git a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
index d6a3169..fd0da23 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
@@ -57,6 +57,7 @@ import java.util.Map;
import java.util.Set;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
+import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TYPE;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
public class LastQueryExecutor {
@@ -91,8 +92,10 @@ public class LastQueryExecutor {
ListDataSet dataSet =
new ListDataSet(
Arrays.asList(
- new PartialPath(COLUMN_TIMESERIES, false), new PartialPath(COLUMN_VALUE, false)),
- Arrays.asList(TSDataType.TEXT, TSDataType.TEXT));
+ new PartialPath(COLUMN_TIMESERIES, false),
+ new PartialPath(COLUMN_VALUE, false),
+ new PartialPath(COLUMN_TYPE, false)),
+ Arrays.asList(TSDataType.TEXT, TSDataType.TEXT, TSDataType.TEXT));
List<Pair<Boolean, TimeValuePair>> lastPairList =
calculateLastPairForSeries(selectedSeries, dataTypes, context, expression, lastQueryPlan);
@@ -117,6 +120,10 @@ public class LastQueryExecutor {
valueField.setBinaryV(new Binary(lastTimeValuePair.getValue().getStringValue()));
resultRecord.addField(valueField);
+ Field typeField = new Field(TSDataType.TEXT);
+ typeField.setBinaryV(new Binary(lastTimeValuePair.getValue().getDataType().name()));
+ resultRecord.addField(typeField);
+
dataSet.putRecord(resultRecord);
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
index 18cf2d9..15c2f0e 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/StaticResps.java
@@ -28,6 +28,7 @@ import java.util.Arrays;
import java.util.List;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TIMESERIES;
+import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_TYPE;
import static org.apache.iotdb.db.conf.IoTDBConstant.COLUMN_VALUE;
/** Static responses that won't change for all requests. */
@@ -39,8 +40,9 @@ class StaticResps {
static final TSExecuteStatementResp LAST_RESP =
getExecuteResp(
- Arrays.asList(COLUMN_TIMESERIES, COLUMN_VALUE),
- Arrays.asList(TSDataType.TEXT.toString(), TSDataType.TEXT.toString()),
+ Arrays.asList(COLUMN_TIMESERIES, COLUMN_VALUE, COLUMN_TYPE),
+ Arrays.asList(
+ TSDataType.TEXT.toString(), TSDataType.TEXT.toString(), TSDataType.TEXT.toString()),
false);
public static TSExecuteStatementResp getNoTimeExecuteResp(
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 2ab39c9..9be6e6b 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
@@ -516,7 +516,7 @@ public class IoTDBAsIT {
@Test
public void lastWithAsTest() throws ClassNotFoundException {
- String[] retArray = new String[] {"400,speed,50.4,", "400,root.sg.d1.s2,28.3,"};
+ String[] retArray = new String[] {"400,speed,50.4,FLOAT,", "400,root.sg.d1.s2,28.3,FLOAT,"};
Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection =
@@ -532,7 +532,7 @@ public class IoTDBAsIT {
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
header.append(resultSetMetaData.getColumnName(i)).append(",");
}
- assertEquals("Time,timeseries,value,", header.toString());
+ assertEquals("Time,timeseries,value,type,", header.toString());
int cnt = 0;
while (resultSet.next()) {
@@ -554,7 +554,9 @@ public class IoTDBAsIT {
@Test
public void lastWithAsDuplicatedTest() throws ClassNotFoundException {
String[] retArray =
- new String[] {"400,speed,50.4,", "400,root.sg.d1.s1,50.4,", "400,temperature,28.3,"};
+ new String[] {
+ "400,speed,50.4,FLOAT,", "400,root.sg.d1.s1,50.4,FLOAT,", "400,temperature,28.3,FLOAT,"
+ };
Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection =
@@ -571,7 +573,7 @@ public class IoTDBAsIT {
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
header.append(resultSetMetaData.getColumnName(i)).append(",");
}
- assertEquals("Time,timeseries,value,", header.toString());
+ assertEquals("Time,timeseries,value,type,", header.toString());
int cnt = 0;
while (resultSet.next()) {