Search in sources :

Example 11 with DimensionIndexer

use of org.apache.druid.segment.DimensionIndexer in project druid by druid-io.

the class OnheapIncrementalIndex method iterableWithPostAggregations.

@Override
public Iterable<Row> iterableWithPostAggregations(@Nullable final List<PostAggregator> postAggs, final boolean descending) {
    final AggregatorFactory[] metrics = getMetricAggs();
    {
        return () -> {
            final List<DimensionDesc> dimensions = getDimensions();
            return Iterators.transform(getFacts().iterator(descending), incrementalIndexRow -> {
                final int rowOffset = incrementalIndexRow.getRowIndex();
                Object[] theDims = incrementalIndexRow.getDims();
                Map<String, Object> theVals = Maps.newLinkedHashMap();
                for (int i = 0; i < theDims.length; ++i) {
                    Object dim = theDims[i];
                    DimensionDesc dimensionDesc = dimensions.get(i);
                    if (dimensionDesc == null) {
                        continue;
                    }
                    String dimensionName = dimensionDesc.getName();
                    DimensionHandler handler = dimensionDesc.getHandler();
                    if (dim == null || handler.getLengthOfEncodedKeyComponent(dim) == 0) {
                        theVals.put(dimensionName, null);
                        continue;
                    }
                    final DimensionIndexer indexer = dimensionDesc.getIndexer();
                    Object rowVals = indexer.convertUnsortedEncodedKeyComponentToActualList(dim);
                    theVals.put(dimensionName, rowVals);
                }
                Aggregator[] aggs = getAggsForRow(rowOffset);
                for (int i = 0; i < aggs.length; ++i) {
                    theVals.put(metrics[i].getName(), aggs[i].get());
                }
                if (postAggs != null) {
                    for (PostAggregator postAgg : postAggs) {
                        theVals.put(postAgg.getName(), postAgg.compute(theVals));
                    }
                }
                return new MapBasedRow(incrementalIndexRow.getTimestamp(), theVals);
            });
        };
    }
}
Also used : DimensionHandler(org.apache.druid.segment.DimensionHandler) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) Aggregator(org.apache.druid.query.aggregation.Aggregator) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) MapBasedRow(org.apache.druid.data.input.MapBasedRow) DimensionIndexer(org.apache.druid.segment.DimensionIndexer)

Aggregations

DimensionIndexer (org.apache.druid.segment.DimensionIndexer)11 Nullable (javax.annotation.Nullable)3 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)3 MutableBitmap (org.apache.druid.collections.bitmap.MutableBitmap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 MapBasedRow (org.apache.druid.data.input.MapBasedRow)1 IAE (org.apache.druid.java.util.common.IAE)1 ISE (org.apache.druid.java.util.common.ISE)1 ParseException (org.apache.druid.java.util.common.parsers.ParseException)1 UnparseableColumnsParseException (org.apache.druid.java.util.common.parsers.UnparseableColumnsParseException)1 Aggregator (org.apache.druid.query.aggregation.Aggregator)1 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)1 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)1 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)1 DimensionHandler (org.apache.druid.segment.DimensionHandler)1 SingleScanTimeDimensionSelector (org.apache.druid.segment.SingleScanTimeDimensionSelector)1