Wei-hao-Li commented on code in PR #18267:
URL: https://github.com/apache/iotdb/pull/18267#discussion_r3628407323


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/LastQueryAggTableScanOperator.java:
##########
@@ -75,6 +75,13 @@ public class LastQueryAggTableScanOperator extends 
AbstractAggTableScanOperator
   private final List<DeviceEntry> cachedDeviceEntries;
   private final int allDeviceCount;
 
+  // A no-GROUP-BY global aggregation whose device set resolves to zero devices
+  // (e.g. last_by on a device that was never written) has nothing for the 
device
+  // loop to iterate, so without this it would emit zero rows. Per SQL 
semantics a
+  // global aggregate over empty input must return exactly one row whose value 
is
+  // NULL (except count()); this one-shot flag drives that single row.
+  private boolean emptyGlobalResultEmitted = false;

Review Comment:
   I think it is better to use default Agg operator when the DeviceEntries is 
empty when generate Operator Tree. The empty process logic has been there.
   
   Just modify one line in DataNodeTableOperatorGenerator is OK:  
   DataNodeTableOperatorGenerator -> visitAggregationTableScan -> 
   
   `OptimizeType optimizeType =
           node.getDeviceEntries().isEmpty()
               ? OptimizeType.NOOP
               : canUseLastCacheOptimize(
                   parameter.getTableAggregators(), node, 
parameter.getTimeColumnName());`
   
   



-- 
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