Search in sources :

Example 1 with MappingIterator

use of com.fasterxml.jackson.databind.MappingIterator in project druid by druid-io.

the class SpillingGrouper method iterator.

@Override
public Iterator<Entry<KeyType>> iterator(final boolean sorted) {
    final List<Iterator<Entry<KeyType>>> iterators = new ArrayList<>(1 + files.size());
    iterators.add(grouper.iterator(sorted));
    for (final File file : files) {
        final MappingIterator<Entry<KeyType>> fileIterator = read(file, keySerde.keyClazz());
        iterators.add(Iterators.transform(fileIterator, new Function<Entry<KeyType>, Entry<KeyType>>() {

            @Override
            public Entry<KeyType> apply(Entry<KeyType> entry) {
                final Object[] deserializedValues = new Object[entry.getValues().length];
                for (int i = 0; i < deserializedValues.length; i++) {
                    deserializedValues[i] = aggregatorFactories[i].deserialize(entry.getValues()[i]);
                    if (deserializedValues[i] instanceof Integer) {
                        // Hack to satisfy the groupBy unit tests; perhaps we could do better by adjusting Jackson config.
                        deserializedValues[i] = ((Integer) deserializedValues[i]).longValue();
                    }
                }
                return new Entry<>(entry.getKey(), deserializedValues);
            }
        }));
        closeables.add(fileIterator);
    }
    return Groupers.mergeIterators(iterators, sorted ? keyObjComparator : null);
}
Also used : Function(com.google.common.base.Function) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) File(java.io.File)

Aggregations

MappingIterator (com.fasterxml.jackson.databind.MappingIterator)1 Function (com.google.common.base.Function)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1