Merge pull request #2101 from himanshug/fix_extraction_dim_filter_cache_key

add extractionFn bytes to cache key in ExtractionDimFilter
This commit is contained in:
Fangjin Yang 2015-12-18 12:05:43 -08:00
commit 71f554bf80
2 changed files with 18 additions and 6 deletions

View File

@ -78,12 +78,14 @@ public class ExtractionDimFilter implements DimFilter
{ {
byte[] dimensionBytes = StringUtils.toUtf8(dimension); byte[] dimensionBytes = StringUtils.toUtf8(dimension);
byte[] valueBytes = StringUtils.toUtf8(value); byte[] valueBytes = StringUtils.toUtf8(value);
byte[] extractionFnBytes = extractionFn.getCacheKey();
return ByteBuffer.allocate(2 + dimensionBytes.length + valueBytes.length) return ByteBuffer.allocate(3 + dimensionBytes.length + valueBytes.length + extractionFnBytes.length)
.put(DimFilterCacheHelper.EXTRACTION_CACHE_ID) .put(DimFilterCacheHelper.EXTRACTION_CACHE_ID)
.put(dimensionBytes) .put(dimensionBytes)
.put(DimFilterCacheHelper.STRING_SEPARATOR) .put(DimFilterCacheHelper.STRING_SEPARATOR)
.put(valueBytes) .put(valueBytes)
.put(DimFilterCacheHelper.STRING_SEPARATOR)
.put(extractionFnBytes)
.array(); .array();
} }

View File

@ -19,8 +19,8 @@
package io.druid.query.filter; package io.druid.query.filter;
import io.druid.query.extraction.ExtractionFn; import io.druid.query.extraction.IdentityExtractionFn;
import org.easymock.EasyMock; import io.druid.query.extraction.RegexDimExtractionFn;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -35,15 +35,25 @@ public class ExtractionDimFilterTest
ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter( ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter(
"abc", "abc",
"d", "d",
EasyMock.createMock(ExtractionFn.class), new IdentityExtractionFn(),
null null
); );
ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter( ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter(
"ab", "ab",
"cd", "cd",
EasyMock.createMock(ExtractionFn.class), new IdentityExtractionFn(),
null null
); );
Assert.assertFalse(Arrays.equals(extractionDimFilter.getCacheKey(), extractionDimFilter2.getCacheKey())); Assert.assertFalse(Arrays.equals(extractionDimFilter.getCacheKey(), extractionDimFilter2.getCacheKey()));
ExtractionDimFilter extractionDimFilter3 = new ExtractionDimFilter(
"ab",
"cd",
new RegexDimExtractionFn("xx", null, null),
null
);
Assert.assertFalse(Arrays.equals(extractionDimFilter2.getCacheKey(), extractionDimFilter3.getCacheKey()));
} }
} }