Search in sources :

Example 1 with DimensionIndexer

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

the class IncrementalIndexAdapter method getDimValueLookup.

@Nullable
@Override
public <T extends Comparable<? super T>> CloseableIndexed<T> getDimValueLookup(String dimension) {
    final DimensionAccessor accessor = accessors.get(dimension);
    if (accessor == null) {
        return null;
    }
    final DimensionIndexer indexer = accessor.dimensionDesc.getIndexer();
    return indexer.getSortedIndexedValues();
}
Also used : DimensionIndexer(org.apache.druid.segment.DimensionIndexer) Nullable(javax.annotation.Nullable)

Example 2 with DimensionIndexer

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

the class IncrementalIndexColumnSelectorFactory method makeDimensionSelectorUndecorated.

private DimensionSelector makeDimensionSelectorUndecorated(DimensionSpec dimensionSpec) {
    final String dimension = dimensionSpec.getDimension();
    final ExtractionFn extractionFn = dimensionSpec.getExtractionFn();
    if (dimension.equals(ColumnHolder.TIME_COLUMN_NAME)) {
        return new SingleScanTimeDimensionSelector(makeColumnValueSelector(dimension), extractionFn, descending);
    }
    final IncrementalIndex.DimensionDesc dimensionDesc = index.getDimension(dimensionSpec.getDimension());
    if (dimensionDesc == null) {
        // not a dimension, column may be a metric
        ColumnCapabilities capabilities = getColumnCapabilities(dimension);
        if (capabilities == null) {
            return DimensionSelector.constant(null, extractionFn);
        }
        if (capabilities.isNumeric()) {
            return ValueTypes.makeNumericWrappingDimensionSelector(capabilities.getType(), makeColumnValueSelector(dimension), extractionFn);
        }
        // if we can't wrap the base column, just return a column of all nulls
        return DimensionSelector.constant(null, extractionFn);
    } else {
        final DimensionIndexer indexer = dimensionDesc.getIndexer();
        return indexer.makeDimensionSelector(dimensionSpec, rowHolder, dimensionDesc);
    }
}
Also used : ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) DimensionIndexer(org.apache.druid.segment.DimensionIndexer) SingleScanTimeDimensionSelector(org.apache.druid.segment.SingleScanTimeDimensionSelector) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 3 with DimensionIndexer

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

the class IncrementalIndexRow method hashCode.

@Override
public int hashCode() {
    int hash = (int) timestamp;
    for (int i = 0; i < dims.length; i++) {
        final DimensionIndexer indexer = dimensionDescsList.get(i).getIndexer();
        hash = 31 * hash + indexer.getUnsortedEncodedKeyComponentHashCode(dims[i]);
    }
    return hash;
}
Also used : DimensionIndexer(org.apache.druid.segment.DimensionIndexer)

Example 4 with DimensionIndexer

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

the class IncrementalIndexStorageAdapter method getMaxValue.

@Nullable
@Override
public Comparable getMaxValue(String column) {
    IncrementalIndex.DimensionDesc desc = index.getDimension(column);
    if (desc == null) {
        return null;
    }
    DimensionIndexer indexer = desc.getIndexer();
    return indexer.getMaxValue();
}
Also used : DimensionIndexer(org.apache.druid.segment.DimensionIndexer) Nullable(javax.annotation.Nullable)

Example 5 with DimensionIndexer

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

the class IncrementalIndexAdapter method processRows.

/**
 * Sometimes it's hard to tell whether one dimension contains a null value or not.
 * If one dimension had show a null or empty value explicitly, then yes, it contains
 * null value. But if one dimension's values are all non-null, it still early to say
 * this dimension does not contain null value. Consider a two row case, first row had
 * "dimA=1" and "dimB=2", the second row only had "dimA=3". To dimB, its value are "2" and
 * never showed a null or empty value. But when we combines these two rows, dimB is null
 * in row 2. So we should iterate all rows to determine whether one dimension contains
 * a null value.
 */
private void processRows(IncrementalIndex index, BitmapFactory bitmapFactory, List<IncrementalIndex.DimensionDesc> dimensions) {
    int rowNum = 0;
    for (IncrementalIndexRow row : index.getFacts().persistIterable()) {
        final Object[] dims = row.getDims();
        for (IncrementalIndex.DimensionDesc dimension : dimensions) {
            final int dimIndex = dimension.getIndex();
            DimensionAccessor accessor = accessors.get(dimension.getName());
            // Add 'null' to the dimension's dictionary.
            if (dimIndex >= dims.length || dims[dimIndex] == null) {
                accessor.indexer.processRowValsToUnsortedEncodedKeyComponent(null, true);
                continue;
            }
            final ColumnCapabilities capabilities = dimension.getCapabilities();
            if (capabilities.hasBitmapIndexes()) {
                final MutableBitmap[] bitmapIndexes = accessor.invertedIndexes;
                final DimensionIndexer indexer = accessor.indexer;
                indexer.fillBitmapsFromUnsortedEncodedKeyComponent(dims[dimIndex], rowNum, bitmapIndexes, bitmapFactory);
            }
        }
        ++rowNum;
    }
}
Also used : DimensionIndexer(org.apache.druid.segment.DimensionIndexer) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

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