Merge pull request #2219 from himanshug/identity_extraction_fn_singleton

make IdentityExtractionFn singleton
This commit is contained in:
Gian Merlino 2016-01-07 10:08:28 -08:00
commit 4ecd901a1a
5 changed files with 18 additions and 9 deletions

View File

@ -24,6 +24,14 @@ import com.google.common.base.Strings;
public class IdentityExtractionFn implements ExtractionFn public class IdentityExtractionFn implements ExtractionFn
{ {
private static final byte CACHE_TYPE_ID = 0x6; private static final byte CACHE_TYPE_ID = 0x6;
private static final IdentityExtractionFn instance = new IdentityExtractionFn();
private IdentityExtractionFn()
{
}
@Override @Override
public byte[] getCacheKey() public byte[] getCacheKey()
{ {
@ -71,4 +79,9 @@ public class IdentityExtractionFn implements ExtractionFn
{ {
return o != null && o instanceof IdentityExtractionFn; return o != null && o instanceof IdentityExtractionFn;
} }
public static final IdentityExtractionFn getInstance()
{
return instance;
}
} }

View File

@ -48,11 +48,7 @@ public class DimensionSelectorHavingSpec implements HavingSpec
{ {
dimension = Preconditions.checkNotNull(dimName, "Must have attribute 'dimension'"); dimension = Preconditions.checkNotNull(dimName, "Must have attribute 'dimension'");
this.value = value; this.value = value;
if (extractionFn != null) { this.extractionFn = extractionFn != null ? extractionFn : IdentityExtractionFn.getInstance();
this.extractionFn = extractionFn;
} else {
this.extractionFn = new IdentityExtractionFn();
}
} }
@JsonProperty("value") @JsonProperty("value")

View File

@ -121,7 +121,7 @@ public class SearchQueryRunner implements QueryRunner<Result<SearchResultValue>>
final BitmapIndex bitmapIndex = column.getBitmapIndex(); final BitmapIndex bitmapIndex = column.getBitmapIndex();
ExtractionFn extractionFn = dimension.getExtractionFn(); ExtractionFn extractionFn = dimension.getExtractionFn();
if (extractionFn == null) { if (extractionFn == null) {
extractionFn = new IdentityExtractionFn(); extractionFn = IdentityExtractionFn.getInstance();
} }
if (bitmapIndex != null) { if (bitmapIndex != null) {
for (int i = 0; i < bitmapIndex.getCardinality(); ++i) { for (int i = 0; i < bitmapIndex.getCardinality(); ++i) {

View File

@ -35,13 +35,13 @@ public class ExtractionDimFilterTest
ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter( ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter(
"abc", "abc",
"d", "d",
new IdentityExtractionFn(), IdentityExtractionFn.getInstance(),
null null
); );
ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter( ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter(
"ab", "ab",
"cd", "cd",
new IdentityExtractionFn(), IdentityExtractionFn.getInstance(),
null null
); );

View File

@ -162,7 +162,7 @@ public class DimensionSelectorHavingSpecTest
@Test @Test
public void testGetCacheKey() public void testGetCacheKey()
{ {
ExtractionFn extractionFn = new IdentityExtractionFn(); ExtractionFn extractionFn = IdentityExtractionFn.getInstance();
byte[] dimBytes = "dimension".getBytes(Charsets.UTF_8); byte[] dimBytes = "dimension".getBytes(Charsets.UTF_8);
byte[] valBytes = "v".getBytes(Charsets.UTF_8); byte[] valBytes = "v".getBytes(Charsets.UTF_8);
byte[] extFunKey = extractionFn.getCacheKey(); byte[] extFunKey = extractionFn.getCacheKey();