use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class CompressedVSizeIndexedV3Supplier method fromIterable.
// for test
public static CompressedVSizeIndexedV3Supplier fromIterable(Iterable<IndexedInts> objectsIterable, int offsetChunkFactor, int maxValue, final ByteOrder byteOrder, CompressedObjectStrategy.CompressionStrategy compression) {
Iterator<IndexedInts> objects = objectsIterable.iterator();
List<Integer> offsetList = new ArrayList<>();
List<Integer> values = new ArrayList<>();
int offset = 0;
while (objects.hasNext()) {
IndexedInts next = objects.next();
offsetList.add(offset);
for (int i = 0; i < next.size(); i++) {
values.add(next.get(i));
}
offset += next.size();
}
offsetList.add(offset);
CompressedIntsIndexedSupplier headerSupplier = CompressedIntsIndexedSupplier.fromList(offsetList, offsetChunkFactor, byteOrder, compression);
CompressedVSizeIntsIndexedSupplier valuesSupplier = CompressedVSizeIntsIndexedSupplier.fromList(values, maxValue, CompressedVSizeIntsIndexedSupplier.maxIntsInBufferForValue(maxValue), byteOrder, compression);
return new CompressedVSizeIndexedV3Supplier(headerSupplier, valuesSupplier);
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class Generic1AggPooledTopNScannerPrototype method scanAndAggregate.
@Override
public long scanAndAggregate(DimensionSelector dimensionSelector, BufferAggregator aggregator, int aggregatorSize, Cursor cursor, int[] positions, ByteBuffer resultsBuffer) {
long scannedRows = 0;
int positionToAllocate = 0;
while (!cursor.isDoneOrInterrupted()) {
final IndexedInts dimValues = dimensionSelector.getRow();
final int dimSize = dimValues.size();
for (int i = 0; i < dimSize; i++) {
int dimIndex = dimValues.get(i);
int position = positions[dimIndex];
if (position >= 0) {
aggregator.aggregate(resultsBuffer, position);
} else if (position == TopNAlgorithm.INIT_POSITION_VALUE) {
positions[dimIndex] = positionToAllocate;
position = positionToAllocate;
aggregator.init(resultsBuffer, position);
aggregator.aggregate(resultsBuffer, position);
positionToAllocate += aggregatorSize;
}
}
scannedRows++;
cursor.advanceUninterruptibly();
}
return scannedRows;
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class FilteredAggregatorTest method makeColumnSelector.
private ColumnSelectorFactory makeColumnSelector(final TestFloatColumnSelector selector) {
return new ColumnSelectorFactory() {
@Override
public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec) {
final String dimensionName = dimensionSpec.getDimension();
final ExtractionFn extractionFn = dimensionSpec.getExtractionFn();
if (dimensionName.equals("dim")) {
return dimensionSpec.decorate(new DimensionSelector() {
@Override
public IndexedInts getRow() {
if (selector.getIndex() % 3 == 2) {
return ArrayBasedIndexedInts.of(new int[] { 1 });
} else {
return ArrayBasedIndexedInts.of(new int[] { 0 });
}
}
@Override
public ValueMatcher makeValueMatcher(String value) {
return DimensionSelectorUtils.makeValueMatcherGeneric(this, value);
}
@Override
public ValueMatcher makeValueMatcher(Predicate<String> predicate) {
return DimensionSelectorUtils.makeValueMatcherGeneric(this, predicate);
}
@Override
public int getValueCardinality() {
return 2;
}
@Override
public String lookupName(int id) {
switch(id) {
case 0:
return "a";
case 1:
return "b";
default:
throw new IllegalArgumentException();
}
}
@Override
public boolean nameLookupPossibleInAdvance() {
return true;
}
@Nullable
@Override
public IdLookup idLookup() {
return new IdLookup() {
@Override
public int lookupId(String name) {
switch(name) {
case "a":
return 0;
case "b":
return 1;
default:
throw new IllegalArgumentException();
}
}
};
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
}
});
} else {
throw new UnsupportedOperationException();
}
}
@Override
public LongColumnSelector makeLongColumnSelector(String columnName) {
throw new UnsupportedOperationException();
}
@Override
public FloatColumnSelector makeFloatColumnSelector(String columnName) {
if (columnName.equals("value")) {
return selector;
} else {
throw new UnsupportedOperationException();
}
}
@Override
public ObjectColumnSelector makeObjectColumnSelector(String columnName) {
throw new UnsupportedOperationException();
}
@Override
public ColumnCapabilities getColumnCapabilities(String columnName) {
ColumnCapabilitiesImpl caps;
if (columnName.equals("value")) {
caps = new ColumnCapabilitiesImpl();
caps.setType(ValueType.FLOAT);
caps.setDictionaryEncoded(false);
caps.setHasBitmapIndexes(false);
} else {
caps = new ColumnCapabilitiesImpl();
caps.setType(ValueType.STRING);
caps.setDictionaryEncoded(true);
caps.setHasBitmapIndexes(true);
}
return caps;
}
};
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class ListFilteredDimensionSpecTest method testDecoratorWithBlacklistUsingNonPresentValues.
@Test
public void testDecoratorWithBlacklistUsingNonPresentValues() {
ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "gx"), false);
DimensionSelector selector = spec.decorate(TestDimensionSelector.instance);
Assert.assertEquals(25, selector.getValueCardinality());
IndexedInts row = selector.getRow();
Assert.assertEquals(2, row.size());
Assert.assertEquals(3, row.get(0));
Assert.assertEquals(5, row.get(1));
Assert.assertEquals("e", selector.lookupName(row.get(0)));
Assert.assertEquals("g", selector.lookupName(row.get(1)));
Assert.assertEquals("a", selector.lookupName(0));
Assert.assertEquals("z", selector.lookupName(24));
Assert.assertEquals(0, selector.idLookup().lookupId("a"));
Assert.assertEquals(24, selector.idLookup().lookupId("z"));
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class ListFilteredDimensionSpecTest method testDecoratorWithBlacklist.
@Test
public void testDecoratorWithBlacklist() {
ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "g"), false);
DimensionSelector selector = spec.decorate(TestDimensionSelector.instance);
Assert.assertEquals(24, selector.getValueCardinality());
IndexedInts row = selector.getRow();
Assert.assertEquals(1, row.size());
Assert.assertEquals(3, row.get(0));
Assert.assertEquals("a", selector.lookupName(0));
Assert.assertEquals("z", selector.lookupName(23));
Assert.assertEquals(0, selector.idLookup().lookupId("a"));
Assert.assertEquals(23, selector.idLookup().lookupId("z"));
}
Aggregations