You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/11/23 09:21:27 UTC

[GitHub] [iotdb] Plutooooooo opened a new pull request #4453: draft commit

Plutooooooo opened a new pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453


   ## Description
   
   
   ### Content1 ...
   
   ### Content2 ...
   
   ### Content3 ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767368297



##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/FunctionExpression.java
##########
@@ -111,13 +117,13 @@ public boolean isConstantOperandInternal() {
   }
 
   @Override
-  public boolean isUDAFExpression() {
-    return isUDAFExpression;
+  public boolean isTimeSeriesGeneratingFunctionExpression() {
+    return !isAggregationFunctionExpression;

Review comment:
       ```suggestion
       return !isPlainAggregationExpression() && !isUserDefinedAggregationExpression();
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] Plutooooooo commented on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
Plutooooooo commented on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-992070482


   My first PR in Apache IoTDB community, thanks for your help!@SteveYurongSu @ericpai 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762804083



##########
File path: docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1019,6 +1019,67 @@ select count(status) from root.ln.wf01.wt01 group by ([0,20),2ms,3ms), level=1;
 Total line number = 7
 It costs 0.004s
 ```
+#### 聚合查询嵌套表达式
+
+IoTDB 支持在 `select` 字句中执行由聚合查询和常量组成的任意嵌套表达式。
+
+**注意:**
+
+- 目前此功能尚不支持group by以及fill算子, 在后续版本会支持。
+- 表达式算术运算(+,-,*,/,%)不支持返回值为布尔类型以及文本类型的聚合函数

Review comment:
       ```suggestion
   - 目前此功能尚不支持 `group by` 以及 `fill` 算子, 在后续版本会支持。
   - 表达式算术运算 (`+`, `-`, `*`, `/`, `%`) 不支持返回值为布尔类型以及文本类型的聚合函数
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762805127



##########
File path: docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1019,6 +1019,67 @@ select count(status) from root.ln.wf01.wt01 group by ([0,20),2ms,3ms), level=1;
 Total line number = 7
 It costs 0.004s
 ```
+#### 聚合查询嵌套表达式

Review comment:
       You have to update the English doc as well :D




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44603596/badge)](https://coveralls.io/builds/44603596)
   
   Coverage increased (+0.08%) to 67.344% when pulling **70e5b030679bc9bea32b7e6742c9fa4e1ea282d7 on Plutooooooo:IOTDB-1973** into **098093a57decc3441eae2fc7964c8934df6aced8 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44480881/badge)](https://coveralls.io/builds/44480881)
   
   Coverage increased (+0.06%) to 67.266% when pulling **de23b50fa2ae14c0493ede8f00d3416362dc1746 on Plutooooooo:IOTDB-1973** into **bdebc923635d9703f14924204c4c7733fb14b2cf on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767369861



##########
File path: docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1051,7 +1050,29 @@ Total line number = 1
 It costs 0.009s
 ```
 
-指定 `GROUP BY` 的聚合查询。
+输入:
+
+```

Review comment:
       ```suggestion
   ```sql
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767369925



##########
File path: docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1045,6 +1045,28 @@ Total line number = 1
 It costs 0.009s
 ```
 
+Input:
+
+```

Review comment:
       ```suggestion
   ```sql
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44556297/badge)](https://coveralls.io/builds/44556297)
   
   Coverage increased (+0.08%) to 67.318% when pulling **717c6896a9c57d03f7e2e388ea3ccde9e7b2a2df on Plutooooooo:IOTDB-1973** into **14505c175a8c1e98535757027f36210b07de213c on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44603831/badge)](https://coveralls.io/builds/44603831)
   
   Coverage increased (+0.09%) to 67.357% when pulling **70e5b030679bc9bea32b7e6742c9fa4e1ea282d7 on Plutooooooo:IOTDB-1973** into **098093a57decc3441eae2fc7964c8934df6aced8 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44517502/badge)](https://coveralls.io/builds/44517502)
   
   Coverage increased (+0.001%) to 67.241% when pulling **b49b5268a4ce092607ee40d7ad0164bce2efeaa5 on Plutooooooo:IOTDB-1973** into **14505c175a8c1e98535757027f36210b07de213c on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767368056



##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/FunctionExpression.java
##########
@@ -111,13 +117,13 @@ public boolean isConstantOperandInternal() {
   }
 
   @Override
-  public boolean isUDAFExpression() {
-    return isUDAFExpression;
+  public boolean isTimeSeriesGeneratingFunctionExpression() {
+    return !isAggregationFunctionExpression;
   }
 
   @Override
-  public boolean isTimeSeriesGeneratingFunctionExpression() {
-    return !isAggregationFunctionExpression;
+  public boolean isUserDefinedAggregationExpression() {
+    return isUDAFExpression;

Review comment:
       ```suggestion
       return isUserDefinedAggregationExpression;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762813015



##########
File path: server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBUDTAIT.java
##########
@@ -0,0 +1,725 @@
+/*
+ * 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.integration.aggregation;
+
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.jdbc.Config;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.Locale;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.fail;
+
+public class IoTDBUDTAIT {

Review comment:
       Move it to the new integration module plz.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44779541/badge)](https://coveralls.io/builds/44779541)
   
   Coverage decreased (-0.01%) to 67.233% when pulling **a303ff432ee3ffd7ce70d52ace64425460b78eae on Plutooooooo:IOTDB-1973** into **45a665866ed830456d0d44ece0c02c37166e22fe on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44482073/badge)](https://coveralls.io/builds/44482073)
   
   Coverage increased (+0.01%) to 67.287% when pulling **055f4064ee20b8e437f6c5c7b13aaa7660b59aec on Plutooooooo:IOTDB-1973** into **046ac2d4c910e5386d102a8ee5aa99a4841b9184 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44680767/badge)](https://coveralls.io/builds/44680767)
   
   Coverage increased (+0.2%) to 67.426% when pulling **ad5dfd6c76fdfe0065064bec966cd80d8b91680a on Plutooooooo:IOTDB-1973** into **098093a57decc3441eae2fc7964c8934df6aced8 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762829002



##########
File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
##########
@@ -654,7 +655,7 @@ private TSExecuteStatementResp internalExecuteQueryStatement(
 
       TSExecuteStatementResp resp = null;
       // execute it before createDataSet since it may change the content of query plan
-      if (plan instanceof QueryPlan && !(plan instanceof UDFPlan)) {
+      if (plan instanceof QueryPlan && !(plan instanceof UDFPlan) && !(plan instanceof UDAFPlan)) {

Review comment:
       UDAFPlan implements UDFPlan

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDAFPlan.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.qp.physical.crud;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
+import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
+import org.apache.iotdb.db.query.expression.Expression;
+import org.apache.iotdb.db.query.expression.ResultColumn;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class UDAFPlan extends RawDataQueryPlan {

Review comment:
       ```suggestion
   public class UDAFPlan extends RawDataQueryPlan implements UDFPlan {
   ```

##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/binary/BinaryExpression.java
##########
@@ -60,9 +68,24 @@ public boolean isConstantOperandInternal() {
 
   @Override
   public boolean isTimeSeriesGeneratingFunctionExpression() {
+    if (isUDAFExpression()) {
+      return false;
+    }
     return true;

Review comment:
       ```suggestion
       return !isUDAFExpression();
   ```

##########
File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
##########
@@ -683,12 +684,14 @@ private TSExecuteStatementResp internalExecuteQueryStatement(
       if (plan instanceof ShowPlan || plan instanceof AuthorPlan) {
         resp = getListDataSetHeaders(newDataSet);
       } else if (plan instanceof UDFPlan
+          || plan instanceof UDAFPlan

Review comment:
       UDAFPlan implements UDFPlan

##########
File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
##########
@@ -860,6 +863,14 @@ private void getWideQueryHeaders(
         }
         seriesTypes = SchemaUtils.getSeriesTypesByPaths(paths, aggregations);
         break;
+      case UDAF:
+        seriesTypes = new ArrayList<>();
+        UDAFPlan udafPlan = (UDAFPlan) plan;

Review comment:
       It may be useless?

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/IQueryRouter.java
##########
@@ -44,6 +45,11 @@ QueryDataSet aggregate(AggregationPlan aggregationPlan, QueryContext context)
       throws QueryFilterOptimizationException, StorageEngineException, IOException,
           QueryProcessException;
 
+  /** Execute UDAF query. */
+  QueryDataSet udafQuery(UDAFPlan udafPlan, QueryContext context)

Review comment:
       Can the plan be executed in cluster mode?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767359334



##########
File path: docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1089,7 +1089,7 @@ It costs 0.012s
 > 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
 > SELECT avg(s1) + avg(s2) FROM root.sg.d1 GROUP BY([0, 10000), 1s) FILL(double [previous]); -- Automated fill 
-> ``` 
+> ```
 
 ### Automated Fill

Review comment:
       ![image](https://user-images.githubusercontent.com/30497621/145737694-866a1501-a031-4e70-a35a-0be89c989205.png)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu merged pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu merged pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767362301



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
##########
@@ -2651,7 +2651,8 @@ private boolean hasDecidedQueryType() {
         || queryOp instanceof FillQueryOperator
         || queryOp instanceof LastQueryOperator
         || queryOp instanceof AggregationQueryOperator
-        || queryOp instanceof UDFQueryOperator;
+        || queryOp instanceof UDFQueryOperator

Review comment:
       ```suggestion
           || queryOp instanceof UDTFQueryOperator
   ```
   
   We can rename `UDFQueryOperator` to `UDTFQueryOperator`, which is clearer.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/FunctionExpression.java
##########
@@ -56,6 +56,9 @@
 
 public class FunctionExpression extends Expression {
 
+  private final String WRONG_TYPE_MESSAGE =

Review comment:
       Remove it :D

##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/TimeSeriesOperand.java
##########
@@ -41,6 +41,8 @@
 import java.util.Set;
 
 public class TimeSeriesOperand extends Expression {
+  private final String WRONG_OPERAND_MESSAGE =

Review comment:
       Remove it.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java
##########
@@ -67,12 +67,13 @@ public boolean isConstantOperandInternal() {
 
   @Override
   public boolean isTimeSeriesGeneratingFunctionExpression() {
-    return true;
+    return !isUserDefinedAggregationExpression();
   }
 
   @Override
-  public boolean isUDAFExpression() {
-    return expression.isUDAFExpression() || expression.isAggregationFunctionExpression();
+  public boolean isUserDefinedAggregationExpression() {
+    return expression.isUserDefinedAggregationExpression()
+        || expression.isPlainAggregationFunctionExpression();

Review comment:
       ```suggestion
           || expression.isPlainAggregationExpression();
   ```

##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/ConstantOperand.java
##########
@@ -41,6 +41,8 @@
 
 /** Constant operand */
 public class ConstantOperand extends Expression {
+  private final String WRONG_TYPE_MESSAGE =

Review comment:
       Remove it since it is useless :D

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
##########
@@ -102,7 +102,11 @@ protected void initQueryDataSetFields(
     this.columnNum = 0;
     if (paths != null) {
       for (Path p : paths) {
-        columnNum += p.getColumnNum();
+        // Path could be null in certain kinds of plans such as UDAFPlan, thus `p != null` is

Review comment:
       Could we remove the judgment?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767384266



##########
File path: docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1116,7 +1137,6 @@ select <path> from <prefixPath> where time = <T> fill(<data_type>[previous, <bef
 表 3-4 给出了所有参数的详细说明。
 
 <center>
-
 **表 3-4previous 填充参数列表**

Review comment:
       ```suggestion
   
   **表 3-4previous 填充参数列表**
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls commented on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44479892/badge)](https://coveralls.io/builds/44479892)
   
   Coverage increased (+0.08%) to 67.285% when pulling **c5dd7296819322d225dc3ef109fee7e3a66f3b1e on Plutooooooo:IOTDB-1973** into **bdebc923635d9703f14924204c4c7733fb14b2cf on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44482009/badge)](https://coveralls.io/builds/44482009)
   
   Coverage decreased (-0.06%) to 67.212% when pulling **055f4064ee20b8e437f6c5c7b13aaa7660b59aec on Plutooooooo:IOTDB-1973** into **046ac2d4c910e5386d102a8ee5aa99a4841b9184 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767367938



##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/FunctionExpression.java
##########
@@ -97,11 +100,14 @@ public FunctionExpression(
     isConstantOperandCache = expressions.stream().anyMatch(Expression::isConstantOperand);
     isUDAFExpression =
         expressions.stream()
-            .anyMatch(v -> v.isUDAFExpression() || v.isAggregationFunctionExpression());
+            .anyMatch(
+                v ->
+                    v.isUserDefinedAggregationExpression()
+                        || v.isPlainAggregationFunctionExpression());
   }
 
   @Override
-  public boolean isAggregationFunctionExpression() {
+  public boolean isPlainAggregationFunctionExpression() {
     return isAggregationFunctionExpression;
   }

Review comment:
       ```suggestion
     public boolean isPlainAggregationFunctionExpression() {
       return isPlainAggregationFunctionExpression;
     }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44502262/badge)](https://coveralls.io/builds/44502262)
   
   Coverage increased (+0.006%) to 67.246% when pulling **742affcdb9d4f744dd555f63523578bead47e904 on Plutooooooo:IOTDB-1973** into **14505c175a8c1e98535757027f36210b07de213c on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762852515



##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/unary/NegationExpression.java
##########
@@ -61,7 +61,12 @@ public boolean isConstantOperandInternal() {
 
   @Override
   public boolean isTimeSeriesGeneratingFunctionExpression() {
-    return true;
+    return !isUDAFExpression();
+  }
+
+  @Override
+  public boolean isUDAFExpression() {

Review comment:
       ```suggestion
     public boolean isUserDefinedAggragationFunctionExpression() {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762851064



##########
File path: server/src/main/java/org/apache/iotdb/db/query/expression/binary/BinaryExpression.java
##########
@@ -48,6 +48,14 @@
   protected final Expression leftExpression;
   protected final Expression rightExpression;
 
+  public Expression getLeftExpression() {
+    return leftExpression;
+  }
+
+  public Expression getRightExpression() {
+    return rightExpression;
+  }

Review comment:
       ```suggestion
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-976463651


   
   [![Coverage Status](https://coveralls.io/builds/44779724/badge)](https://coveralls.io/builds/44779724)
   
   Coverage decreased (-0.01%) to 67.231% when pulling **a303ff432ee3ffd7ce70d52ace64425460b78eae on Plutooooooo:IOTDB-1973** into **45a665866ed830456d0d44ece0c02c37166e22fe on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762804595



##########
File path: docs/zh/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1019,6 +1019,67 @@ select count(status) from root.ln.wf01.wt01 group by ([0,20),2ms,3ms), level=1;
 Total line number = 7
 It costs 0.004s
 ```
+#### 聚合查询嵌套表达式
+
+IoTDB 支持在 `select` 字句中执行由聚合查询和常量组成的任意嵌套表达式。
+
+**注意:**
+
+- 目前此功能尚不支持group by以及fill算子, 在后续版本会支持。
+- 表达式算术运算(+,-,*,/,%)不支持返回值为布尔类型以及文本类型的聚合函数
+
+##### 语法
+
+下面是聚合查询嵌套表达式子句的语法定义:
+
+```sql
+selectClause
+    : SELECT resultColumn (',' resultColumn)*
+    ;
+
+resultColumn
+    : expression (AS ID)?
+    ;
+
+expression
+    : '(' expression ')'
+    | '-' expression
+    | expression ('*' | '/' | '%') expression
+    | expression ('+' | '-') expression
+    | functionName '('timeSeriesSuffixPath')'
+    | number
+    ;
+```
+
+##### 示例
+
+输入:
+
+```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;
+```
+
+结果:
+
+```
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+
+|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) / c
+ount(root.sg.b))|
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+
+|               4|               3|                                           2.5|                                                                                                    -8
+2.66666666666667|
++----------------+----------------+----------------------------------------------+------------------------------------------------------------------------------------------------------
+----------------+

Review comment:
       hmm.. something's wrong with the format.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r762832726



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/QueryDataSet.java
##########
@@ -102,7 +102,9 @@ protected void initQueryDataSetFields(
     this.columnNum = 0;
     if (paths != null) {
       for (Path p : paths) {
-        columnNum += p.getColumnNum();
+        if (p != null) {

Review comment:
       ```suggestion
           if (p != null) {
   ```
   Please add some comments here.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#issuecomment-992069112


   This PR is a follow-up to #4517 and focuses on code optimization, testing, and documentation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767359334



##########
File path: docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1089,7 +1089,7 @@ It costs 0.012s
 > 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
 > SELECT avg(s1) + avg(s2) FROM root.sg.d1 GROUP BY([0, 10000), 1s) FILL(double [previous]); -- Automated fill 
-> ``` 
+> ```
 
 ### Automated Fill

Review comment:
       ![Uploading image.png…]()
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #4453: [IOTDB-1973] Supports aggregate queries, constants, and arithmetic nested expressions in SELECT clauses

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #4453:
URL: https://github.com/apache/iotdb/pull/4453#discussion_r767384906



##########
File path: docs/UserGuide/IoTDB-SQL-Language/DML-Data-Manipulation-Language.md
##########
@@ -1109,10 +1131,11 @@ select <path> from <prefixPath> where time = <T> fill(<data_type>[previous, <bef
 
 Detailed descriptions of all parameters are given in Table 3-4.
 
-<center>
+<center

Review comment:
       ```suggestion
   <center>
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org