You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Jackie-Jiang (via GitHub)" <gi...@apache.org> on 2023/07/08 02:39:41 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #11057: Support for new dataTime format in `DateTimeGranularitySpec` without explicitly setting size

Jackie-Jiang commented on code in PR #11057:
URL: https://github.com/apache/pinot/pull/11057#discussion_r1256777533


##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/DateTimeGranularitySpec.java:
##########
@@ -53,38 +55,49 @@ public DateTimeGranularitySpec(String granularity) {
     char separator;
     int sizePosition;
     int timeUnitPosition;
+    int minTokens = NUM_TOKENS;
+    int maxTokens = NUM_TOKENS;

Review Comment:
   (minor) Move the assignment into the if check for readability



##########
pinot-spi/src/main/java/org/apache/pinot/spi/data/DateTimeGranularitySpec.java:
##########
@@ -53,38 +55,49 @@ public DateTimeGranularitySpec(String granularity) {
     char separator;
     int sizePosition;
     int timeUnitPosition;
+    int minTokens = NUM_TOKENS;
+    int maxTokens = NUM_TOKENS;
 
     if (Character.isDigit(granularity.charAt(0))) {
       // Colon format: 'size:timeUnit'
       separator = COLON_SEPARATOR;
       sizePosition = COLON_FORMAT_SIZE_POSITION;
       timeUnitPosition = COLON_FORMAT_TIME_UNIT_POSITION;
     } else {
-      // Pipe format: 'timeUnit|size'
+      // Pipe format: 'timeUnit(|size)'
       separator = PIPE_SEPARATOR;
       sizePosition = PIPE_FORMAT_SIZE_POSITION;
       timeUnitPosition = PIPE_FORMAT_TIME_UNIT_POSITION;
+
+      minTokens = PIPE_FORMAT_MIN_TOKENS;
+      maxTokens = PIPE_FORMAT_MAX_TOKENS;
     }
 
     String[] granularityTokens = StringUtil.split(granularity, separator, 2);
-    Preconditions.checkArgument(granularityTokens.length >= NUM_TOKENS,
-            "Invalid granularity: %s, must be of format 'timeUnit|size' or 'size:timeUnit'", granularity);
+    Preconditions.checkArgument(granularityTokens.length >= minTokens && granularityTokens.length <= maxTokens,
+            "Invalid granularity: %s, must be of format 'timeUnit(|size)' or 'size:timeUnit'", granularity);
 
     try {
-      _size = Integer.parseInt(granularityTokens[sizePosition]);
+      _timeUnit = TimeUnit.valueOf(granularityTokens[timeUnitPosition]);
     } catch (Exception e) {
       throw new IllegalArgumentException(
-          String.format("Invalid size: %s in granularity: %s", granularityTokens[sizePosition], granularity));
+          String.format("Invalid time unit: %s in granularity: %s", granularityTokens[timeUnitPosition],
+              granularity));
+    }
+
+    // New format without explicitly setting size - use default size = 1
+    if (granularityTokens.length == 1) {

Review Comment:
   (minor)
   ```suggestion
       if (granularityTokens.length == PIPE_FORMAT_MIN_TOKENS) {
   ```



-- 
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-unsubscribe@pinot.apache.org

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


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