gortiz commented on code in PR #18649:
URL: https://github.com/apache/pinot/pull/18649#discussion_r3357495088


##########
pinot-spi/src/main/java/org/apache/pinot/spi/query/QueryProgressStats.java:
##########
@@ -0,0 +1,123 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.spi.query;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collection;
+import javax.annotation.Nullable;
+
+
+/// Progress for a running query.
+///
+/// The progress percentage is derived from processed work units over total 
work units. For single-stage queries, work
+/// units map to selected segments. For multi-stage queries, work units 
include selected segments and stage op-chains,
+/// because non-leaf stages can still be running after all leaf segments have 
been scanned. A negative percentage means
+/// the denominator is not known yet.
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class QueryProgressStats {
+  private final long _processedWorkUnits;

Review Comment:
   Minor style nit: this class is a natural candidate for a Java 21 record — 
it's an immutable value object with no mutable state. The only friction points 
are (1) `_progressPercent` is a derived field that would need to become a 
method, and (2) the null-coercion in the `@JsonCreator` constructor 
(`processedWorkUnits != null ? processedWorkUnits : processedSegments`) 
requires a static factory rather than the canonical constructor, since one 
component's default depends on another component's value. If you go that route:
   
   ```java
   @JsonIgnoreProperties(ignoreUnknown = true)
   public record QueryProgressStats(
       long processedWorkUnits, long totalWorkUnits,
       long processedSegments,  long totalSegmentsToProcess,
       boolean estimated
   ) {
       @JsonCreator
       public static QueryProgressStats fromJson(
           @JsonProperty("processedWorkUnits")     Long pw,
           @JsonProperty("totalWorkUnits")         Long tw,
           @JsonProperty("processedSegments")      Long ps,
           @JsonProperty("totalSegmentsToProcess") Long ts,
           @JsonProperty("estimated")              Boolean est) {
         long seg = ps  != null ? ps  : 0L;
         long tot = ts  != null ? ts  : -1L;
         return new QueryProgressStats(
             pw != null ? pw : seg,
             tw != null ? tw : tot,
             seg, tot, est != null && est);
       }
   
       public double progressPercent() {
         if (totalWorkUnits < 0)  return -1.0;
         if (totalWorkUnits == 0) return 100.0;
         return Math.min(100.0, processedWorkUnits * 100.0 / totalWorkUnits);
       }
   }
   ```
   
   Note the API surface change: accessors become `processedWorkUnits()` vs 
`getProcessedWorkUnits()`. JSON clients are unaffected (Jackson handles both); 
Java API callers see a source-level break. Totally fine to leave as-is if you 
prefer to avoid the churn.



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