You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/07/09 04:10:20 UTC

[GitHub] [druid] suneet-s opened a new pull request #11423: Display errors for invalid timezones in TIME_FORMAT

suneet-s opened a new pull request #11423:
URL: https://github.com/apache/druid/pull/11423


   ### Description
   
   Users sometimes make typos when picking timezones - like `America/Los Angeles`
   instead of `America/Los_Angeles` instead of defaulting to UTC, this change
   makes it so that an error is thrown instead notifying the user of their mistake.
   
   ##### Key changed/added classes in this PR
    * `DateTimes`
    * `OurBar`
    * `TheirBaz`
   
   This PR has:
   - [x] been self-reviewed.
   - [ ] added documentation for new or modified features or behaviors.
   - [x] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [x] been tested in a test Druid cluster.
   


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

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



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


[GitHub] [druid] suneet-s merged pull request #11423: Display errors for invalid timezones in TIME_FORMAT

Posted by GitBox <gi...@apache.org>.
suneet-s merged pull request #11423:
URL: https://github.com/apache/druid/pull/11423


   


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

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



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


[GitHub] [druid] suneet-s commented on a change in pull request #11423: Display errors for invalid timezones in TIME_FORMAT

Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #11423:
URL: https://github.com/apache/druid/pull/11423#discussion_r666693115



##########
File path: core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
##########
@@ -53,14 +57,28 @@
       "[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}(Z|[+\\-][0-9]{2}(:[0-9]{2}))"
   );
 
-  @SuppressForbidden(reason = "DateTimeZone#forID")
   public static DateTimeZone inferTzFromString(String tzId)
+  {
+    return inferTzFromString(tzId, true);
+  }
+
+  /**
+   * @return The dateTimezone for the provided {@param tzId}. If {@param fallback} is true, the default timezone
+   * will be returned if the tzId does not match a supported timezone.
+   * @throws IllegalArgumentException if {@param fallback} is false and the provided tzId doesn't match a supported
+   * timezone.
+   */
+  @SuppressForbidden(reason = "DateTimeZone#forID")
+  public static DateTimeZone inferTzFromString(String tzId, boolean fallback) throws IllegalArgumentException
   {
     try {
       return DateTimeZone.forID(tzId);
     }
     catch (IllegalArgumentException e) {
       // also support Java timezone strings
+      if (!fallback && !AVAILABLE_TIMEZONE_IDS.contains(tzId)) {
+        throw e;

Review comment:
       `The datetime zone id 'America/Unknown' is not recognised` is the error message in the tests. I'm not sure if it's better form to standardize the error message or not, but I didn't feel like logging the error message and throwing a sanitized error message instead. Let me know if you think another error message will be better.




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

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



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


[GitHub] [druid] abhishekagarwal87 commented on a change in pull request #11423: Display errors for invalid timezones in TIME_FORMAT

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on a change in pull request #11423:
URL: https://github.com/apache/druid/pull/11423#discussion_r666696982



##########
File path: core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
##########
@@ -53,14 +57,28 @@
       "[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}(Z|[+\\-][0-9]{2}(:[0-9]{2}))"
   );
 
-  @SuppressForbidden(reason = "DateTimeZone#forID")
   public static DateTimeZone inferTzFromString(String tzId)
+  {
+    return inferTzFromString(tzId, true);
+  }
+
+  /**
+   * @return The dateTimezone for the provided {@param tzId}. If {@param fallback} is true, the default timezone
+   * will be returned if the tzId does not match a supported timezone.
+   * @throws IllegalArgumentException if {@param fallback} is false and the provided tzId doesn't match a supported
+   * timezone.
+   */
+  @SuppressForbidden(reason = "DateTimeZone#forID")
+  public static DateTimeZone inferTzFromString(String tzId, boolean fallback) throws IllegalArgumentException
   {
     try {
       return DateTimeZone.forID(tzId);
     }
     catch (IllegalArgumentException e) {
       // also support Java timezone strings
+      if (!fallback && !AVAILABLE_TIMEZONE_IDS.contains(tzId)) {
+        throw e;

Review comment:
       No. This is good enough 👍 
   




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

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



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


[GitHub] [druid] abhishekagarwal87 commented on a change in pull request #11423: Display errors for invalid timezones in TIME_FORMAT

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on a change in pull request #11423:
URL: https://github.com/apache/druid/pull/11423#discussion_r666670473



##########
File path: core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
##########
@@ -53,14 +57,28 @@
       "[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}(Z|[+\\-][0-9]{2}(:[0-9]{2}))"
   );
 
-  @SuppressForbidden(reason = "DateTimeZone#forID")
   public static DateTimeZone inferTzFromString(String tzId)
+  {
+    return inferTzFromString(tzId, true);
+  }
+
+  /**
+   * @return The dateTimezone for the provided {@param tzId}. If {@param fallback} is true, the default timezone
+   * will be returned if the tzId does not match a supported timezone.
+   * @throws IllegalArgumentException if {@param fallback} is false and the provided tzId doesn't match a supported
+   * timezone.
+   */
+  @SuppressForbidden(reason = "DateTimeZone#forID")
+  public static DateTimeZone inferTzFromString(String tzId, boolean fallback) throws IllegalArgumentException
   {
     try {
       return DateTimeZone.forID(tzId);
     }
     catch (IllegalArgumentException e) {
       // also support Java timezone strings
+      if (!fallback && !AVAILABLE_TIMEZONE_IDS.contains(tzId)) {
+        throw e;

Review comment:
       what would be the message in this exception? If it is too cryptic, we can add a message of our own that tzId is an invalid timezone. 




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

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



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


[GitHub] [druid] suneet-s commented on a change in pull request #11423: Display errors for invalid timezones in TIME_FORMAT

Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #11423:
URL: https://github.com/apache/druid/pull/11423#discussion_r666693115



##########
File path: core/src/main/java/org/apache/druid/java/util/common/DateTimes.java
##########
@@ -53,14 +57,28 @@
       "[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}(Z|[+\\-][0-9]{2}(:[0-9]{2}))"
   );
 
-  @SuppressForbidden(reason = "DateTimeZone#forID")
   public static DateTimeZone inferTzFromString(String tzId)
+  {
+    return inferTzFromString(tzId, true);
+  }
+
+  /**
+   * @return The dateTimezone for the provided {@param tzId}. If {@param fallback} is true, the default timezone
+   * will be returned if the tzId does not match a supported timezone.
+   * @throws IllegalArgumentException if {@param fallback} is false and the provided tzId doesn't match a supported
+   * timezone.
+   */
+  @SuppressForbidden(reason = "DateTimeZone#forID")
+  public static DateTimeZone inferTzFromString(String tzId, boolean fallback) throws IllegalArgumentException
   {
     try {
       return DateTimeZone.forID(tzId);
     }
     catch (IllegalArgumentException e) {
       // also support Java timezone strings
+      if (!fallback && !AVAILABLE_TIMEZONE_IDS.contains(tzId)) {
+        throw e;

Review comment:
       `The datetime zone id 'America/Unknown' is not recognised` is the error message in the tests. I'm not sure if it's better form to standardize the error message or not, but I didn't feel like logging the error message and throwing a sanitized error message instead and I'm not aware of a current best practice on exposing error messages - so I took the easy way out :) Let me know if you think another error message will be better.




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

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



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