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


##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/TimeSeriesAggregationFunction.java:
##########
@@ -44,41 +46,74 @@
 
 
 /**
- * Aggregation function used by the Time Series Engine.
- * TODO: This can't be used with SQL because the Object Serde is not 
implemented.
+ * Aggregation function used by the Time Series Engine. This can't be used 
with SQL because the Object Serde is not yet
+ * implemented. Though we don't plan on exposing this function anytime soon.
+ * <h2>Converting Time Values to Bucket Indexes</h2>
+ * <p>
+ *   This aggregation function will map each scanned data point to a time 
bucket index. This is done using the
+ *   formula: {@code ((timeValue + timeOffset) - timeReferencePoint - 1) / 
bucketSize}. The entire calculation is done
+ *   in the Time Unit (seconds, ms, etc.) of the timeValue returned by the 
time expression chosen by the user.
+ *   The method used to add values to the series builders is:
+ *   {@link BaseTimeSeriesBuilder#addValueAtIndex(int, Double, long)}.
+ * </p>
+ * <p>
+ *   The formula originates from the fact that we use half-open time 
intervals, which are open on the left.
+ *   The timeReferencePoint is usually the start of the time-range being 
scanned. Assuming everything is in seconds,
+ *   the time buckets can generally thought to look something like the 
following:
+ *   <pre>
+ *     (timeReferencePoint, timeReferencePoint + bucketSize]
+ *     (timeReferencePoint + bucketSize, timeReferencePoint + 2 * bucketSize]
+ *     ...
+ *     (timeReferencePoint + (numBuckets - 1) * bucketSize, timeReferencePoint 
+ numBuckets * bucketSize]
+ *   </pre>
+ * </p>
+ * <p>
+ *   Also, note that the timeReferencePoint is simply calculated as follows:
+ *   <pre>
+ *     timeReferencePointInSeconds = firstBucketValue - bucketSizeInSeconds
+ *   </pre>
+ * </p>
  */
 public class TimeSeriesAggregationFunction implements 
AggregationFunction<BaseTimeSeriesBuilder, DoubleArrayList> {
   private final TimeSeriesBuilderFactory _factory;
   private final AggInfo _aggInfo;
   private final ExpressionContext _valueExpression;
   private final ExpressionContext _timeExpression;
   private final TimeBuckets _timeBuckets;
+  private final long _timeReferencePoint;
+  private final long _timeOffset;
+  private final long _timeBucketDivisor;
 
   /**
    * Arguments are as shown below:
    * <pre>
-   *   timeSeriesAggregate("m3ql", "MIN", valueExpr, timeBucketExpr, 
firstBucketValue, bucketLenSeconds, numBuckets,
-   *      "aggParam1=value1")
+   *   timeSeriesAggregate("m3ql", "MIN", valueExpr, timeExpr, timeUnit, 
offsetSeconds, firstBucketValue,
+   *       bucketLenSeconds, numBuckets, "aggParam1=value1")
    * </pre>
    */
   public TimeSeriesAggregationFunction(List<ExpressionContext> arguments) {

Review Comment:
   **Note:** At some point we'll add support for taking in another expression 
here, to extract the Exemplar values when appropriate.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to