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 2020/03/23 11:59:23 UTC

[GitHub] [incubator-iotdb] samperson1997 commented on a change in pull request #936: modify eng system design

samperson1997 commented on a change in pull request #936: modify eng system design
URL: https://github.com/apache/incubator-iotdb/pull/936#discussion_r396395636
 
 

 ##########
 File path: docs/Documentation/SystemDesign/5-DataQuery/4-AggregationQuery.md
 ##########
 @@ -0,0 +1,114 @@
+<!--
+
+    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.
+
+-->
+
+# Aggregation query
+
+The main logic of the aggregation query is in AggregateExecutor
+
+* org.apache.iotdb.db.query.executor.AggregationExecutor
+
+## Aggregation query without value filter
+
+For aggregate queries without value filters, the results are obtained by the `executeWithoutValueFilter()` method and a dataSet is constructed. First use the `mergeSameSeries()` method to merge aggregate queries for the same time series. For example: if you need to calculate count(s1), sum(s2), count(s3), sum(s1), you need to calculate two aggregation values of s1, then the pathToAggrIndexesMap result will be: s1-> 0, 3; s2-> 1; s3-> 2.
+
+Then you will get `pathToAggrIndexesMap`, where each entry is an aggregate query of series, so you can calculate its aggregate value `aggregateResults` by calling the `groupAggregationsBySeries()` method.  Before you finally create the result set, you need to restore its order to the order of the user query.  Finally use the `constructDataSet()` method to create a result set and return it.
+
+The `groupAggregationsBySeries ()` method is explained in detail below.  First create an `IAggregateReader`:
+```
+IAggregateReader seriesReader = new SeriesAggregateReader(
+        pathToAggrIndexes.getKey(), tsDataType, context, QueryResourceManager.getInstance()
+        .getQueryDataSource(seriesPath, context, timeFilter), timeFilter, null);
+```
+
+For each entry (that is, series), first create an aggregate result `AggregateResult` for each aggregate query. Maintain a boolean list `isCalculatedList`, corresponding to whether each `AggregateResult` has been calculated. Record the remaining number of functions to be calculated in `remainingToCalculate`.  The list of boolean values and this count value will make some aggregate functions (such as `FIRST_VALUE`) not need to continue the entire loop process after obtaining the result.
+
+Next, update `AggregateResult` according to the usage method of `aggregateReader` introduced in Section 5.2:
+
+```
+while (aggregateReader.hasNextChunk()) {
+  if (aggregateReader.canUseCurrentChunkStatistics()) {
+    Statistics chunkStatistics = aggregateReader.currentChunkStatistics();
+    
+    // do some aggregate calculation using chunk statistics
+    ...
+    
+    aggregateReader.skipCurrentChunk();
+    continue;
+  }
+	  
+  while (aggregateReader.hasNextPage()) {
+	 if (aggregateReader.canUseCurrentPageStatistics()) {
+	   Statistics pageStatistic = aggregateReader.currentPageStatistics();
+	   
+	   // do some aggregate calculation using page statistics
+      ...
+	   
+	   aggregateReader.skipCurrentPage();
+	   continue;
+	 } else {
+	 	BatchData batchData = aggregateReader.nextPage();
+	 	// do some aggregate calculation using batch data
+      ...
+	 }	 
+  }
+}
+```
+
+It should be noted that before updating each result, you need to first determine whether it has been calculated (using the isCalculatedList list); after each update, call the isCalculatedAggregationResult () method to update the boolean values in the list  .  If all values in the list are true, that is, the value of `remainingToCalculate` is 0, it proves that all aggregate function results have been calculated and can be returned.
 
 Review comment:
   ```suggestion
   It should be noted that before updating each result, you need to first determine whether it has been calculated (using the `isCalculatedList` list); after each update, call the `isCalculatedAggregationResult()` method to update the boolean values in the list. If all values in the list are true, that is, the value of `remainingToCalculate` is 0, it proves that all aggregate function results have been calculated and can be returned.
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services