Search in sources :

Example 1 with DictionaryEncodedColumn

use of io.druid.segment.column.DictionaryEncodedColumn 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 DictionaryEncodedColumn

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

the class StringDimensionHandler method getEncodedKeyComponentFromColumn.

@Override
public int[] getEncodedKeyComponentFromColumn(Closeable column, int currRow) {
    DictionaryEncodedColumn dict = (DictionaryEncodedColumn) column;
    int[] theVals;
    if (dict.hasMultipleValues()) {
        final IndexedInts dimVals = dict.getMultiValueRow(currRow);
        theVals = new int[dimVals.size()];
        for (int i = 0; i < theVals.length; ++i) {
            theVals[i] = dimVals.get(i);
        }
    } else {
        theVals = new int[1];
        theVals[0] = dict.getSingleValueRow(currRow);
    }
    return theVals;
}
Also used : IndexedInts(io.druid.segment.data.IndexedInts) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn)

Example 3 with DictionaryEncodedColumn

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

the class IndexMergerTest method assertDimCompression.

private void assertDimCompression(QueryableIndex index, CompressedObjectStrategy.CompressionStrategy expectedStrategy) throws Exception {
    // Java voodoo
    if (expectedStrategy == null || expectedStrategy == CompressedObjectStrategy.CompressionStrategy.UNCOMPRESSED) {
        return;
    }
    DictionaryEncodedColumn encodedColumn = index.getColumn("dim2").getDictionaryEncoding();
    Object obj;
    if (encodedColumn.hasMultipleValues()) {
        Field field = SimpleDictionaryEncodedColumn.class.getDeclaredField("multiValueColumn");
        field.setAccessible(true);
        obj = field.get(encodedColumn);
    } else {
        Field field = SimpleDictionaryEncodedColumn.class.getDeclaredField("column");
        field.setAccessible(true);
        obj = field.get(encodedColumn);
    }
    // CompressedVSizeIntsIndexedSupplier$CompressedByteSizeIndexedInts
    // CompressedVSizeIndexedSupplier$CompressedVSizeIndexed
    Field compressedSupplierField = obj.getClass().getDeclaredField("this$0");
    compressedSupplierField.setAccessible(true);
    Object supplier = compressedSupplierField.get(obj);
    Field compressionField = supplier.getClass().getDeclaredField("compression");
    compressionField.setAccessible(true);
    Object strategy = compressionField.get(supplier);
    Assert.assertEquals(expectedStrategy, strategy);
}
Also used : Field(java.lang.reflect.Field) SimpleDictionaryEncodedColumn(io.druid.segment.column.SimpleDictionaryEncodedColumn) DictionaryEncodedColumn(io.druid.segment.column.DictionaryEncodedColumn)

Example 4 with DictionaryEncodedColumn

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

the class ColumnSelectorBitmapIndexSelector method getDimensionValues.

@Override
public Indexed<String> getDimensionValues(String dimension) {
    if (isFilterableVirtualColumn(dimension)) {
        // Virtual columns don't have dictionaries or indexes.
        return null;
    }
    final Column columnDesc = index.getColumn(dimension);
    if (columnDesc == null || !columnDesc.getCapabilities().isDictionaryEncoded()) {
        return null;
    }
    final DictionaryEncodedColumn<String> column = columnDesc.getDictionaryEncoding();
    return new Indexed<String>() {

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

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

        @Override
        public String get(int index) {
            return column.lookupName(index);
        }

        @Override
        public int indexOf(String value) {
            return column.lookupId(value);
        }

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

Aggregations

DictionaryEncodedColumn (io.druid.segment.column.DictionaryEncodedColumn)4 Column (io.druid.segment.column.Column)2 GenericColumn (io.druid.segment.column.GenericColumn)2 Indexed (io.druid.segment.data.Indexed)2 ComplexColumn (io.druid.segment.column.ComplexColumn)1 IndexedFloatsGenericColumn (io.druid.segment.column.IndexedFloatsGenericColumn)1 IndexedLongsGenericColumn (io.druid.segment.column.IndexedLongsGenericColumn)1 SimpleDictionaryEncodedColumn (io.druid.segment.column.SimpleDictionaryEncodedColumn)1 IndexedInts (io.druid.segment.data.IndexedInts)1 ListIndexed (io.druid.segment.data.ListIndexed)1 Field (java.lang.reflect.Field)1