You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by jf...@apache.org on 2018/11/16 19:25:59 UTC

[incubator-pinot] 01/01: Handle invalid durations in the duration DSL

This is an automated email from the ASF dual-hosted git repository.

jfim pushed a commit to branch handle-invalid-durations-in-duration-dsl
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit e9f7074806e73c94bb0d834eab63e6f754a59bc7
Author: Jean-Francois Im <je...@gmail.com>
AuthorDate: Thu Nov 15 12:24:44 2018 -0800

    Handle invalid durations in the duration DSL
    
    Handle invalid durations in the duration DSL by removing invalid values
    when loading (eg. "null DAYS" or "null null"). These values come from
    invalid old-style configurations that got migrated to the new config
    format.
    
    This does not fully round-trip. For example, an old config with timeUnit
    of DAYS and timeValue of null will lose the DAYS qualifier, although
    this configuration was invalid (and ignored) in the first place.
---
 .../com/linkedin/pinot/common/config/DurationDsl.java  | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/pinot-common/src/main/java/com/linkedin/pinot/common/config/DurationDsl.java b/pinot-common/src/main/java/com/linkedin/pinot/common/config/DurationDsl.java
index d9b72b9..f26aba3 100644
--- a/pinot-common/src/main/java/com/linkedin/pinot/common/config/DurationDsl.java
+++ b/pinot-common/src/main/java/com/linkedin/pinot/common/config/DurationDsl.java
@@ -28,14 +28,22 @@ public class DurationDsl implements SingleKeyDsl<Duration> {
       return null;
     }
 
-    String[] parts = text.split(" ");
-    final String unit = parts[1].toUpperCase();
-    final String unitCount = parts[0];
-    return new Duration(TimeUnit.valueOf(unit), Integer.parseInt(unitCount));
+    try {
+      String[] parts = text.split(" ");
+      final String unit = parts[1].toUpperCase();
+      final String unitCount = parts[0];
+      return new Duration(TimeUnit.valueOf(unit), Integer.parseInt(unitCount));
+    } catch (Exception e) {
+      return null;
+    }
   }
 
   @Override
   public String unparse(Duration value) {
-    return value.getUnitCount() + " " + value.getUnit();
+    if (value != null) {
+      return value.getUnitCount() + " " + value.getUnit();
+    } else {
+      return null;
+    }
   }
 }


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