From d892918a3d5b79ac14ad5b200bb70a796f2ff4c9 Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Tue, 29 Mar 2016 17:03:26 -0500 Subject: [PATCH] handle null values in In Filter --- .../src/main/java/io/druid/query/filter/InDimFilter.java | 3 ++- .../java/io/druid/query/filter/InDimFilterSerDesrTest.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/processing/src/main/java/io/druid/query/filter/InDimFilter.java b/processing/src/main/java/io/druid/query/filter/InDimFilter.java index eba15b3446b..675b11ba9fa 100644 --- a/processing/src/main/java/io/druid/query/filter/InDimFilter.java +++ b/processing/src/main/java/io/druid/query/filter/InDimFilter.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.metamx.common.StringUtils; @@ -66,7 +67,7 @@ public class InDimFilter implements DimFilter int valuesBytesSize = 0; int index = 0; for (String value : values) { - valuesBytes[index] = StringUtils.toUtf8(value); + valuesBytes[index] = StringUtils.toUtf8(Strings.nullToEmpty(value)); valuesBytesSize += valuesBytes[index].length + 1; ++index; } diff --git a/processing/src/test/java/io/druid/query/filter/InDimFilterSerDesrTest.java b/processing/src/test/java/io/druid/query/filter/InDimFilterSerDesrTest.java index ad3d44558eb..80e9dc6d7fc 100644 --- a/processing/src/test/java/io/druid/query/filter/InDimFilterSerDesrTest.java +++ b/processing/src/test/java/io/druid/query/filter/InDimFilterSerDesrTest.java @@ -66,4 +66,11 @@ public class InDimFilterSerDesrTest final InDimFilter inDimFilter_2 = new InDimFilter("dimTest", Arrays.asList("good,bad")); Assert.assertNotEquals(inDimFilter_1.getCacheKey(), inDimFilter_2.getCacheKey()); } + + @Test + public void testGetCacheKeyNullValue() throws IOException + { + InDimFilter inDimFilter = mapper.readValue("{\"type\":\"in\",\"dimension\":\"dimTest\",\"values\":[null]}", InDimFilter.class); + Assert.assertNotNull(inDimFilter.getCacheKey()); + } }