From 3ec1877887b3cd3b9ff6ea95a62bff29162b752a Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Thu, 16 Mar 2017 22:59:11 -0700 Subject: [PATCH] Fix BucketExtractionFn on objects that are strings. (#4072) --- .../java/io/druid/query/extraction/BucketExtractionFn.java | 2 +- .../io/druid/query/extraction/BucketExtractionFnTest.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/processing/src/main/java/io/druid/query/extraction/BucketExtractionFn.java b/processing/src/main/java/io/druid/query/extraction/BucketExtractionFn.java index 1606883954d..ed957ca0276 100644 --- a/processing/src/main/java/io/druid/query/extraction/BucketExtractionFn.java +++ b/processing/src/main/java/io/druid/query/extraction/BucketExtractionFn.java @@ -60,7 +60,7 @@ public class BucketExtractionFn implements ExtractionFn if (value instanceof Number) { return bucket(((Number) value).doubleValue()); } else if (value instanceof String) { - return apply(value); + return apply((String) value); } return null; } diff --git a/processing/src/test/java/io/druid/query/extraction/BucketExtractionFnTest.java b/processing/src/test/java/io/druid/query/extraction/BucketExtractionFnTest.java index 80acde0d1b8..d0d7632eb22 100644 --- a/processing/src/test/java/io/druid/query/extraction/BucketExtractionFnTest.java +++ b/processing/src/test/java/io/druid/query/extraction/BucketExtractionFnTest.java @@ -32,6 +32,7 @@ public class BucketExtractionFnTest public void testApply() { BucketExtractionFn extractionFn1 = new BucketExtractionFn(100.0, 0.5); + Assert.assertEquals("1200.5", extractionFn1.apply((Object) "1234.99")); Assert.assertEquals("1200.5", extractionFn1.apply("1234.99")); Assert.assertEquals("0.5", extractionFn1.apply("1")); Assert.assertEquals("0.5", extractionFn1.apply("100")); @@ -69,7 +70,7 @@ public class BucketExtractionFnTest final ObjectMapper objectMapper = new DefaultObjectMapper(); final String json1 = "{ \"type\" : \"bucket\", \"size\" : \"2\", \"offset\" : \"0.5\" }"; - BucketExtractionFn extractionFn1 = (BucketExtractionFn)objectMapper.readValue(json1, ExtractionFn.class); + BucketExtractionFn extractionFn1 = (BucketExtractionFn) objectMapper.readValue(json1, ExtractionFn.class); Assert.assertEquals(2, extractionFn1.getSize(), DELTA); Assert.assertEquals(0.5, extractionFn1.getOffset(), DELTA); @@ -82,7 +83,7 @@ public class BucketExtractionFnTest ); final String json2 = "{ \"type\" : \"bucket\"}"; - BucketExtractionFn extractionFn2 = (BucketExtractionFn)objectMapper.readValue(json2, ExtractionFn.class); + BucketExtractionFn extractionFn2 = (BucketExtractionFn) objectMapper.readValue(json2, ExtractionFn.class); Assert.assertEquals(1, extractionFn2.getSize(), DELTA); Assert.assertEquals(0, extractionFn2.getOffset(), DELTA);