From 82ea34800380c63fd5be7e28d5875280a440e4d7 Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Wed, 16 Dec 2015 14:00:38 -0600 Subject: [PATCH] add extractionFn bytes to cache key in ExtractionDimFilter --- .../query/filter/ExtractionDimFilter.java | 6 ++++-- .../query/filter/ExtractionDimFilterTest.java | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/processing/src/main/java/io/druid/query/filter/ExtractionDimFilter.java b/processing/src/main/java/io/druid/query/filter/ExtractionDimFilter.java index 14ade3e8306..ceaace31a57 100644 --- a/processing/src/main/java/io/druid/query/filter/ExtractionDimFilter.java +++ b/processing/src/main/java/io/druid/query/filter/ExtractionDimFilter.java @@ -78,12 +78,14 @@ public class ExtractionDimFilter implements DimFilter { byte[] dimensionBytes = StringUtils.toUtf8(dimension); byte[] valueBytes = StringUtils.toUtf8(value); - - return ByteBuffer.allocate(2 + dimensionBytes.length + valueBytes.length) + byte[] extractionFnBytes = extractionFn.getCacheKey(); + return ByteBuffer.allocate(3 + dimensionBytes.length + valueBytes.length + extractionFnBytes.length) .put(DimFilterCacheHelper.EXTRACTION_CACHE_ID) .put(dimensionBytes) .put(DimFilterCacheHelper.STRING_SEPARATOR) .put(valueBytes) + .put(DimFilterCacheHelper.STRING_SEPARATOR) + .put(extractionFnBytes) .array(); } diff --git a/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java b/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java index d686cedce2e..44138b9f77f 100644 --- a/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java +++ b/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java @@ -19,8 +19,8 @@ package io.druid.query.filter; -import io.druid.query.extraction.ExtractionFn; -import org.easymock.EasyMock; +import io.druid.query.extraction.IdentityExtractionFn; +import io.druid.query.extraction.RegexDimExtractionFn; import org.junit.Assert; import org.junit.Test; @@ -35,15 +35,25 @@ public class ExtractionDimFilterTest ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter( "abc", "d", - EasyMock.createMock(ExtractionFn.class), + new IdentityExtractionFn(), null ); ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter( "ab", "cd", - EasyMock.createMock(ExtractionFn.class), + new IdentityExtractionFn(), null ); + 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())); } }