Search in sources :

Example 6 with Rowboat

use of io.druid.segment.Rowboat in project druid by druid-io.

the class IncrementalIndexAdapter method getRows.

@Override
public Iterable<Rowboat> getRows() {
    return new Iterable<Rowboat>() {

        @Override
        public Iterator<Rowboat> iterator() {
            final List<IncrementalIndex.DimensionDesc> dimensions = index.getDimensions();
            final DimensionHandler[] handlers = new DimensionHandler[dimensions.size()];
            final DimensionIndexer[] indexers = new DimensionIndexer[dimensions.size()];
            for (IncrementalIndex.DimensionDesc dimension : dimensions) {
                handlers[dimension.getIndex()] = dimension.getHandler();
                indexers[dimension.getIndex()] = dimension.getIndexer();
            }
            /*
         * Note that the transform function increments a counter to determine the rowNum of
         * the iterated Rowboats. We need to return a new iterator on each
         * iterator() call to ensure the counter starts at 0.
         */
            return Iterators.transform(index.getFacts().entrySet().iterator(), new Function<Map.Entry<IncrementalIndex.TimeAndDims, Integer>, Rowboat>() {

                int count = 0;

                @Override
                public Rowboat apply(Map.Entry<IncrementalIndex.TimeAndDims, Integer> input) {
                    final IncrementalIndex.TimeAndDims timeAndDims = input.getKey();
                    final Object[] dimValues = timeAndDims.getDims();
                    final int rowOffset = input.getValue();
                    Object[] dims = new Object[dimValues.length];
                    for (IncrementalIndex.DimensionDesc dimension : dimensions) {
                        final int dimIndex = dimension.getIndex();
                        if (dimIndex >= dimValues.length || dimValues[dimIndex] == null) {
                            continue;
                        }
                        final DimensionIndexer indexer = indexers[dimIndex];
                        Object sortedDimVals = indexer.convertUnsortedEncodedKeyComponentToSortedEncodedKeyComponent(dimValues[dimIndex]);
                        dims[dimIndex] = sortedDimVals;
                    }
                    Object[] metrics = new Object[index.getMetricAggs().length];
                    for (int i = 0; i < metrics.length; i++) {
                        metrics[i] = index.getMetricObjectValue(rowOffset, i);
                    }
                    return new Rowboat(timeAndDims.getTimestamp(), dims, metrics, count++, handlers);
                }
            });
        }
    };
}
Also used : DimensionHandler(io.druid.segment.DimensionHandler) DimensionIndexer(io.druid.segment.DimensionIndexer) Map(java.util.Map) Rowboat(io.druid.segment.Rowboat)

Aggregations

Rowboat (io.druid.segment.Rowboat)6 DimensionHandler (io.druid.segment.DimensionHandler)3 Test (org.junit.Test)3 IndexableAdapter (io.druid.segment.IndexableAdapter)2 QueryableIndexIndexableAdapter (io.druid.segment.QueryableIndexIndexableAdapter)2 StringDimensionHandler (io.druid.segment.StringDimensionHandler)2 DataSegment (io.druid.timeline.DataSegment)2 Interval (org.joda.time.Interval)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 DimensionIndexer (io.druid.segment.DimensionIndexer)1 IndexMerger (io.druid.segment.IndexMerger)1 QueryableIndex (io.druid.segment.QueryableIndex)1 RowboatFilteringIndexAdapter (io.druid.segment.RowboatFilteringIndexAdapter)1 IncrementalIndexTest (io.druid.segment.data.IncrementalIndexTest)1 TimelineObjectHolder (io.druid.timeline.TimelineObjectHolder)1 VersionedIntervalTimeline (io.druid.timeline.VersionedIntervalTimeline)1 HashBasedNumberedShardSpec (io.druid.timeline.partition.HashBasedNumberedShardSpec)1 PartitionChunk (io.druid.timeline.partition.PartitionChunk)1 File (java.io.File)1