Skip to content

Commit

Permalink
Fix BucketExtractionFn on objects that are strings. (apache#4072)
Browse files Browse the repository at this point in the history
  • Loading branch information
gianm authored and jon-wei committed Mar 17, 2017
1 parent 403fbae commit 3ec1877
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String apply(Object value)
if (value instanceof Number) {
return bucket(((Number) value).doubleValue());
} else if (value instanceof String) {
return apply(value);
return apply((String) value);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testSerde() throws Exception
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);

Expand All @@ -82,7 +83,7 @@ public void testSerde() throws Exception
);

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);

Expand Down

0 comments on commit 3ec1877

Please sign in to comment.