ankitsultana commented on code in PR #17170:
URL: https://github.com/apache/pinot/pull/17170#discussion_r2529201171


##########
pinot-common/src/test/java/org/apache/pinot/common/response/mapper/TimeSeriesResponseMapperTest.java:
##########
@@ -23,7 +23,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import org.apache.pinot.common.response.broker.BrokerResponseNativeV2;
+import org.apache.pinot.common.response.broker.BrokerResponseNative;

Review Comment:
   same here: why V2 to V1?



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/TimeSeriesExchangeReceiveOperator.java:
##########
@@ -50,6 +51,20 @@
  * different servers, we will simply append them to the list, creating a union.
  */
 public class TimeSeriesExchangeReceiveOperator extends BaseTimeSeriesOperator {
+
+  private static final List<DataTable.MetadataKey> ADDITIVE_STATS_KEYS = 
List.of(

Review Comment:
   Can you create a ticket for the partial result feature? Just so we don't 
lose track. Thanks



##########
pinot-common/src/main/java/org/apache/pinot/common/response/mapper/TimeSeriesResponseMapper.java:
##########
@@ -20,8 +20,10 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.datatable.DataTable;
 import org.apache.pinot.common.response.BrokerResponse;
-import org.apache.pinot.common.response.broker.BrokerResponseNativeV2;
+import org.apache.pinot.common.response.broker.BrokerResponseNative;

Review Comment:
   Why the change from V2 to the older one? V2 is the latest response format



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/TimeSeriesExchangeReceiveOperator.java:
##########
@@ -146,13 +168,37 @@ private TimeSeriesBlock getNextBlockWithAggregation()
       timeSeriesList.add(entry.getValue().build());
       seriesMap.put(seriesHash, timeSeriesList);
     }
-    return new TimeSeriesBlock(timeBuckets, seriesMap);
+    return new TimeSeriesBlock(timeBuckets, seriesMap, aggregatedStats);
+  }
+
+  /**
+   * TODO: Consider consolidating stats merging logic with
+   * {@link org.apache.pinot.core.query.reduce.ExecutionStatsAggregator}
+   **/
+  private void mergeStats(Map<String, String> aggregatedStats, Map<String, 
String> metadata) {
+    for (DataTable.MetadataKey statKey : ADDITIVE_STATS_KEYS) {
+      String key = statKey.getName();
+      String existingValue = aggregatedStats.get(key);
+      String newValue = metadata.get(key);
+      if (newValue != null) {
+        try {
+          long newLong = Long.parseLong(newValue);
+          long existingLong = existingValue != null ? 
Long.parseLong(existingValue) : 0L;
+          aggregatedStats.put(key, Long.toString(existingLong + newLong));
+        } catch (NumberFormatException e) {
+          // Ignore malformed stats
+          LOGGER.warn("Failed to parse metadata key: {} with value: {}. 
Ignoring it in stats aggregation",

Review Comment:
   warning: logging in query path can be risky. Consider wrapping this in a 
rate-limiter of sorts (e.g. adding a static counter that logs only on certain 
conditions. contention shouldn't be an issue since this event is expected to be 
rare).



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/TimeSeriesExchangeReceiveOperator.java:
##########
@@ -146,13 +168,37 @@ private TimeSeriesBlock getNextBlockWithAggregation()
       timeSeriesList.add(entry.getValue().build());
       seriesMap.put(seriesHash, timeSeriesList);
     }
-    return new TimeSeriesBlock(timeBuckets, seriesMap);
+    return new TimeSeriesBlock(timeBuckets, seriesMap, aggregatedStats);
+  }
+
+  /**
+   * TODO: Consider consolidating stats merging logic with
+   * {@link org.apache.pinot.core.query.reduce.ExecutionStatsAggregator}
+   **/
+  private void mergeStats(Map<String, String> aggregatedStats, Map<String, 
String> metadata) {
+    for (DataTable.MetadataKey statKey : ADDITIVE_STATS_KEYS) {
+      String key = statKey.getName();
+      String existingValue = aggregatedStats.get(key);
+      String newValue = metadata.get(key);
+      if (newValue != null) {
+        try {
+          long newLong = Long.parseLong(newValue);
+          long existingLong = existingValue != null ? 
Long.parseLong(existingValue) : 0L;
+          aggregatedStats.put(key, Long.toString(existingLong + newLong));

Review Comment:
   Can we prefix the key name using some scheme? Because we also have some 
metadata already being sent and I am worried in the future someone can make a 
change where the keys start colliding with each other (e.g. see 
`TimeSeries.PLAN_ID`)



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/timeseries/TimeSeriesExchangeReceiveOperator.java:
##########
@@ -146,13 +164,31 @@ private TimeSeriesBlock getNextBlockWithAggregation()
       timeSeriesList.add(entry.getValue().build());
       seriesMap.put(seriesHash, timeSeriesList);
     }
-    return new TimeSeriesBlock(timeBuckets, seriesMap);
+    return new TimeSeriesBlock(timeBuckets, seriesMap, aggregatedStats);
+  }
+
+  /**
+   * TODO: Consider consolidating stats merging logic with
+   * {@link org.apache.pinot.core.query.reduce.ExecutionStatsAggregator}
+   **/
+  private void mergeStats(Map<String, String> aggregatedStats, Map<String, 
String> metadata) {
+    for (DataTable.MetadataKey statKey : ADDITIVE_STATS_KEYS) {
+      String key = statKey.getName();
+      String existingValue = aggregatedStats.get(key);
+      String newValue = metadata.get(key);
+      if (newValue != null) {
+        long existingLong = existingValue != null ? 
Long.parseLong(existingValue) : 0L;
+        long newLong = Long.parseLong(newValue);
+        aggregatedStats.put(key, Long.toString(existingLong + newLong));
+      }
+    }
   }
 
   private TimeSeriesBlock getNextBlockNoAggregation()
       throws Throwable {
     Map<Long, List<TimeSeries>> timeSeriesMap = new HashMap<>();
     TimeBuckets timeBuckets = null;
+    Map<String, String> aggregatedStats = new HashMap<>();

Review Comment:
   Issue should suffice for now.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to