JackieTien97 commented on code in PR #16103:
URL: https://github.com/apache/iotdb/pull/16103#discussion_r2256162298


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/LastQueryAggTableScanOperator.java:
##########
@@ -285,11 +295,202 @@ private void buildResultUseLastCache() {
     currentHitCacheIndex++;
   }
 
-  private void updateLastCacheIfPossible() {
-    if (!needUpdateCache) {
-      return;
+  private void buildResultUseLastValuesCache() {
+    appendGroupKeysToResult(cachedDeviceEntries, currentHitCacheIndex);
+    TimeValuePair[] currentHitResult = 
lastValuesCacheResults.get(currentHitCacheIndex);
+    // there is no problem when the cache result doesn't contain time column, 
because we will not
+    // use lastRowTime in later process
+    long lastRowTime = currentHitResult[currentHitResult.length - 
1].getTimestamp();
+    int channel = 0;
+    for (int i = 0; i < tableAggregators.size(); i++) {
+      TableAggregator aggregator = tableAggregators.get(i);
+      ColumnBuilder columnBuilder = 
resultTsBlockBuilder.getColumnBuilder(groupingKeySize + i);
+      int columnIdx = aggregatorInputChannels.get(channel);
+      ColumnSchema schema = aggColumnSchemas.get(columnIdx);
+      TsTableColumnCategory category = schema.getColumnCategory();
+      switch (category) {
+        case TAG:
+          String id =
+              getNthIdColumnValue(
+                  cachedDeviceEntries.get(currentHitCacheIndex), 
aggColumnsIndexArray[columnIdx]);
+          if (aggregator.getAccumulator() instanceof LastDescAccumulator) {
+            if (id == null) {
+              if (aggregator.getStep().isOutputPartial()) {
+                columnBuilder.writeBinary(
+                    new Binary(
+                        serializeTimeValue(getTSDataType(schema.getType()), 
lastRowTime, null)));
+              } else {
+                columnBuilder.appendNull();
+              }
+            } else {
+              if (aggregator.getStep().isOutputPartial()) {
+                columnBuilder.writeBinary(
+                    new Binary(
+                        serializeTimeValue(

Review Comment:
   call the same method as last row



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to