use of it.unimi.dsi.fastutil.ints.Int2IntMap in project druid by druid-io.
the class ListFilteredDimensionSpec method filterBlackList.
private DimensionSelector filterBlackList(DimensionSelector selector) {
final int selectorCardinality = selector.getValueCardinality();
if (selectorCardinality < 0 || !selector.nameLookupPossibleInAdvance()) {
return new PredicateFilteredDimensionSelector(selector, new Predicate<String>() {
@Override
public boolean apply(@Nullable String input) {
return !values.contains(input);
}
});
}
final int maxPossibleFilteredCardinality = selectorCardinality;
int count = 0;
final Int2IntMap forwardMapping = new Int2IntOpenHashMap(maxPossibleFilteredCardinality);
forwardMapping.defaultReturnValue(-1);
final int[] reverseMapping = new int[maxPossibleFilteredCardinality];
for (int i = 0; i < selectorCardinality; i++) {
if (!values.contains(Strings.nullToEmpty(selector.lookupName(i)))) {
forwardMapping.put(i, count);
reverseMapping[count++] = i;
}
}
return new ForwardingFilteredDimensionSelector(selector, forwardMapping, reverseMapping);
}
use of it.unimi.dsi.fastutil.ints.Int2IntMap in project druid by druid-io.
the class RegexFilteredDimensionSpec method decorate.
@Override
public DimensionSelector decorate(final DimensionSelector selector) {
if (selector == null) {
return null;
}
final int selectorCardinality = selector.getValueCardinality();
if (selectorCardinality < 0 || !selector.nameLookupPossibleInAdvance()) {
return new PredicateFilteredDimensionSelector(selector, new Predicate<String>() {
@Override
public boolean apply(@Nullable String input) {
return compiledRegex.matcher(Strings.nullToEmpty(input)).matches();
}
});
}
int count = 0;
final Int2IntMap forwardMapping = new Int2IntOpenHashMap();
forwardMapping.defaultReturnValue(-1);
for (int i = 0; i < selectorCardinality; i++) {
if (compiledRegex.matcher(Strings.nullToEmpty(selector.lookupName(i))).matches()) {
forwardMapping.put(i, count++);
}
}
final int[] reverseMapping = new int[forwardMapping.size()];
for (Int2IntMap.Entry e : forwardMapping.int2IntEntrySet()) {
reverseMapping[e.getIntValue()] = e.getIntKey();
}
return new ForwardingFilteredDimensionSelector(selector, forwardMapping, reverseMapping);
}
use of it.unimi.dsi.fastutil.ints.Int2IntMap in project pinot by linkedin.
the class NoDictionarySingleColumnGroupKeyGenerator method getKeyForValue.
@SuppressWarnings("unchecked")
private int getKeyForValue(int value) {
Int2IntMap map = (Int2IntMap) _groupKeyMap;
int groupId = map.get(value);
if (groupId == INVALID_ID) {
groupId = _numGroupKeys;
map.put(value, _numGroupKeys++);
}
return groupId;
}
use of it.unimi.dsi.fastutil.ints.Int2IntMap in project druid by druid-io.
the class ListFilteredDimensionSpec method filterWhiteList.
private DimensionSelector filterWhiteList(DimensionSelector selector) {
final int selectorCardinality = selector.getValueCardinality();
if (selectorCardinality < 0 || (selector.idLookup() == null && !selector.nameLookupPossibleInAdvance())) {
return new PredicateFilteredDimensionSelector(selector, Predicates.in(values));
}
final int maxPossibleFilteredCardinality = values.size();
int count = 0;
final Int2IntMap forwardMapping = new Int2IntOpenHashMap(maxPossibleFilteredCardinality);
forwardMapping.defaultReturnValue(-1);
final int[] reverseMapping = new int[maxPossibleFilteredCardinality];
IdLookup idLookup = selector.idLookup();
if (idLookup != null) {
for (String value : values) {
int i = idLookup.lookupId(value);
if (i >= 0) {
forwardMapping.put(i, count);
reverseMapping[count++] = i;
}
}
} else {
for (int i = 0; i < selectorCardinality; i++) {
if (values.contains(Strings.nullToEmpty(selector.lookupName(i)))) {
forwardMapping.put(i, count);
reverseMapping[count++] = i;
}
}
}
return new ForwardingFilteredDimensionSelector(selector, forwardMapping, reverseMapping);
}
use of it.unimi.dsi.fastutil.ints.Int2IntMap in project pinot by linkedin.
the class NoDictionarySingleColumnGroupKeyGenerator method createGroupKeyMap.
/**
* Helper method to create the group-key map, depending on the data type.
* Uses primitive maps when possible.
*
* @param keyType DataType for the key
* @return Map
*/
private Map createGroupKeyMap(FieldSpec.DataType keyType) {
Map map;
switch(keyType) {
case INT:
Int2IntMap intMap = new Int2IntOpenHashMap();
intMap.defaultReturnValue(INVALID_ID);
map = intMap;
break;
case LONG:
Long2IntOpenHashMap longMap = new Long2IntOpenHashMap();
longMap.defaultReturnValue(INVALID_ID);
map = longMap;
break;
case FLOAT:
Float2IntOpenHashMap floatMap = new Float2IntOpenHashMap();
floatMap.defaultReturnValue(INVALID_ID);
map = floatMap;
break;
case DOUBLE:
Double2IntOpenHashMap doubleMap = new Double2IntOpenHashMap();
doubleMap.defaultReturnValue(INVALID_ID);
map = doubleMap;
break;
case STRING:
Object2IntOpenHashMap<String> stringMap = new Object2IntOpenHashMap<>();
stringMap.defaultReturnValue(INVALID_ID);
map = stringMap;
break;
default:
throw new IllegalArgumentException("Illegal data type for no-dictionary key generator: " + keyType);
}
return map;
}
Aggregations