From 6dc69c2f30245d60c867c1d7d2dfbd5b76dd2d58 Mon Sep 17 00:00:00 2001 From: nishantmonu51 Date: Tue, 2 Dec 2014 22:44:33 +0530 Subject: [PATCH] code cleanups & formatting --- ...ApproximateHistogramFoldingAggregator.java | 4 +- .../hyperloglog/HyperUniquesAggregator.java | 4 +- .../segment/incremental/IncrementalIndex.java | 2 +- .../incremental/OffheapIncrementalIndex.java | 65 +++++++++---------- .../incremental/OnheapIncrementalIndex.java | 55 +++++----------- 5 files changed, 53 insertions(+), 77 deletions(-) diff --git a/extensions/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java b/extensions/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java index 1b234cd8fc5..9f5b77a5490 100644 --- a/extensions/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java +++ b/extensions/histogram/src/main/java/io/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java @@ -84,13 +84,13 @@ public class ApproximateHistogramFoldingAggregator implements Aggregator @Override public float getFloat() { - throw new UnsupportedOperationException("ApproximateHistogramAggregator does not support getFloat()"); + throw new UnsupportedOperationException("ApproximateHistogramFoldingAggregator does not support getFloat()"); } @Override public long getLong() { - throw new UnsupportedOperationException("ApproximateHistogramAggregator does not support getLong()"); + throw new UnsupportedOperationException("ApproximateHistogramFoldingAggregator does not support getLong()"); } @Override diff --git a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java index 9602c2333ad..3f12ff877ec 100644 --- a/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java @@ -63,13 +63,13 @@ public class HyperUniquesAggregator implements Aggregator @Override public float getFloat() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("HyperUniquesAggregator does not support getFloat()"); } @Override public long getLong() { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException("HyperUniquesAggregator does not support getLong()"); } @Override diff --git a/processing/src/main/java/io/druid/segment/incremental/IncrementalIndex.java b/processing/src/main/java/io/druid/segment/incremental/IncrementalIndex.java index fdfb9519794..3c2d8844f82 100644 --- a/processing/src/main/java/io/druid/segment/incremental/IncrementalIndex.java +++ b/processing/src/main/java/io/druid/segment/incremental/IncrementalIndex.java @@ -62,7 +62,7 @@ public interface IncrementalIndex extends Iterable, Closeable boolean isEmpty(); - ConcurrentNavigableMap getSubMap(TimeAndDims start, TimeAndDims end); + ConcurrentNavigableMap getSubMap(TimeAndDims start, TimeAndDims end); Integer getMetricIndex(String columnName); diff --git a/processing/src/main/java/io/druid/segment/incremental/OffheapIncrementalIndex.java b/processing/src/main/java/io/druid/segment/incremental/OffheapIncrementalIndex.java index 038668bec30..956e1815fbe 100644 --- a/processing/src/main/java/io/druid/segment/incremental/OffheapIncrementalIndex.java +++ b/processing/src/main/java/io/druid/segment/incremental/OffheapIncrementalIndex.java @@ -22,15 +22,11 @@ package io.druid.segment.incremental; import com.google.common.base.Function; import com.google.common.base.Throwables; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; import com.metamx.common.IAE; import com.metamx.common.ISE; import io.druid.collections.ResourceHolder; @@ -63,8 +59,6 @@ import org.mapdb.DB; import org.mapdb.DBMaker; import org.mapdb.Serializer; -import javax.annotation.Nullable; -import java.io.Closeable; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -80,7 +74,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.WeakHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicInteger; @@ -143,7 +136,7 @@ public class OffheapIncrementalIndex implements IncrementalIndex @Override public LongColumnSelector makeLongColumnSelector(final String columnName) { - if(columnName.equals(Column.TIME_COLUMN_NAME)){ + if (columnName.equals(Column.TIME_COLUMN_NAME)) { return new LongColumnSelector() { @Override @@ -333,18 +326,18 @@ public class OffheapIncrementalIndex implements IncrementalIndex } this.bufferHolder = bufferPool.take(); this.dimValues = new DimensionHolder(); - final DBMaker dbMaker = DBMaker.newMemoryDirectDB() - .transactionDisable() - .asyncWriteEnable() - .cacheSoftRefEnable(); - factsDb = dbMaker.make(); - db = dbMaker.make(); + final DBMaker dbMaker = DBMaker.newMemoryDirectDB() + .transactionDisable() + .asyncWriteEnable() + .cacheSoftRefEnable(); + factsDb = dbMaker.make(); + db = dbMaker.make(); final TimeAndDimsSerializer timeAndDimsSerializer = new TimeAndDimsSerializer(this); this.facts = factsDb.createTreeMap("__facts" + UUID.randomUUID()) - .keySerializer(timeAndDimsSerializer) - .comparator(timeAndDimsSerializer.getComparator()) - .valueSerializer(Serializer.INTEGER) - .make(); + .keySerializer(timeAndDimsSerializer) + .comparator(timeAndDimsSerializer.getComparator()) + .valueSerializer(Serializer.INTEGER) + .make(); } @@ -366,6 +359,7 @@ public class OffheapIncrementalIndex implements IncrementalIndex ); } + @Override public InputRow formatRow(InputRow row) { for (Function rowTransformer : rowTransformers) { @@ -390,6 +384,7 @@ public class OffheapIncrementalIndex implements IncrementalIndex * * @return the number of rows in the data set after adding the InputRow */ + @Override public int add(InputRow row) { row = formatRow(row); @@ -471,22 +466,24 @@ public class OffheapIncrementalIndex implements IncrementalIndex return numEntries.get(); } + @Override public boolean isEmpty() { return numEntries.get() == 0; } + @Override public int size() { return numEntries.get(); } - public long getMinTimeMillis() + private long getMinTimeMillis() { return facts.firstKey().getTimestamp(); } - public long getMaxTimeMillis() + private long getMaxTimeMillis() { return facts.lastKey().getTimestamp(); } @@ -509,61 +506,61 @@ public class OffheapIncrementalIndex implements IncrementalIndex return retVal; } + @Override public AggregatorFactory[] getMetricAggs() { return metrics; } + @Override public List getDimensions() { return dimensions; } + @Override public String getMetricType(String metric) { return metricTypes.get(metric); } - public long getMinTimestamp() - { - return minTimestamp; - } - - public QueryGranularity getGranularity() - { - return gran; - } - + @Override public Interval getInterval() { return new Interval(minTimestamp, isEmpty() ? minTimestamp : gran.next(getMaxTimeMillis())); } + @Override public DateTime getMinTime() { return isEmpty() ? null : new DateTime(getMinTimeMillis()); } + @Override public DateTime getMaxTime() { return isEmpty() ? null : new DateTime(getMaxTimeMillis()); } + @Override public DimDim getDimension(String dimension) { return isEmpty() ? null : dimValues.get(dimension); } + @Override public Integer getDimensionIndex(String dimension) { return dimensionOrder.get(dimension); } + @Override public List getMetricNames() { return metricNames; } + @Override public Integer getMetricIndex(String metricName) { return metricIndexes.get(metricName); @@ -592,16 +589,19 @@ public class OffheapIncrementalIndex implements IncrementalIndex return aggs[aggOffset].get(bufferHolder.get(), getMetricPosition(rowOffset, aggOffset)); } + @Override public ColumnCapabilities getCapabilities(String column) { return columnCapabilities.get(column); } + @Override public ConcurrentNavigableMap getFacts() { return facts; } + @Override public ConcurrentNavigableMap getSubMap(TimeAndDims start, TimeAndDims end) { return facts.subMap(start, end); @@ -678,11 +678,6 @@ public class OffheapIncrementalIndex implements IncrementalIndex dimensions = Maps.newConcurrentMap(); } - void reset() - { - dimensions.clear(); - } - DimDim add(String dimension) { DimDim holder = dimensions.get(dimension); diff --git a/processing/src/main/java/io/druid/segment/incremental/OnheapIncrementalIndex.java b/processing/src/main/java/io/druid/segment/incremental/OnheapIncrementalIndex.java index 83e652f1e66..47195073031 100644 --- a/processing/src/main/java/io/druid/segment/incremental/OnheapIncrementalIndex.java +++ b/processing/src/main/java/io/druid/segment/incremental/OnheapIncrementalIndex.java @@ -27,11 +27,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; import com.metamx.common.IAE; import com.metamx.common.ISE; -import io.druid.collections.StupidPool; import io.druid.data.input.InputRow; import io.druid.data.input.MapBasedRow; import io.druid.data.input.Row; @@ -56,9 +53,6 @@ import io.druid.segment.serde.ComplexMetrics; import org.joda.time.DateTime; import org.joda.time.Interval; -import javax.annotation.Nullable; -import java.io.Closeable; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -161,14 +155,10 @@ public class OnheapIncrementalIndex implements IncrementalIndex columnCapabilities.put(spatialDimension.getDimName(), capabilities); } this.dimValues = new DimensionHolder(); - this.facts = createFactsTable(); + this.facts = new ConcurrentSkipListMap<>(); this.deserializeComplexMetrics = deserializeComplexMetrics; } - protected ConcurrentNavigableMap createFactsTable() { - return new ConcurrentSkipListMap<>(); - } - public OnheapIncrementalIndex( long minTimestamp, QueryGranularity gran, @@ -207,6 +197,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex ); } + @Override public InputRow formatRow(InputRow row) { for (Function rowTransformer : rowTransformers) { @@ -231,6 +222,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex * * @return the number of rows in the data set after adding the InputRow */ + @Override public int add(InputRow row) { row = formatRow(row); @@ -287,7 +279,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex final TimeAndDims key = new TimeAndDims(Math.max(gran.truncate(row.getTimestampFromEpoch()), minTimestamp), dims); Integer rowOffset; synchronized (this) { - rowOffset = numEntries.get(); + rowOffset = numEntries.get(); final Integer prev = facts.putIfAbsent(key, rowOffset); if (prev != null) { rowOffset = prev; @@ -301,7 +293,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex @Override public LongColumnSelector makeLongColumnSelector(final String columnName) { - if(columnName.equals(Column.TIME_COLUMN_NAME)){ + if (columnName.equals(Column.TIME_COLUMN_NAME)) { return new LongColumnSelector() { @Override @@ -459,11 +451,13 @@ public class OnheapIncrementalIndex implements IncrementalIndex return numEntries.get(); } + @Override public boolean isEmpty() { return numEntries.get() == 0; } + @Override public int size() { return numEntries.get(); @@ -487,12 +481,12 @@ public class OnheapIncrementalIndex implements IncrementalIndex return aggList.get(rowOffset)[aggOffset].get(); } - public long getMinTimeMillis() + private long getMinTimeMillis() { return facts.firstKey().getTimestamp(); } - public long getMaxTimeMillis() + private long getMaxTimeMillis() { return facts.lastKey().getTimestamp(); } @@ -515,31 +509,24 @@ public class OnheapIncrementalIndex implements IncrementalIndex return retVal; } + @Override public AggregatorFactory[] getMetricAggs() { return metrics; } + @Override public List getDimensions() { return dimensions; } + @Override public String getMetricType(String metric) { return metricTypes.get(metric); } - public long getMinTimestamp() - { - return minTimestamp; - } - - public QueryGranularity getGranularity() - { - return gran; - } - public Interval getInterval() { return new Interval(minTimestamp, isEmpty() ? minTimestamp : gran.next(getMaxTimeMillis())); @@ -575,11 +562,6 @@ public class OnheapIncrementalIndex implements IncrementalIndex return metricIndexes.get(metricName); } - Aggregator getAggregator(int rowOffset, int metricIndex) - { - return aggList.get(rowOffset)[metricIndex]; - } - public ColumnCapabilities getCapabilities(String column) { return columnCapabilities.get(column); @@ -601,6 +583,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex return iterableWithPostAggregations(null).iterator(); } + @Override public Iterable iterableWithPostAggregations(final List postAggs) { return new Iterable() @@ -649,6 +632,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex @Override public void close() { + // Nothing to close } class DimensionHolder @@ -660,11 +644,6 @@ public class OnheapIncrementalIndex implements IncrementalIndex dimensions = Maps.newConcurrentMap(); } - void reset() - { - dimensions.clear(); - } - DimDim add(String dimension) { DimDim holder = dimensions.get(dimension); @@ -683,7 +662,8 @@ public class OnheapIncrementalIndex implements IncrementalIndex } } - private static class DimDimImpl implements DimDim{ + private static class DimDimImpl implements DimDim + { private final Map falseIds; private final Map falseIdsReverse; private volatile String[] sortedVals = null; @@ -699,6 +679,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex /** * Returns the interned String value to allow fast comparisons using `==` instead of `.equals()` + * * @see io.druid.segment.incremental.IncrementalIndexStorageAdapter.EntryHolderValueMatcherFactory#makeValueMatcher(String, String) */ public String get(String str) @@ -772,7 +753,7 @@ public class OnheapIncrementalIndex implements IncrementalIndex public boolean compareCannonicalValues(String s1, String s2) { - return s1 ==s2; + return s1 == s2; } } }