use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class RegexFilteredDimensionSpecTest method testDecorator.
@Test
public void testDecorator() {
RegexFilteredDimensionSpec spec = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), "[c,g]");
DimensionSelector selector = spec.decorate(TestDimensionSelector.instance);
Assert.assertEquals(2, selector.getValueCardinality());
IndexedInts row = selector.getRow();
Assert.assertEquals(2, row.size());
Assert.assertEquals(0, row.get(0));
Assert.assertEquals(1, row.get(1));
Assert.assertEquals("c", selector.lookupName(0));
Assert.assertEquals("g", selector.lookupName(1));
Assert.assertEquals(0, selector.idLookup().lookupId("c"));
Assert.assertEquals(1, selector.idLookup().lookupId("g"));
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class NullDimensionSelectorTest method testGetRow.
@Test
public void testGetRow() throws Exception {
IndexedInts row = selector.getRow();
Assert.assertEquals(1, row.size());
Assert.assertEquals(0, row.get(0));
Iterator<Integer> iter = row.iterator();
Assert.assertEquals(true, iter.hasNext());
Assert.assertEquals(0, iter.next().intValue());
Assert.assertEquals(false, iter.hasNext());
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class RowBasedGrouperHelper method getValueSuppliersForDimensions.
@SuppressWarnings("unchecked")
private static Supplier<Comparable>[] getValueSuppliersForDimensions(final ColumnSelectorFactory columnSelectorFactory, final List<DimensionSpec> dimensions, final Map<String, ValueType> rawInputRowSignature) {
final Supplier[] inputRawSuppliers = new Supplier[dimensions.size()];
for (int i = 0; i < dimensions.size(); i++) {
final ColumnValueSelector selector = DimensionHandlerUtils.getColumnValueSelectorFromDimensionSpec(dimensions.get(i), columnSelectorFactory);
ValueType type = rawInputRowSignature.get(dimensions.get(i).getDimension());
if (type == null) {
// Subquery post-aggs aren't added to the rowSignature (see rowSignatureFor() in GroupByQueryHelper) because
// their types aren't known, so default to String handling.
type = ValueType.STRING;
}
switch(type) {
case STRING:
inputRawSuppliers[i] = new Supplier<Comparable>() {
@Override
public Comparable get() {
final String value;
IndexedInts index = ((DimensionSelector) selector).getRow();
value = index.size() == 0 ? "" : ((DimensionSelector) selector).lookupName(index.get(0));
return Strings.nullToEmpty(value);
}
};
break;
case LONG:
inputRawSuppliers[i] = new Supplier<Comparable>() {
@Override
public Comparable get() {
return ((LongColumnSelector) selector).get();
}
};
break;
case FLOAT:
inputRawSuppliers[i] = new Supplier<Comparable>() {
@Override
public Comparable get() {
return ((FloatColumnSelector) selector).get();
}
};
break;
default:
throw new IAE("invalid type: [%s]", type);
}
}
return inputRawSuppliers;
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class StringGroupByColumnSelectorStrategy method initColumnValues.
@Override
public void initColumnValues(ColumnValueSelector selector, int columnIndex, Object[] valuess) {
DimensionSelector dimSelector = (DimensionSelector) selector;
IndexedInts row = dimSelector.getRow();
valuess[columnIndex] = row;
}
use of io.druid.segment.data.IndexedInts in project druid by druid-io.
the class ForwardingFilteredDimensionSelector method makeValueMatcher.
@Override
public ValueMatcher makeValueMatcher(final String value) {
IdLookup idLookup = idLookup();
if (idLookup != null) {
final int valueId = idLookup.lookupId(value);
if (valueId >= 0 || value == null) {
return new ValueMatcher() {
@Override
public boolean matches() {
final IndexedInts baseRow = selector.getRow();
final int baseRowSize = baseRow.size();
boolean nullRow = true;
for (int i = 0; i < baseRowSize; i++) {
int forwardedValue = forwardMapping.get(baseRow.get(i));
if (forwardedValue >= 0) {
// valueId is -1, we don't want to return true from matches().
if (forwardedValue == valueId) {
return true;
}
nullRow = false;
}
}
// null should match empty rows in multi-value columns
return nullRow && value == null;
}
};
} else {
return BooleanValueMatcher.of(false);
}
} else {
// Employ precomputed BitSet optimization
return makeValueMatcher(Predicates.equalTo(value));
}
}
Aggregations