use of io.druid.segment.ColumnValueSelector 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;
}
Aggregations