Search in sources :

Example 6 with BaseColumn

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

the class BroadcastSegmentIndexedTableTest method checkNonIndexedReader.

private void checkNonIndexedReader(String columnName) {
    checkColumnSelectorFactory(columnName);
    try (final Closer closer = Closer.create()) {
        final int columnIndex = columnNames.indexOf(columnName);
        final int numRows = backingSegment.asStorageAdapter().getNumRows();
        final IndexedTable.Reader reader = broadcastTable.columnReader(columnIndex);
        closer.register(reader);
        final SimpleAscendingOffset offset = new SimpleAscendingOffset(numRows);
        final BaseColumn theColumn = backingSegment.asQueryableIndex().getColumnHolder(columnName).getColumn();
        closer.register(theColumn);
        final BaseObjectColumnValueSelector<?> selector = theColumn.makeColumnValueSelector(offset);
        // compare with selector make sure reader can read correct values
        for (int row = 0; row < numRows; row++) {
            offset.setCurrentOffset(row);
            Assert.assertEquals(selector.getObject(), reader.read(row));
        }
        // make sure it doesn't have an index since it isn't a key column
        try {
            Assert.assertEquals(null, broadcastTable.columnIndex(columnIndex));
        } catch (IAE iae) {
            Assert.assertEquals(StringUtils.format("Column[%d] is not a key column", columnIndex), iae.getMessage());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) BaseColumn(org.apache.druid.segment.column.BaseColumn) IOException(java.io.IOException) IAE(org.apache.druid.java.util.common.IAE)

Example 7 with BaseColumn

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

the class BroadcastSegmentIndexedTable method columnReader.

@Override
public Reader columnReader(int column) {
    if (!rowSignature.contains(column)) {
        throw new IAE("Column[%d] is not a valid column for segment[%s]", column, segment.getId());
    }
    final SimpleAscendingOffset offset = new SimpleAscendingOffset(adapter.getNumRows());
    final BaseColumn baseColumn = queryableIndex.getColumnHolder(rowSignature.getColumnName(column)).getColumn();
    final BaseObjectColumnValueSelector<?> selector = baseColumn.makeColumnValueSelector(offset);
    return new Reader() {

        @Nullable
        @Override
        public Object read(int row) {
            offset.setCurrentOffset(row);
            return selector.getObject();
        }

        @Override
        public void close() throws IOException {
            baseColumn.close();
        }
    };
}
Also used : SimpleAscendingOffset(org.apache.druid.segment.SimpleAscendingOffset) BaseColumn(org.apache.druid.segment.column.BaseColumn) IAE(org.apache.druid.java.util.common.IAE)

Example 8 with BaseColumn

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

the class QueryableIndexCursorSequenceBuilder method build.

public Sequence<Cursor> build(final Granularity gran) {
    final Offset baseOffset;
    if (filterBitmap == null) {
        baseOffset = descending ? new SimpleDescendingOffset(index.getNumRows()) : new SimpleAscendingOffset(index.getNumRows());
    } else {
        baseOffset = BitmapOffset.of(filterBitmap, descending, index.getNumRows());
    }
    // Column caches shared amongst all cursors in this sequence.
    final Map<String, BaseColumn> columnCache = new HashMap<>();
    final NumericColumn timestamps = (NumericColumn) index.getColumnHolder(ColumnHolder.TIME_COLUMN_NAME).getColumn();
    final Closer closer = Closer.create();
    closer.register(timestamps);
    Iterable<Interval> iterable = gran.getIterable(interval);
    if (descending) {
        iterable = Lists.reverse(ImmutableList.copyOf(iterable));
    }
    return Sequences.withBaggage(Sequences.map(Sequences.simple(iterable), new Function<Interval, Cursor>() {

        @Override
        public Cursor apply(final Interval inputInterval) {
            final long timeStart = Math.max(interval.getStartMillis(), inputInterval.getStartMillis());
            final long timeEnd = Math.min(interval.getEndMillis(), gran.increment(inputInterval.getStartMillis()));
            if (descending) {
                for (; baseOffset.withinBounds(); baseOffset.increment()) {
                    if (timestamps.getLongSingleValueRow(baseOffset.getOffset()) < timeEnd) {
                        break;
                    }
                }
            } else {
                for (; baseOffset.withinBounds(); baseOffset.increment()) {
                    if (timestamps.getLongSingleValueRow(baseOffset.getOffset()) >= timeStart) {
                        break;
                    }
                }
            }
            final Offset offset = descending ? new DescendingTimestampCheckingOffset(baseOffset, timestamps, timeStart, minDataTimestamp >= timeStart) : new AscendingTimestampCheckingOffset(baseOffset, timestamps, timeEnd, maxDataTimestamp < timeEnd);
            final Offset baseCursorOffset = offset.clone();
            final ColumnSelectorFactory columnSelectorFactory = new QueryableIndexColumnSelectorFactory(index, virtualColumns, descending, closer, baseCursorOffset.getBaseReadableOffset(), columnCache);
            final DateTime myBucket = gran.toDateTime(inputInterval.getStartMillis());
            if (postFilter == null) {
                return new QueryableIndexCursor(baseCursorOffset, columnSelectorFactory, myBucket);
            } else {
                FilteredOffset filteredOffset = new FilteredOffset(baseCursorOffset, columnSelectorFactory, descending, postFilter, bitmapIndexSelector);
                return new QueryableIndexCursor(filteredOffset, columnSelectorFactory, myBucket);
            }
        }
    }), closer);
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) QueryableIndexVectorColumnSelectorFactory(org.apache.druid.segment.vector.QueryableIndexVectorColumnSelectorFactory) VectorColumnSelectorFactory(org.apache.druid.segment.vector.VectorColumnSelectorFactory) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) Offset(org.apache.druid.segment.data.Offset) ReadableOffset(org.apache.druid.segment.data.ReadableOffset) FilteredVectorOffset(org.apache.druid.segment.vector.FilteredVectorOffset) BitmapVectorOffset(org.apache.druid.segment.vector.BitmapVectorOffset) NoFilterVectorOffset(org.apache.druid.segment.vector.NoFilterVectorOffset) VectorOffset(org.apache.druid.segment.vector.VectorOffset) Function(com.google.common.base.Function) NumericColumn(org.apache.druid.segment.column.NumericColumn) BaseColumn(org.apache.druid.segment.column.BaseColumn) Interval(org.joda.time.Interval)

Aggregations

BaseColumn (org.apache.druid.segment.column.BaseColumn)8 Closer (org.apache.druid.java.util.common.io.Closer)4 IOException (java.io.IOException)3 SimpleAscendingOffset (org.apache.druid.segment.SimpleAscendingOffset)3 DictionaryEncodedColumn (org.apache.druid.segment.column.DictionaryEncodedColumn)3 HashMap (java.util.HashMap)2 Nullable (javax.annotation.Nullable)2 IAE (org.apache.druid.java.util.common.IAE)2 RuntimeShapeInspector (org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)2 BitmapIndex (org.apache.druid.segment.column.BitmapIndex)2 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)2 NumericColumn (org.apache.druid.segment.column.NumericColumn)2 CloseableIndexed (org.apache.druid.segment.data.CloseableIndexed)2 BitmapVectorOffset (org.apache.druid.segment.vector.BitmapVectorOffset)2 FilteredVectorOffset (org.apache.druid.segment.vector.FilteredVectorOffset)2 NoFilterVectorOffset (org.apache.druid.segment.vector.NoFilterVectorOffset)2 QueryableIndexVectorColumnSelectorFactory (org.apache.druid.segment.vector.QueryableIndexVectorColumnSelectorFactory)2 VectorColumnSelectorFactory (org.apache.druid.segment.vector.VectorColumnSelectorFactory)2 VectorOffset (org.apache.druid.segment.vector.VectorOffset)2 Function (com.google.common.base.Function)1