haimeiguo commented on a change in pull request #2571:
URL: https://github.com/apache/iotdb/pull/2571#discussion_r565128057



##########
File path: server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
##########
@@ -668,6 +666,23 @@ private TSExecuteStatementResp 
internalExecuteQueryStatement(String statement, l
     }
   }
 
+  /*
+  calculate fetch size for group by time plan
+   */
+  private int getFetchSizeForGroupByTimePlan(GroupByTimePlan groupByTimePlan) {
+    int rows =  (int) ((groupByTimePlan.getEndTime() - 
groupByTimePlan.getStartTime()) / groupByTimePlan
+        .getInterval());
+    // edge case for group by months when starttime is in February
+    // ie. time range = [2020-02-02, 2020-03-02), interval = 1mo, rows will 
get 0
+    if (rows == 0 && groupByTimePlan.isIntervalByMonth()) {
+      Calendar calendar = Calendar.getInstance();
+      calendar.setTimeInMillis(groupByTimePlan.getStartTime());
+      calendar.add(Calendar.MONTH, (int) (groupByTimePlan.getInterval() / 
MS_TO_MONTH));
+      rows = calendar.getTimeInMillis() <= groupByTimePlan.getEndTime() ? 1 : 
0;

Review comment:
       we add starttime by interval months to check if the group by interval is 
within starttime to endtime range which includes endtime itself. if we use < 
sign, the group by result is not correct for edge case 
   
   ie starttime = 2/1, endtime = 3/1 and interval = 1mo, we add 1 mo to 2/1, 
then calendar.getTimeInMillis() will be 3/1, which is equal to 
groupByTimePlan.getEndTime(), if use < sign, the result will not include 2/1 to 
3/1 interval
   




----------------------------------------------------------------
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:
[email protected]


Reply via email to