From 217079d0c759840f7e02e4c6d80a24b0b0edee37 Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Wed, 6 Jan 2016 22:29:07 -0600 Subject: [PATCH] make IdentityExtractionFn singleton --- .../query/extraction/IdentityExtractionFn.java | 13 +++++++++++++ .../groupby/having/DimensionSelectorHavingSpec.java | 6 +----- .../io/druid/query/search/SearchQueryRunner.java | 2 +- .../druid/query/filter/ExtractionDimFilterTest.java | 4 ++-- .../having/DimensionSelectorHavingSpecTest.java | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/processing/src/main/java/io/druid/query/extraction/IdentityExtractionFn.java b/processing/src/main/java/io/druid/query/extraction/IdentityExtractionFn.java index 63afd3d9e48..76a71977084 100644 --- a/processing/src/main/java/io/druid/query/extraction/IdentityExtractionFn.java +++ b/processing/src/main/java/io/druid/query/extraction/IdentityExtractionFn.java @@ -24,6 +24,14 @@ import com.google.common.base.Strings; public class IdentityExtractionFn implements ExtractionFn { private static final byte CACHE_TYPE_ID = 0x6; + + private static final IdentityExtractionFn instance = new IdentityExtractionFn(); + + private IdentityExtractionFn() + { + + } + @Override public byte[] getCacheKey() { @@ -71,4 +79,9 @@ public class IdentityExtractionFn implements ExtractionFn { return o != null && o instanceof IdentityExtractionFn; } + + public static final IdentityExtractionFn getInstance() + { + return instance; + } } diff --git a/processing/src/main/java/io/druid/query/groupby/having/DimensionSelectorHavingSpec.java b/processing/src/main/java/io/druid/query/groupby/having/DimensionSelectorHavingSpec.java index 822bdfba130..542472f8507 100644 --- a/processing/src/main/java/io/druid/query/groupby/having/DimensionSelectorHavingSpec.java +++ b/processing/src/main/java/io/druid/query/groupby/having/DimensionSelectorHavingSpec.java @@ -48,11 +48,7 @@ public class DimensionSelectorHavingSpec implements HavingSpec { dimension = Preconditions.checkNotNull(dimName, "Must have attribute 'dimension'"); this.value = value; - if (extractionFn != null) { - this.extractionFn = extractionFn; - } else { - this.extractionFn = new IdentityExtractionFn(); - } + this.extractionFn = extractionFn != null ? extractionFn : IdentityExtractionFn.getInstance(); } @JsonProperty("value") diff --git a/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java b/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java index 2be205b83e2..1a7571bd218 100644 --- a/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java +++ b/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java @@ -121,7 +121,7 @@ public class SearchQueryRunner implements QueryRunner> final BitmapIndex bitmapIndex = column.getBitmapIndex(); ExtractionFn extractionFn = dimension.getExtractionFn(); if (extractionFn == null) { - extractionFn = new IdentityExtractionFn(); + extractionFn = IdentityExtractionFn.getInstance(); } if (bitmapIndex != null) { for (int i = 0; i < bitmapIndex.getCardinality(); ++i) { 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 44138b9f77f..83bd406495d 100644 --- a/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java +++ b/processing/src/test/java/io/druid/query/filter/ExtractionDimFilterTest.java @@ -35,13 +35,13 @@ public class ExtractionDimFilterTest ExtractionDimFilter extractionDimFilter = new ExtractionDimFilter( "abc", "d", - new IdentityExtractionFn(), + IdentityExtractionFn.getInstance(), null ); ExtractionDimFilter extractionDimFilter2 = new ExtractionDimFilter( "ab", "cd", - new IdentityExtractionFn(), + IdentityExtractionFn.getInstance(), null ); diff --git a/processing/src/test/java/io/druid/query/groupby/having/DimensionSelectorHavingSpecTest.java b/processing/src/test/java/io/druid/query/groupby/having/DimensionSelectorHavingSpecTest.java index 01c7c01c1f0..c1f6fc13633 100644 --- a/processing/src/test/java/io/druid/query/groupby/having/DimensionSelectorHavingSpecTest.java +++ b/processing/src/test/java/io/druid/query/groupby/having/DimensionSelectorHavingSpecTest.java @@ -162,7 +162,7 @@ public class DimensionSelectorHavingSpecTest @Test public void testGetCacheKey() { - ExtractionFn extractionFn = new IdentityExtractionFn(); + ExtractionFn extractionFn = IdentityExtractionFn.getInstance(); byte[] dimBytes = "dimension".getBytes(Charsets.UTF_8); byte[] valBytes = "v".getBytes(Charsets.UTF_8); byte[] extFunKey = extractionFn.getCacheKey();