Search in sources :

Example 1 with Int2IntMap

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);
}
Also used : Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 2 with Int2IntMap

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);
}
Also used : Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 3 with Int2IntMap

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;
}
Also used : Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 4 with Int2IntMap

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);
}
Also used : IdLookup(io.druid.segment.IdLookup) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Example 5 with Int2IntMap

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;
}
Also used : Long2IntOpenHashMap(it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap) Float2IntOpenHashMap(it.unimi.dsi.fastutil.floats.Float2IntOpenHashMap) Double2IntOpenHashMap(it.unimi.dsi.fastutil.doubles.Double2IntOpenHashMap) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) Double2IntOpenHashMap(it.unimi.dsi.fastutil.doubles.Double2IntOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap) Float2IntMap(it.unimi.dsi.fastutil.floats.Float2IntMap) Double2IntMap(it.unimi.dsi.fastutil.doubles.Double2IntMap) Long2IntOpenHashMap(it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) Map(java.util.Map) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Float2IntOpenHashMap(it.unimi.dsi.fastutil.floats.Float2IntOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap)

Aggregations

Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)5 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)4 IdLookup (io.druid.segment.IdLookup)1 Double2IntMap (it.unimi.dsi.fastutil.doubles.Double2IntMap)1 Double2IntOpenHashMap (it.unimi.dsi.fastutil.doubles.Double2IntOpenHashMap)1 Float2IntMap (it.unimi.dsi.fastutil.floats.Float2IntMap)1 Float2IntOpenHashMap (it.unimi.dsi.fastutil.floats.Float2IntOpenHashMap)1 Long2IntMap (it.unimi.dsi.fastutil.longs.Long2IntMap)1 Long2IntOpenHashMap (it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap)1 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)1 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 Map (java.util.Map)1