You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/01/17 11:44:06 UTC

[iotdb] branch master updated: [IOTDB-2377] Modify description of nested expressions in User Guide (#4857)

This is an automated email from the ASF dual-hosted git repository.

rong 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 82928e9  [IOTDB-2377] Modify description of nested expressions in User Guide (#4857)
82928e9 is described below

commit 82928e9f1eb6132f121dd7a1f15a8121fb284330
Author: LLY <48...@users.noreply.github.com>
AuthorDate: Mon Jan 17 19:43:28 2022 +0800

    [IOTDB-2377] Modify description of nested expressions in User Guide (#4857)
---
 .../DML-Data-Manipulation-Language.md              | 245 +++++++++++++-------
 .../DML-Data-Manipulation-Language.md              | 247 ++++++++++++++-------
 2 files changed, 337 insertions(+), 155 deletions(-)

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 1c647eb..749dfa3 100644
--- a/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
+++ b/docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
@@ -548,63 +548,6 @@ Known Implementation UDF Libraries:
 
 + [IoTDB-Quality](https://thulab.github.io/iotdb-quality), a UDF library about data quality, including data profiling, data quality evalution and data repairing, etc.
 
-### Nested Expressions
-
-IoTDB supports the execution of arbitrary nested expressions consisting of **numbers, time series, arithmetic expressions, and time series generating functions (including user-defined functions)** in the `select` clause.
-
-> Please note that Aligned Timeseries has not been supported in Nested Expressions yet. An error message is expected if you use Nested Expressions with Aligned Timeseries selected in a query statement.
-
-#### Syntax
-
-The following is the syntax definition of the `select` clause:
-
-```sql
-selectClause
-    : SELECT resultColumn (',' resultColumn)*
-    ;
-
-resultColumn
-    : expression (AS ID)?
-    ;
-
-expression
-    : '(' expression ')'
-    | '-' expression
-    | expression ('*' | '/' | '%') expression
-    | expression ('+' | '-') expression
-    | functionName '(' expression (',' expression)* functionAttribute* ')'
-    | timeSeriesSuffixPath
-    | number
-    ;
-```
-
-#### Example
-
-SQL:
-
-```sql
-select a,
-       b,
-       ((a + 1) * 2 - 1) % 2 + 1.5,
-       sin(a + sin(a + sin(b))),
-       -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b))
-from root.sg1.d1;
-```
-
-Result:
-
-```
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-|                         Time|root.sg1.d1.a|root.sg1.d1.b|((((root.sg1.d1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.d1.a + sin(root.sg1.d1.a + sin(root.sg1.d1.b)))|-root.sg1.d1.a + root.sg1.d1.b * ((sin(root.sg1.d1.a + root.sg1.d1.b) * sin(root.sg1.d1.a + root.sg1.d1.b)) + (cos(root.sg1.d1.a + root.sg1.d1.b) * cos(root.sg1.d1.a + root.sg1.d1.b)))|
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-|1970-01-01T08:00:00.000+08:00|            0|            0|                                        2.5|                                                         0.0|                                                                                                                                                                                    -0.0|
-|1970-01-01T08:00:00.001+08:00|            1|            1|                                        2.5|                                          0.9238430524420609|                                                                                                                                                                                    -2.0|
-|1970-01-01T08:00:00.002+08:00|            2|            2|                                        2.5|                                          0.7903505371876317|                                                                                                                                                                                    -4.0|
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-Total line number = 3
-It costs 0.170s
-```
-
 ### Fill Null Value
 
 In the actual use of IoTDB, when doing the query operation of timeseries, situations where the value is null at some time points may appear, which will obstruct the further analysis by users. In order to better reflect the degree of data change, users expect missing values to be filled. Therefore, the IoTDB system introduces fill methods.
@@ -1399,15 +1342,159 @@ Total line number = 7
 It costs 0.004s
 ```
 
+### Nested Expressions
+
+IoTDB supports the calculation of arbitrary nested expressions. Since time series query and aggregation query can not be used in a query statement at the same time, we divide nested expressions into two types, which are nested expressions with time series query and nested expressions with aggregation query. 
+
+The following is the syntax definition of the `select` clause:
+
+```sql
+selectClause
+    : SELECT resultColumn (',' resultColumn)*
+    ;
+
+resultColumn
+    : expression (AS ID)?
+    ;
+
+expression
+    : '(' expression ')'
+    | '-' expression
+    | expression ('*' | '/' | '%') expression
+    | expression ('+' | '-') expression
+    | functionName '(' expression (',' expression)* functionAttribute* ')'
+    | timeSeriesSuffixPath
+    | number
+    ;
+```
+
+#### Nested Expressions with Time Series Query
+
+IoTDB supports the calculation of arbitrary nested expressions consisting of **numbers, time series, time series generating functions (including user-defined functions) and arithmetic expressions** in the `select` clause.
+
+##### Example
+
+Input1:
+
+```sql
+select a,
+       b,
+       ((a + 1) * 2 - 1) % 2 + 1.5,
+       sin(a + sin(a + sin(b))),
+       -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1
+from root.sg1;
+```
+
+Result1:
+
+```
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+|                         Time|root.sg1.a|root.sg1.b|((((root.sg1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.a + sin(root.sg1.a + sin(root.sg1.b)))|(-root.sg1.a + root.sg1.b * ((sin(root.sg1.a + root.sg1.b) * sin(root.sg1.a + root.sg1.b)) + (cos(root.sg1.a + root.sg1.b) * cos(root.sg1.a + root.sg1.b)))) + 1|
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+|1970-01-01T08:00:00.010+08:00|         1|         1|                                     2.5|                                 0.9238430524420609|                                                                                                                      -1.0|
+|1970-01-01T08:00:00.020+08:00|         2|         2|                                     2.5|                                 0.7903505371876317|                                                                                                                      -3.0|
+|1970-01-01T08:00:00.030+08:00|         3|         3|                                     2.5|                                0.14065207680386618|                                                                                                                      -5.0|
+|1970-01-01T08:00:00.040+08:00|         4|      null|                                     2.5|                                               null|                                                                                                                      null|
+|1970-01-01T08:00:00.050+08:00|      null|         5|                                    null|                                               null|                                                                                                                      null|
+|1970-01-01T08:00:00.060+08:00|         6|         6|                                     2.5|                                -0.7288037411970916|                                                                                                                     -11.0|
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+Total line number = 6
+It costs 0.048s
+```
+
+Input2:
+
+```sql
+select (a + b) * 2 + sin(a) from root.sg
+```
+
+Result2:
+
+```
++-----------------------------+----------------------------------------------+
+|                         Time|((root.sg.a + root.sg.b) * 2) + sin(root.sg.a)|
++-----------------------------+----------------------------------------------+
+|1970-01-01T08:00:00.010+08:00|                             59.45597888911063|
+|1970-01-01T08:00:00.020+08:00|                            100.91294525072763|
+|1970-01-01T08:00:00.030+08:00|                            139.01196837590714|
+|1970-01-01T08:00:00.040+08:00|                            180.74511316047935|
+|1970-01-01T08:00:00.050+08:00|                            219.73762514629607|
+|1970-01-01T08:00:00.060+08:00|                             259.6951893788978|
+|1970-01-01T08:00:00.070+08:00|                             300.7738906815579|
+|1970-01-01T08:00:00.090+08:00|                             39.45597888911063|
+|1970-01-01T08:00:00.100+08:00|                             39.45597888911063|
++-----------------------------+----------------------------------------------+
+Total line number = 9
+It costs 0.011s
+```
+
+Input3:
+
+```sql
+select (a + *) / 2  from root.sg1
+```
+
+Result3:
+
+```
++-----------------------------+-----------------------------+-----------------------------+
+|                         Time|(root.sg1.a + root.sg1.a) / 2|(root.sg1.a + root.sg1.b) / 2|
++-----------------------------+-----------------------------+-----------------------------+
+|1970-01-01T08:00:00.010+08:00|                          1.0|                          1.0|
+|1970-01-01T08:00:00.020+08:00|                          2.0|                          2.0|
+|1970-01-01T08:00:00.030+08:00|                          3.0|                          3.0|
+|1970-01-01T08:00:00.040+08:00|                          4.0|                         null|
+|1970-01-01T08:00:00.060+08:00|                          6.0|                          6.0|
++-----------------------------+-----------------------------+-----------------------------+
+Total line number = 5
+It costs 0.011s
+```
+
+Input4:
+
+```sql
+select (a + b) * 3 from root.sg, root.ln
+```
+
+Result4:
+
+```
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+|                         Time|(root.sg.a + root.sg.b) * 3|(root.sg.a + root.ln.b) * 3|(root.ln.a + root.sg.b) * 3|(root.ln.a + root.ln.b) * 3|
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+|1970-01-01T08:00:00.010+08:00|                       90.0|                      270.0|                      360.0|                      540.0|
+|1970-01-01T08:00:00.020+08:00|                      150.0|                      330.0|                      690.0|                      870.0|
+|1970-01-01T08:00:00.030+08:00|                      210.0|                      450.0|                      570.0|                      810.0|
+|1970-01-01T08:00:00.040+08:00|                      270.0|                      240.0|                      690.0|                      660.0|
+|1970-01-01T08:00:00.050+08:00|                      330.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.060+08:00|                      390.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.070+08:00|                      450.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.090+08:00|                       60.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.100+08:00|                       60.0|                       null|                       null|                       null|
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+Total line number = 9
+It costs 0.014s
+```
+
+##### Explanation
+
+- Only when the left operand and the right operand under a certain timestamp are not `null`, the nested expressions will have an output value. Otherwise this row will not be included in the result. 
+  - In Result1 of the Example part, the value of time series `root.sg.a` at time 40 is 4, while the value of time series `root.sg.b` is `null`. So at time 40, the value of nested expressions `(a + b) * 2 + sin(a)` is `null`. So in Result2, this row is not included in the result.
+- If one operand in the nested expressions can be translated into multiple time series (For example, `*`), the result of each time series will be included in the result (Cartesian product). Please refer to Input3, Input4 and corresponding Result3 and Result4 in Example.
+
+##### Note
+
+> Please note that Aligned Time Series has not been supported in Nested Expressions with Time Series Query yet. An error message is expected if you use it with Aligned Time Series selected in a query statement.
+
 #### Nested Expressions query with aggregations
 
-IoTDB supports aggregation query nested by any other expressions.
+IoTDB supports the calculation of arbitrary nested expressions consisting of **numbers, aggregations and arithmetic expressions** in the `select` clause.
 
 ##### Example
 
-1. Aggregation query without `GROUP BY`.
+Aggregation query without `GROUP BY`.
 
-Input:
+Input1:
 
 ```sql
 select avg(temperature),
@@ -1418,7 +1505,7 @@ select avg(temperature),
 from root.ln.wf01.wt01;
 ```
 
-Result:
+Result1:
 
 ```
 +----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+
@@ -1430,31 +1517,29 @@ Total line number = 1
 It costs 0.009s
 ```
 
-Input:
+Input2:
 
 ```sql
-select count(a),
-       count(b),
-       ((count(a) + 1) * 2 - 1) % 2 + 1.5,
-       -(count(a) + count(b)) * (count(a) * count(b)) + count(a) / count(b)
-from root.sg;
+select avg(*), 
+	   (avg(*) + 1) * 3 / 2 -1 
+from root.sg1
 ```
 
-Result:
+Result2:
 
 ```
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
-|count(root.sg.a)|count(root.sg.b)|((((count(root.sg.a) + 1) * 2) - 1) % 2) + 1.5|(-count(root.sg.a) + count(root.sg.b) * (count(root.sg.a) * count(root.sg.b))) + (count(root.sg.a) / count(root.sg.b))|
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
-|               4|               3|                                           2.5|                                                                                                    -82.66666666666667|
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
++---------------+---------------+-------------------------------------+-------------------------------------+
+|avg(root.sg1.a)|avg(root.sg1.b)|(((avg(root.sg1.a) + 1) * 3) / 2) - 1|(((avg(root.sg1.b) + 1) * 3) / 2) - 1|
++---------------+---------------+-------------------------------------+-------------------------------------+
+|            3.2|            3.4|                    5.300000000000001|                   5.6000000000000005|
++---------------+---------------+-------------------------------------+-------------------------------------+
 Total line number = 1
-It costs 0.013s
+It costs 0.007s
 ```
 
-2. Aggregation with `GROUP BY`.
+Aggregation with `GROUP BY`.
 
-Input:
+Input3:
 
 ```sql
 select avg(temperature),
@@ -1466,7 +1551,7 @@ from root.ln.wf01.wt01
 GROUP BY([10, 90), 10ms);
 ```
 
-Result:
+Result3:
 
 ```
 +-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+
@@ -1485,6 +1570,11 @@ Total line number = 8
 It costs 0.012s
 ```
 
+##### Explanation
+
+- Only when the left operand and the right operand under a certain timestamp are not `null`, the nested expressions will have an output value. Otherwise this row will not be included in the result. But for nested expressions with `GROUP BY` clause, it is better to show the result of all time intervals. Please refer to Input3 and corresponding Result3 in Example.
+- If one operand in the nested expressions can be translated into multiple time series (For example, `*`), the result of each time series will be included in the result (Cartesian product). Please refer to Input2 and corresponding Result2 in Example.
+
 ##### Note
 
 > Automated fill (`FILL`) and grouped by level (`GROUP BY LEVEL`) are not supported in an aggregation query with expression nested. They may be supported in future versions.
@@ -1492,6 +1582,7 @@ It costs 0.012s
 > The aggregation expression must be the lowest level input of one expression tree. Any kind expressions except timeseries are not valid as aggregation function parameters。
 >
 > In a word, the following queries are not valid.
+>
 > ```sql
 > SELECT avg(s1+1) FROM root.sg.d1; -- The aggregation function has expression parameters.
 > SELECT avg(s1) + avg(s2) FROM root.sg.* GROUP BY LEVEL=1; -- Grouped by level
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 e93a529..8807ba8 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
@@ -560,63 +560,6 @@ It costs 0.078s
 
 + [IoTDB-Quality](https://thulab.github.io/iotdb-quality),一个关于数据质量的 UDF 库实现,包括数据画像、数据质量评估与修复等一系列函数。
 
-### 嵌套表达式
-
-IoTDB 支持在 `select` 字句中执行由**数字常量,时间序列、算数运算表达式和时间序列生成函数(包括用户自定义函数)**组成的任意嵌套表达式。
-
-> 请注意,目前对齐时间序列(Aligned Timeseries)尚不支持嵌套表达式查询。使用嵌套表达式时,如果操作数包含对齐时间序列,会提示错误。
-
-#### 语法
-
-下面是 `select` 子句的语法定义:
-
-```sql
-selectClause
-    : SELECT resultColumn (',' resultColumn)*
-    ;
-
-resultColumn
-    : expression (AS ID)?
-    ;
-
-expression
-    : '(' expression ')'
-    | '-' expression
-    | expression ('*' | '/' | '%') expression
-    | expression ('+' | '-') expression
-    | functionName '(' expression (',' expression)* functionAttribute* ')'
-    | timeSeriesSuffixPath
-    | number
-    ;
-```
-
-#### 示例
-
-输入:
-
-```sql
-select a,
-       b,
-       ((a + 1) * 2 - 1) % 2 + 1.5,
-       sin(a + sin(a + sin(b))),
-       -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b))
-from root.sg1.d1;
-```
-
-结果:
-
-```
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-|                         Time|root.sg1.d1.a|root.sg1.d1.b|((((root.sg1.d1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.d1.a + sin(root.sg1.d1.a + sin(root.sg1.d1.b)))|-root.sg1.d1.a + root.sg1.d1.b * ((sin(root.sg1.d1.a + root.sg1.d1.b) * sin(root.sg1.d1.a + root.sg1.d1.b)) + (cos(root.sg1.d1.a + root.sg1.d1.b) * cos(root.sg1.d1.a + root.sg1.d1.b)))|
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-|1970-01-01T08:00:00.000+08:00|            0|            0|                                        2.5|                                                         0.0|                                                                                                                                                                                    -0.0|
-|1970-01-01T08:00:00.001+08:00|            1|            1|                                        2.5|                                          0.9238430524420609|                                                                                                                                                                                    -2.0|
-|1970-01-01T08:00:00.002+08:00|            2|            2|                                        2.5|                                          0.7903505371876317|                                                                                                                                                                                    -4.0|
-+-----------------------------+-------------+-------------+-------------------------------------------+------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
-Total line number = 3
-It costs 0.170s
-```
-
 ### 空值填充
 
 在 IoTDB 的实际使用中,当进行时间序列的查询操作时,可能会出现在某些时间点值为 null 的情况,这会妨碍用户进行进一步的分析。 为了更好地反映数据更改的程度,用户希望可以自动填充缺失值。 因此,IoTDB 系统引入了自动填充功能。
@@ -1419,15 +1362,159 @@ select count(status) from root.ln.wf01.wt01 group by ([2017-11-01 00:00:00, 2017
 Total line number = 7
 It costs 0.004s
 ```
+### 嵌套表达式
+
+IoTDB支持嵌套表达式,由于聚合查询和时间序列查询不能在一条查询语句中同时出现,我们将支持的嵌套表达式分为时间序列查询嵌套表达式和聚合查询嵌套表达式两类。
+
+下面是嵌套表达式统一的 `SELECT` 子句语法定义:
+
+```sql
+selectClause
+    : SELECT resultColumn (',' resultColumn)*
+    ;
+
+resultColumn
+    : expression (AS ID)?
+    ;
+
+expression
+    : '(' expression ')'
+    | '-' expression
+    | expression ('*' | '/' | '%') expression
+    | expression ('+' | '-') expression
+    | functionName '(' expression (',' expression)* functionAttribute* ')'
+    | timeSeriesSuffixPath
+    | number
+    ;
+```
+
+#### 时间序列查询嵌套表达式
+
+IoTDB 支持在 `SELECT` 子句中计算由**数字常量,时间序列、时间序列生成函数(包括用户自定义函数)和算数运算表达式**组成的任意嵌套表达式。
+
+##### 示例
+
+输入1:
+
+```sql
+select a,
+       b,
+       ((a + 1) * 2 - 1) % 2 + 1.5,
+       sin(a + sin(a + sin(b))),
+       -(a + b) * (sin(a + b) * sin(a + b) + cos(a + b) * cos(a + b)) + 1
+from root.sg1;
+```
+
+结果集1:
+
+```
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+|                         Time|root.sg1.a|root.sg1.b|((((root.sg1.a + 1) * 2) - 1) % 2) + 1.5|sin(root.sg1.a + sin(root.sg1.a + sin(root.sg1.b)))|(-root.sg1.a + root.sg1.b * ((sin(root.sg1.a + root.sg1.b) * sin(root.sg1.a + root.sg1.b)) + (cos(root.sg1.a + root.sg1.b) * cos(root.sg1.a + root.sg1.b)))) + 1|
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+|1970-01-01T08:00:00.010+08:00|         1|         1|                                     2.5|                                 0.9238430524420609|                                                                                                                      -1.0|
+|1970-01-01T08:00:00.020+08:00|         2|         2|                                     2.5|                                 0.7903505371876317|                                                                                                                      -3.0|
+|1970-01-01T08:00:00.030+08:00|         3|         3|                                     2.5|                                0.14065207680386618|                                                                                                                      -5.0|
+|1970-01-01T08:00:00.040+08:00|         4|      null|                                     2.5|                                               null|                                                                                                                      null|
+|1970-01-01T08:00:00.050+08:00|      null|         5|                                    null|                                               null|                                                                                                                      null|
+|1970-01-01T08:00:00.060+08:00|         6|         6|                                     2.5|                                -0.7288037411970916|                                                                                                                     -11.0|
++-----------------------------+----------+----------+----------------------------------------+---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
+Total line number = 6
+It costs 0.048s
+```
+
+输入2:
+
+```sql
+select (a + b) * 2 + sin(a) from root.sg
+```
+
+结果集2:
+
+```
++-----------------------------+----------------------------------------------+
+|                         Time|((root.sg.a + root.sg.b) * 2) + sin(root.sg.a)|
++-----------------------------+----------------------------------------------+
+|1970-01-01T08:00:00.010+08:00|                             59.45597888911063|
+|1970-01-01T08:00:00.020+08:00|                            100.91294525072763|
+|1970-01-01T08:00:00.030+08:00|                            139.01196837590714|
+|1970-01-01T08:00:00.040+08:00|                            180.74511316047935|
+|1970-01-01T08:00:00.050+08:00|                            219.73762514629607|
+|1970-01-01T08:00:00.060+08:00|                             259.6951893788978|
+|1970-01-01T08:00:00.070+08:00|                             300.7738906815579|
+|1970-01-01T08:00:00.090+08:00|                             39.45597888911063|
+|1970-01-01T08:00:00.100+08:00|                             39.45597888911063|
++-----------------------------+----------------------------------------------+
+Total line number = 9
+It costs 0.011s
+```
+
+输入3:
+
+```sql
+select (a + *) / 2  from root.sg1
+```
+
+结果集3:
+
+```
++-----------------------------+-----------------------------+-----------------------------+
+|                         Time|(root.sg1.a + root.sg1.a) / 2|(root.sg1.a + root.sg1.b) / 2|
++-----------------------------+-----------------------------+-----------------------------+
+|1970-01-01T08:00:00.010+08:00|                          1.0|                          1.0|
+|1970-01-01T08:00:00.020+08:00|                          2.0|                          2.0|
+|1970-01-01T08:00:00.030+08:00|                          3.0|                          3.0|
+|1970-01-01T08:00:00.040+08:00|                          4.0|                         null|
+|1970-01-01T08:00:00.060+08:00|                          6.0|                          6.0|
++-----------------------------+-----------------------------+-----------------------------+
+Total line number = 5
+It costs 0.011s
+```
+
+输入4:
+
+```sql
+select (a + b) * 3 from root.sg, root.ln
+```
+
+结果集4:
+
+```
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+|                         Time|(root.sg.a + root.sg.b) * 3|(root.sg.a + root.ln.b) * 3|(root.ln.a + root.sg.b) * 3|(root.ln.a + root.ln.b) * 3|
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+|1970-01-01T08:00:00.010+08:00|                       90.0|                      270.0|                      360.0|                      540.0|
+|1970-01-01T08:00:00.020+08:00|                      150.0|                      330.0|                      690.0|                      870.0|
+|1970-01-01T08:00:00.030+08:00|                      210.0|                      450.0|                      570.0|                      810.0|
+|1970-01-01T08:00:00.040+08:00|                      270.0|                      240.0|                      690.0|                      660.0|
+|1970-01-01T08:00:00.050+08:00|                      330.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.060+08:00|                      390.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.070+08:00|                      450.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.090+08:00|                       60.0|                       null|                       null|                       null|
+|1970-01-01T08:00:00.100+08:00|                       60.0|                       null|                       null|                       null|
++-----------------------------+---------------------------+---------------------------+---------------------------+---------------------------+
+Total line number = 9
+It costs 0.014s
+```
+
+##### 说明
+
+- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。
+  - 从结果集1中可知,时间戳40下,时间序列`root.sg.a`的值为4,`root.sg.b`的值为`null`。所以在时间戳40下,表达式`(a + b) * 2 + sin(a)`的值为`null`,从结果集2可以看出,时间戳40没有出现。
+- 如果表达式中某个操作数对应多条时间序列(如通配符`*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。请参考示例中输入3、4和对应结果集3、4。
+
+##### 注意
+
+> 目前对齐时间序列(Aligned Timeseries)尚不支持时间序列查询嵌套表达式。使用时间序列查询嵌套表达式时,如果操作数包含对齐时间序列,会提示错误。
+
 #### 聚合查询嵌套表达式
 
-IoTDB 支持在 `SELECT` 字句中执行由聚合查询和其他运算组成的任意嵌套表达式。
+IoTDB 支持在 `SELECT` 子句中计算由**数字常量,聚合查询和算数运算表达式**组成的任意嵌套表达式。
 
 ##### 示例
 
-1. 不指定 `GROUP BY` 的聚合查询。
+不指定 `GROUP BY` 的聚合查询。
 
-输入:
+输入1:
 
 ```sql
 select avg(temperature),
@@ -1438,7 +1525,7 @@ select avg(temperature),
 from root.ln.wf01.wt01;
 ```
 
-结果:
+结果集1:
 
 ```
 +----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+--------------------------------------------------------------------+
@@ -1450,31 +1537,29 @@ Total line number = 1
 It costs 0.009s
 ```
 
-输入:
+输入2:
 
 ```sql
-select count(a),
-       count(b),
-       ((count(a) + 1) * 2 - 1) % 2 + 1.5,
-       -(count(a) + count(b)) * (count(a) * count(b)) + count(a) / count(b)
-from root.sg;
+select avg(*), 
+	   (avg(*) + 1) * 3 / 2 -1 
+from root.sg1
 ```
 
-结果:
+结果集2:
 
 ```
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
-|count(root.sg.a)|count(root.sg.b)|((((count(root.sg.a) + 1) * 2) - 1) % 2) + 1.5|(-count(root.sg.a) + count(root.sg.b) * (count(root.sg.a) * count(root.sg.b))) + (count(root.sg.a) / count(root.sg.b))|
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
-|               4|               3|                                           2.5|                                                                                                    -82.66666666666667|
-+----------------+----------------+----------------------------------------------+----------------------------------------------------------------------------------------------------------------------+
++---------------+---------------+-------------------------------------+-------------------------------------+
+|avg(root.sg1.a)|avg(root.sg1.b)|(((avg(root.sg1.a) + 1) * 3) / 2) - 1|(((avg(root.sg1.b) + 1) * 3) / 2) - 1|
++---------------+---------------+-------------------------------------+-------------------------------------+
+|            3.2|            3.4|                    5.300000000000001|                   5.6000000000000005|
++---------------+---------------+-------------------------------------+-------------------------------------+
 Total line number = 1
-It costs 0.013s
+It costs 0.007s
 ```
 
-2. 指定 `GROUP BY` 的聚合查询。
+指定 `GROUP BY` 的聚合查询。
 
-输入:
+输入3:
 
 ```sql
 select avg(temperature),
@@ -1486,7 +1571,7 @@ from root.ln.wf01.wt01
 GROUP BY([10, 90), 10ms);
 ```
 
-结果:
+结果集3:
 
 ```
 +-----------------------------+----------------------------------+---------------------------------------+--------------------------------------+--------------------------------+----------+
@@ -1505,6 +1590,11 @@ Total line number = 8
 It costs 0.012s
 ```
 
+##### 说明
+
+- 当某个时间戳下左操作数和右操作数都不为空(`null`)时,表达式才会有结果,否则表达式值为`null`,且默认不出现在结果集中。但在使用`GROUP BY`子句的聚合查询嵌套表达式中,我们希望保留每个时间窗口的值,所以表达式值为`null`的窗口也包含在结果集中。请参考输入3及结果集3。
+- 如果表达式中某个操作数对应多条时间序列(如通配符`*`),那么每条时间序列对应的结果都会出现在结果集中(按照笛卡尔积形式)。请参考输入2及结果集2。
+
 ##### 注意
 
 > 目前此功能尚不支持填充算子(`FILL`)和按层级聚合(`GROUP BY LEVEL`)查询, 在后续版本会支持。
@@ -1512,8 +1602,9 @@ It costs 0.012s
 > 聚合计算目前只能当做最底层表达式输入,暂不支持聚合函数内部出现表达式。
 >
 > 即不支持以下查询
+>
 > ```SQL
-> SELECT avg(s1+1) FROM root.sg.d1; -- 聚合函数内部有表达式
+> SELECT avg(s1 + 1) FROM root.sg.d1; -- 聚合函数内部有表达式
 > SELECT avg(s1) + avg(s2) FROM root.sg.* GROUP BY LEVEL=1; -- 按层级聚合
 > SELECT avg(s1) + avg(s2) FROM root.sg.d1 GROUP BY([0, 10000), 1s) FILL(previous); -- 空值填充 
 > ```