handle null values in In Filter

This commit is contained in:
Parag Jain 2016-03-29 17:03:26 -05:00
parent e2cabc93ca
commit d892918a3d
2 changed files with 9 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.metamx.common.StringUtils; import com.metamx.common.StringUtils;
@ -66,7 +67,7 @@ public class InDimFilter implements DimFilter
int valuesBytesSize = 0; int valuesBytesSize = 0;
int index = 0; int index = 0;
for (String value : values) { for (String value : values) {
valuesBytes[index] = StringUtils.toUtf8(value); valuesBytes[index] = StringUtils.toUtf8(Strings.nullToEmpty(value));
valuesBytesSize += valuesBytes[index].length + 1; valuesBytesSize += valuesBytes[index].length + 1;
++index; ++index;
} }

View File

@ -66,4 +66,11 @@ public class InDimFilterSerDesrTest
final InDimFilter inDimFilter_2 = new InDimFilter("dimTest", Arrays.asList("good,bad")); final InDimFilter inDimFilter_2 = new InDimFilter("dimTest", Arrays.asList("good,bad"));
Assert.assertNotEquals(inDimFilter_1.getCacheKey(), inDimFilter_2.getCacheKey()); 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());
}
} }