Search in sources :

Example 56 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities in project druid by apache.

the class LookupSegmentTest method test_asStorageAdapter_getColumnCapabilitiesV.

@Test
public void test_asStorageAdapter_getColumnCapabilitiesV() {
    final ColumnCapabilities capabilities = LOOKUP_SEGMENT.asStorageAdapter().getColumnCapabilities("v");
    // Note: the "v" column does not actually have multiple values, but the RowBasedStorageAdapter doesn't allow
    // reporting complete single-valued capabilities. It would be good to change this in the future, so query engines
    // running on top of lookups can take advantage of singly-valued optimizations.
    Assert.assertEquals(ValueType.STRING, capabilities.getType());
    Assert.assertTrue(capabilities.hasMultipleValues().isUnknown());
    Assert.assertFalse(capabilities.isDictionaryEncoded().isTrue());
}
Also used : ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) Test(org.junit.Test)

Example 57 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities in project druid by apache.

the class DoubleLastAggregatorFactory method factorizeVector.

@Override
public VectorAggregator factorizeVector(VectorColumnSelectorFactory columnSelectorFactory) {
    ColumnCapabilities capabilities = columnSelectorFactory.getColumnCapabilities(fieldName);
    VectorValueSelector valueSelector = columnSelectorFactory.makeValueSelector(fieldName);
    // time is always long
    BaseLongVectorValueSelector timeSelector = (BaseLongVectorValueSelector) columnSelectorFactory.makeValueSelector(timeColumn);
    if (capabilities == null || capabilities.isNumeric()) {
        return new DoubleLastVectorAggregator(timeSelector, valueSelector);
    } else {
        return NumericNilVectorAggregator.doubleNilVectorAggregator();
    }
}
Also used : BaseLongVectorValueSelector(org.apache.druid.segment.vector.BaseLongVectorValueSelector) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) BaseLongVectorValueSelector(org.apache.druid.segment.vector.BaseLongVectorValueSelector) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 58 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities in project druid by apache.

the class FloatLastAggregatorFactory method factorizeVector.

@Override
public VectorAggregator factorizeVector(VectorColumnSelectorFactory columnSelectorFactory) {
    ColumnCapabilities capabilities = columnSelectorFactory.getColumnCapabilities(fieldName);
    VectorValueSelector valueSelector = columnSelectorFactory.makeValueSelector(fieldName);
    // time is always long
    BaseLongVectorValueSelector timeSelector = (BaseLongVectorValueSelector) columnSelectorFactory.makeValueSelector(timeColumn);
    if (capabilities == null || capabilities.isNumeric()) {
        return new FloatLastVectorAggregator(timeSelector, valueSelector);
    } else {
        return NumericNilVectorAggregator.floatNilVectorAggregator();
    }
}
Also used : BaseLongVectorValueSelector(org.apache.druid.segment.vector.BaseLongVectorValueSelector) VectorValueSelector(org.apache.druid.segment.vector.VectorValueSelector) BaseLongVectorValueSelector(org.apache.druid.segment.vector.BaseLongVectorValueSelector) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 59 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities in project druid by apache.

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)

Example 60 with ColumnCapabilities

use of org.apache.druid.segment.column.ColumnCapabilities in project druid by apache.

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)

Aggregations

ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)170 Test (org.junit.Test)106 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)60 ColumnCapabilitiesImpl (org.apache.druid.segment.column.ColumnCapabilitiesImpl)18 ArrayList (java.util.ArrayList)12 VectorValueSelector (org.apache.druid.segment.vector.VectorValueSelector)12 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)10 ColumnHolder (org.apache.druid.segment.column.ColumnHolder)10 ValueType (org.apache.druid.segment.column.ValueType)9 Nullable (javax.annotation.Nullable)8 DimensionSpec (org.apache.druid.query.dimension.DimensionSpec)8 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)8 ColumnType (org.apache.druid.segment.column.ColumnType)8 RowSignature (org.apache.druid.segment.column.RowSignature)8 BaseLongVectorValueSelector (org.apache.druid.segment.vector.BaseLongVectorValueSelector)8 File (java.io.File)6 List (java.util.List)6 TreeMap (java.util.TreeMap)6 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)6 Pair (org.apache.druid.java.util.common.Pair)6