Replace HistoricalFloatColumnSelector with more generic HistoricalColumnSelector (#4796)

This commit is contained in:
Roman Leventov 2017-09-14 15:52:06 -05:00 committed by Charles Allen
parent a17e48fe69
commit b61248fdb1
12 changed files with 108 additions and 60 deletions

View File

@ -24,21 +24,21 @@ import io.druid.segment.data.IndexedInts;
import io.druid.segment.data.Offset;
import io.druid.segment.historical.HistoricalCursor;
import io.druid.segment.historical.HistoricalDimensionSelector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import java.nio.ByteBuffer;
public class Historical1SimpleDoubleAggPooledTopNScannerPrototype
implements Historical1AggPooledTopNScanner<
HistoricalDimensionSelector,
HistoricalFloatColumnSelector,
HistoricalColumnSelector,
SimpleDoubleBufferAggregator
>
{
@Override
public long scanAndAggregate(
HistoricalDimensionSelector dimensionSelector,
HistoricalFloatColumnSelector metricSelector,
HistoricalColumnSelector metricSelector,
SimpleDoubleBufferAggregator aggregator,
int aggregatorSize,
HistoricalCursor cursor,
@ -52,7 +52,7 @@ public class Historical1SimpleDoubleAggPooledTopNScannerPrototype
int positionToAllocate = 0;
while (offset.withinBounds() && !Thread.currentThread().isInterrupted()) {
int rowNum = offset.getOffset();
double metric = metricSelector.get(rowNum);
double metric = metricSelector.getDouble(rowNum);
final IndexedInts dimValues = dimensionSelector.getRow(rowNum);
final int dimSize = dimValues.size();
for (int i = 0; i < dimSize; i++) {

View File

@ -22,7 +22,7 @@ package io.druid.query.topn;
import io.druid.query.aggregation.SimpleDoubleBufferAggregator;
import io.druid.segment.data.Offset;
import io.druid.segment.historical.HistoricalCursor;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import io.druid.segment.historical.SingleValueHistoricalDimensionSelector;
import java.nio.ByteBuffer;
@ -30,14 +30,14 @@ import java.nio.ByteBuffer;
public class HistoricalSingleValueDimSelector1SimpleDoubleAggPooledTopNScannerPrototype
implements Historical1AggPooledTopNScanner<
SingleValueHistoricalDimensionSelector,
HistoricalFloatColumnSelector,
HistoricalColumnSelector,
SimpleDoubleBufferAggregator
>
{
@Override
public long scanAndAggregate(
SingleValueHistoricalDimensionSelector dimensionSelector,
HistoricalFloatColumnSelector metricSelector,
HistoricalColumnSelector metricSelector,
SimpleDoubleBufferAggregator aggregator,
int aggregatorSize,
HistoricalCursor cursor,
@ -54,10 +54,10 @@ public class HistoricalSingleValueDimSelector1SimpleDoubleAggPooledTopNScannerPr
int dimIndex = dimensionSelector.getRowValue(rowNum);
int position = positions[dimIndex];
if (position >= 0) {
aggregator.aggregate(resultsBuffer, position, metricSelector.get(rowNum));
aggregator.aggregate(resultsBuffer, position, metricSelector.getDouble(rowNum));
} else if (position == TopNAlgorithm.INIT_POSITION_VALUE) {
positions[dimIndex] = positionToAllocate;
aggregator.putFirst(resultsBuffer, positionToAllocate, metricSelector.get(rowNum));
aggregator.putFirst(resultsBuffer, positionToAllocate, metricSelector.getDouble(rowNum));
positionToAllocate += aggregatorSize;
}
processedRows++;

View File

@ -41,7 +41,7 @@ import io.druid.segment.data.IndexedInts;
import io.druid.segment.data.Offset;
import io.druid.segment.historical.HistoricalCursor;
import io.druid.segment.historical.HistoricalDimensionSelector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import io.druid.segment.historical.SingleValueHistoricalDimensionSelector;
import java.nio.ByteBuffer;
@ -131,7 +131,7 @@ public class PooledTopNAlgorithm
final Cursor cursor = params.getCursor();
if (cursor instanceof HistoricalCursor && aggregator instanceof SimpleDoubleBufferAggregator) {
if (params.getDimSelector() instanceof SingleValueHistoricalDimensionSelector &&
((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalFloatColumnSelector) {
((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
return scanAndAggregateHistorical1SimpleDoubleAgg(
params,
positions,
@ -152,7 +152,7 @@ public class PooledTopNAlgorithm
final Cursor cursor = params.getCursor();
if (cursor instanceof HistoricalCursor && aggregator instanceof SimpleDoubleBufferAggregator) {
if (params.getDimSelector() instanceof HistoricalDimensionSelector &&
((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalFloatColumnSelector) {
((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
return scanAndAggregateHistorical1SimpleDoubleAgg(
params,
positions,

View File

@ -20,9 +20,9 @@
package io.druid.segment;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
public final class ZeroFloatColumnSelector implements HistoricalFloatColumnSelector
public final class ZeroFloatColumnSelector implements FloatColumnSelector, HistoricalColumnSelector
{
private static final ZeroFloatColumnSelector INSTANCE = new ZeroFloatColumnSelector();
@ -43,9 +43,9 @@ public final class ZeroFloatColumnSelector implements HistoricalFloatColumnSelec
}
@Override
public float get(int offset)
public double getDouble(int offset)
{
return getFloat();
return 0.0;
}
@Override

View File

@ -22,9 +22,9 @@ package io.druid.segment.column;
import io.druid.query.monomorphicprocessing.CalledFromHotLoop;
import io.druid.query.monomorphicprocessing.HotLoopCallee;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.data.ReadableOffset;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import java.io.Closeable;
@ -41,7 +41,7 @@ public interface GenericColumn extends HotLoopCallee, Closeable
@CalledFromHotLoop
float getFloatSingleValueRow(int rowNum);
HistoricalFloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset);
FloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset);
@CalledFromHotLoop
long getLongSingleValueRow(int rowNum);

View File

@ -21,10 +21,10 @@ package io.druid.segment.column;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.data.IndexedDoubles;
import io.druid.segment.data.ReadableOffset;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
public class IndexedDoublesGenericColumn implements GenericColumn
@ -67,7 +67,7 @@ public class IndexedDoublesGenericColumn implements GenericColumn
}
@Override
public HistoricalFloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
public FloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
{
return column.makeFloatColumnSelector(offset);
}

View File

@ -21,10 +21,10 @@ package io.druid.segment.column;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.data.IndexedFloats;
import io.druid.segment.data.ReadableOffset;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
/**
*/
@ -68,7 +68,7 @@ public class IndexedFloatsGenericColumn implements GenericColumn
}
@Override
public HistoricalFloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
public FloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
{
return column.makeFloatColumnSelector(offset);
}

View File

@ -21,10 +21,10 @@ package io.druid.segment.column;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.data.IndexedLongs;
import io.druid.segment.data.ReadableOffset;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
/**
*/
@ -68,7 +68,7 @@ public class IndexedLongsGenericColumn implements GenericColumn
}
@Override
public HistoricalFloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
public FloatColumnSelector makeFloatSingleValueRowSelector(ReadableOffset offset)
{
return column.makeFloatColumnSelector(offset);
}

View File

@ -21,8 +21,9 @@ package io.druid.segment.data;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import java.io.Closeable;
@ -37,7 +38,7 @@ public interface IndexedDoubles extends Closeable
default DoubleColumnSelector makeDoubleColumnSelector(ReadableOffset offset)
{
return new DoubleColumnSelector()
class HistoricalDoubleColumnSelector implements DoubleColumnSelector, HistoricalColumnSelector
{
@Override
public double getDouble()
@ -45,43 +46,51 @@ public interface IndexedDoubles extends Closeable
return IndexedDoubles.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedDoubles.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedDoubles.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalDoubleColumnSelector();
}
default HistoricalFloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
default FloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
{
return new HistoricalFloatColumnSelector()
class HistoricalFloatColumnSelector implements FloatColumnSelector, HistoricalColumnSelector
{
@Override
public float get(int offset)
{
return (float) IndexedDoubles.this.get(offset);
}
@Override
public float getFloat()
{
return (float) IndexedDoubles.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedDoubles.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedDoubles.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalFloatColumnSelector();
}
default LongColumnSelector makeLongColumnSelector(ReadableOffset offset)
{
return new LongColumnSelector()
class HistoricalLongColumnSelector implements LongColumnSelector, HistoricalColumnSelector
{
@Override
public long getLong()
@ -89,13 +98,20 @@ public interface IndexedDoubles extends Closeable
return (long) IndexedDoubles.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedDoubles.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedDoubles.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalLongColumnSelector();
}
}

View File

@ -21,8 +21,9 @@ package io.druid.segment.data;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import java.io.Closeable;
@ -38,9 +39,9 @@ public interface IndexedFloats extends Closeable
@Override
void close();
default HistoricalFloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
default FloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
{
return new HistoricalFloatColumnSelector()
class HistoricalFloatColumnSelector implements FloatColumnSelector, HistoricalColumnSelector
{
@Override
public float getFloat()
@ -49,7 +50,7 @@ public interface IndexedFloats extends Closeable
}
@Override
public float get(int offset)
public double getDouble(int offset)
{
return IndexedFloats.this.get(offset);
}
@ -60,12 +61,13 @@ public interface IndexedFloats extends Closeable
inspector.visit("indexed", IndexedFloats.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalFloatColumnSelector();
}
default DoubleColumnSelector makeDoubleColumnSelector(ReadableOffset offset)
{
return new DoubleColumnSelector()
class HistoricalDoubleColumnSelector implements DoubleColumnSelector, HistoricalColumnSelector
{
@Override
public double getDouble()
@ -73,18 +75,25 @@ public interface IndexedFloats extends Closeable
return IndexedFloats.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedFloats.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedFloats.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalDoubleColumnSelector();
}
default LongColumnSelector makeLongColumnSelector(ReadableOffset offset)
{
return new LongColumnSelector()
class HistoricalLongColumnSelector implements LongColumnSelector, HistoricalColumnSelector
{
@Override
public long getLong()
@ -92,12 +101,19 @@ public interface IndexedFloats extends Closeable
return (long) IndexedFloats.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedFloats.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedFloats.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalLongColumnSelector();
}
}

View File

@ -21,8 +21,9 @@ package io.druid.segment.data;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.historical.HistoricalFloatColumnSelector;
import io.druid.segment.historical.HistoricalColumnSelector;
import java.io.Closeable;
@ -40,7 +41,7 @@ public interface IndexedLongs extends Closeable
default LongColumnSelector makeLongColumnSelector(ReadableOffset offset)
{
return new LongColumnSelector()
class HistoricalLongColumnSelector implements LongColumnSelector, HistoricalColumnSelector
{
@Override
public long getLong()
@ -48,18 +49,25 @@ public interface IndexedLongs extends Closeable
return IndexedLongs.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedLongs.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedLongs.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalLongColumnSelector();
}
default HistoricalFloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
default FloatColumnSelector makeFloatColumnSelector(ReadableOffset offset)
{
return new HistoricalFloatColumnSelector()
class HistoricalFloatColumnSelector implements FloatColumnSelector, HistoricalColumnSelector
{
@Override
public float getFloat()
@ -68,9 +76,9 @@ public interface IndexedLongs extends Closeable
}
@Override
public float get(int offset)
public double getDouble(int offset)
{
return (float) IndexedLongs.this.get(offset);
return IndexedLongs.this.get(offset);
}
@Override
@ -79,12 +87,13 @@ public interface IndexedLongs extends Closeable
inspector.visit("indexed", IndexedLongs.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalFloatColumnSelector();
}
default DoubleColumnSelector makeDoubleColumnSelector(ReadableOffset offset)
{
return new DoubleColumnSelector()
class HistoricalDoubleColumnSelector implements DoubleColumnSelector, HistoricalColumnSelector
{
@Override
public double getDouble()
@ -92,12 +101,19 @@ public interface IndexedLongs extends Closeable
return (double) IndexedLongs.this.get(offset.getOffset());
}
@Override
public double getDouble(int offset)
{
return IndexedLongs.this.get(offset);
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("indexed", IndexedLongs.this);
inspector.visit("offset", offset);
}
};
}
return new HistoricalDoubleColumnSelector();
}
}

View File

@ -20,10 +20,10 @@
package io.druid.segment.historical;
import io.druid.query.monomorphicprocessing.CalledFromHotLoop;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.ColumnValueSelector;
public interface HistoricalFloatColumnSelector extends FloatColumnSelector
public interface HistoricalColumnSelector extends ColumnValueSelector
{
@CalledFromHotLoop
float get(int offset);
double getDouble(int offset);
}