Search in sources :

Example 1 with Column

use of io.druid.segment.column.Column in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getDimValueLookup.

@Override
public Indexed<Comparable> getDimValueLookup(String dimension) {
    final Column column = input.getColumn(dimension);
    if (column == null) {
        return null;
    }
    final DictionaryEncodedColumn dict = column.getDictionaryEncoding();
    if (dict == null) {
        return null;
    }
    return new Indexed<Comparable>() {

        @Override
        public Class<? extends Comparable> getClazz() {
            return Comparable.class;
        }

        @Override
        public int size() {
            return dict.getCardinality();
        }

        @Override
        public Comparable get(int index) {
            return dict.lookupName(index);
        }

        @Override
        public int indexOf(Comparable value) {
            return dict.lookupId(value);
        }

        @Override
        public Iterator<Comparable> iterator() {
            return IndexedIterable.create(this).iterator();
        }
    };
}
Also used : IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) ListIndexed(io.druid.segment.data.ListIndexed) Indexed(io.druid.segment.data.Indexed)

Example 2 with Column

use of io.druid.segment.column.Column in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getRows.

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

        @Override
        public Iterator<Rowboat> iterator() {
            return new Iterator<Rowboat>() {

                final GenericColumn timestamps = input.getColumn(Column.TIME_COLUMN_NAME).getGenericColumn();

                final Closeable[] metrics;

                final Closeable[] columns;

                final Closer closer = Closer.create();

                final int numMetrics = getMetricNames().size();

                final DimensionHandler[] handlers = new DimensionHandler[availableDimensions.size()];

                Collection<DimensionHandler> handlerSet = input.getDimensionHandlers().values();

                int currRow = 0;

                boolean done = false;

                {
                    closer.register(timestamps);
                    handlerSet.toArray(handlers);
                    this.columns = FluentIterable.from(handlerSet).transform(new Function<DimensionHandler, Closeable>() {

                        @Override
                        public Closeable apply(DimensionHandler handler) {
                            Column column = input.getColumn(handler.getDimensionName());
                            return handler.getSubColumn(column);
                        }
                    }).toArray(Closeable.class);
                    for (Closeable column : columns) {
                        closer.register(column);
                    }
                    final Indexed<String> availableMetrics = getMetricNames();
                    metrics = new Closeable[availableMetrics.size()];
                    for (int i = 0; i < metrics.length; ++i) {
                        final Column column = input.getColumn(availableMetrics.get(i));
                        final ValueType type = column.getCapabilities().getType();
                        switch(type) {
                            case FLOAT:
                            case LONG:
                                metrics[i] = column.getGenericColumn();
                                break;
                            case COMPLEX:
                                metrics[i] = column.getComplexColumn();
                                break;
                            default:
                                throw new ISE("Cannot handle type[%s]", type);
                        }
                    }
                    for (Closeable metricColumn : metrics) {
                        closer.register(metricColumn);
                    }
                }

                @Override
                public boolean hasNext() {
                    final boolean hasNext = currRow < numRows;
                    if (!hasNext && !done) {
                        CloseQuietly.close(closer);
                        done = true;
                    }
                    return hasNext;
                }

                @Override
                public Rowboat next() {
                    if (!hasNext()) {
                        throw new NoSuchElementException();
                    }
                    final Object[] dims = new Object[columns.length];
                    int dimIndex = 0;
                    for (final Closeable column : columns) {
                        dims[dimIndex] = handlers[dimIndex].getEncodedKeyComponentFromColumn(column, currRow);
                        dimIndex++;
                    }
                    Object[] metricArray = new Object[numMetrics];
                    for (int i = 0; i < metricArray.length; ++i) {
                        if (metrics[i] instanceof IndexedFloatsGenericColumn) {
                            metricArray[i] = ((GenericColumn) metrics[i]).getFloatSingleValueRow(currRow);
                        } else if (metrics[i] instanceof IndexedLongsGenericColumn) {
                            metricArray[i] = ((GenericColumn) metrics[i]).getLongSingleValueRow(currRow);
                        } else if (metrics[i] instanceof ComplexColumn) {
                            metricArray[i] = ((ComplexColumn) metrics[i]).getRowValue(currRow);
                        }
                    }
                    final Rowboat retVal = new Rowboat(timestamps.getLongSingleValueRow(currRow), dims, metricArray, currRow, handlers);
                    ++currRow;
                    return retVal;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : Closer(com.google.common.io.Closer) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) IndexedIterable(io.druid.segment.data.IndexedIterable) FluentIterable(com.google.common.collect.FluentIterable) ValueType(io.druid.segment.column.ValueType) Closeable(java.io.Closeable) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) Iterator(java.util.Iterator) Collection(java.util.Collection) ISE(io.druid.java.util.common.ISE) NoSuchElementException(java.util.NoSuchElementException) ComplexColumn(io.druid.segment.column.ComplexColumn)

Example 3 with Column

use of io.druid.segment.column.Column in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getBitmapIndex.

@Override
public IndexedInts getBitmapIndex(String dimension, int dictId) {
    final Column column = input.getColumn(dimension);
    if (column == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    final BitmapIndex bitmaps = column.getBitmapIndex();
    if (bitmaps == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    if (dictId >= 0) {
        return new BitmapCompressedIndexedInts(bitmaps.getBitmap(dictId));
    } else {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
}
Also used : IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) BitmapCompressedIndexedInts(io.druid.segment.data.BitmapCompressedIndexedInts) BitmapIndex(io.druid.segment.column.BitmapIndex)

Example 4 with Column

use of io.druid.segment.column.Column in project druid by druid-io.

the class QueryableIndexIndexableAdapter method getBitmapIndex.

@VisibleForTesting
IndexedInts getBitmapIndex(String dimension, String value) {
    final Column column = input.getColumn(dimension);
    if (column == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    final BitmapIndex bitmaps = column.getBitmapIndex();
    if (bitmaps == null) {
        return EmptyIndexedInts.EMPTY_INDEXED_INTS;
    }
    return new BitmapCompressedIndexedInts(bitmaps.getBitmap(bitmaps.getIndex(value)));
}
Also used : IndexedLongsGenericColumn(io.druid.segment.column.IndexedLongsGenericColumn) GenericColumn(io.druid.segment.column.GenericColumn) ComplexColumn(io.druid.segment.column.ComplexColumn) Column(io.druid.segment.column.Column) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn) IndexedFloatsGenericColumn(io.druid.segment.column.IndexedFloatsGenericColumn) BitmapCompressedIndexedInts(io.druid.segment.data.BitmapCompressedIndexedInts) BitmapIndex(io.druid.segment.column.BitmapIndex) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with Column

use of io.druid.segment.column.Column in project druid by druid-io.

the class UseIndexesStrategy method makeTimeFilteredBitmap.

static ImmutableBitmap makeTimeFilteredBitmap(final QueryableIndex index, final Segment segment, final Filter filter, final Interval interval) {
    final BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions();
    final ImmutableBitmap baseFilter;
    if (filter == null) {
        baseFilter = null;
    } else {
        final BitmapIndexSelector selector = new ColumnSelectorBitmapIndexSelector(index.getBitmapFactoryForDimensions(), VirtualColumns.EMPTY, index);
        Preconditions.checkArgument(filter.supportsBitmapIndex(selector), "filter[%s] should support bitmap", filter);
        baseFilter = filter.getBitmapIndex(selector);
    }
    final ImmutableBitmap timeFilteredBitmap;
    if (!interval.contains(segment.getDataInterval())) {
        final MutableBitmap timeBitmap = bitmapFactory.makeEmptyMutableBitmap();
        final Column timeColumn = index.getColumn(Column.TIME_COLUMN_NAME);
        try (final GenericColumn timeValues = timeColumn.getGenericColumn()) {
            int startIndex = Math.max(0, getStartIndexOfTime(timeValues, interval.getStartMillis(), true));
            int endIndex = Math.min(timeValues.length() - 1, getStartIndexOfTime(timeValues, interval.getEndMillis(), false));
            for (int i = startIndex; i <= endIndex; i++) {
                timeBitmap.add(i);
            }
            final ImmutableBitmap finalTimeBitmap = bitmapFactory.makeImmutableBitmap(timeBitmap);
            timeFilteredBitmap = (baseFilter == null) ? finalTimeBitmap : finalTimeBitmap.intersection(baseFilter);
        }
    } else {
        timeFilteredBitmap = baseFilter;
    }
    return timeFilteredBitmap;
}
Also used : ColumnSelectorBitmapIndexSelector(io.druid.segment.ColumnSelectorBitmapIndexSelector) GenericColumn(io.druid.segment.column.GenericColumn) ImmutableBitmap(io.druid.collections.bitmap.ImmutableBitmap) GenericColumn(io.druid.segment.column.GenericColumn) Column(io.druid.segment.column.Column) MutableBitmap(io.druid.collections.bitmap.MutableBitmap) ColumnSelectorBitmapIndexSelector(io.druid.segment.ColumnSelectorBitmapIndexSelector) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) BitmapFactory(io.druid.collections.bitmap.BitmapFactory)

Aggregations

Column (io.druid.segment.column.Column)11 GenericColumn (io.druid.segment.column.GenericColumn)8 ComplexColumn (io.druid.segment.column.ComplexColumn)7 DictionaryEncodedColumn (io.druid.segment.column.DictionaryEncodedColumn)7 IndexedFloatsGenericColumn (io.druid.segment.column.IndexedFloatsGenericColumn)5 IndexedLongsGenericColumn (io.druid.segment.column.IndexedLongsGenericColumn)5 BitmapIndex (io.druid.segment.column.BitmapIndex)4 ISE (io.druid.java.util.common.ISE)3 ValueType (io.druid.segment.column.ValueType)3 BitmapFactory (io.druid.collections.bitmap.BitmapFactory)2 ImmutableBitmap (io.druid.collections.bitmap.ImmutableBitmap)2 BitmapCompressedIndexedInts (io.druid.segment.data.BitmapCompressedIndexedInts)2 Indexed (io.druid.segment.data.Indexed)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FluentIterable (com.google.common.collect.FluentIterable)1 Closer (com.google.common.io.Closer)1 ConciseBitmapFactory (io.druid.collections.bitmap.ConciseBitmapFactory)1 MutableBitmap (io.druid.collections.bitmap.MutableBitmap)1