Search in sources :

Example 71 with ColumnCapabilities

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

the class GroupByQueryEngineV2 method getCardinalityForArrayAggregation.

/**
 * Returns the cardinality of array needed to do array-based aggregation, or -1 if array-based aggregation
 * is impossible.
 */
public static int getCardinalityForArrayAggregation(GroupByQueryConfig querySpecificConfig, GroupByQuery query, StorageAdapter storageAdapter, ByteBuffer buffer) {
    if (querySpecificConfig.isForceHashAggregation()) {
        return -1;
    }
    final List<DimensionSpec> dimensions = query.getDimensions();
    final ColumnCapabilities columnCapabilities;
    final int cardinality;
    // Find cardinality
    if (dimensions.isEmpty()) {
        columnCapabilities = null;
        cardinality = 1;
    } else if (dimensions.size() == 1) {
        // real columns).
        if (query.getVirtualColumns().exists(Iterables.getOnlyElement(dimensions).getDimension())) {
            return -1;
        }
        // to allocate appropriate values
        if (dimensions.get(0).getOutputType().isArray()) {
            return -1;
        }
        final String columnName = Iterables.getOnlyElement(dimensions).getDimension();
        columnCapabilities = storageAdapter.getColumnCapabilities(columnName);
        cardinality = storageAdapter.getDimensionCardinality(columnName);
    } else {
        // Cannot use array-based aggregation with more than one dimension.
        return -1;
    }
    // Choose array-based aggregation if the grouping key is a single string dimension of a known cardinality
    if (Types.is(columnCapabilities, ValueType.STRING) && cardinality > 0) {
        final AggregatorFactory[] aggregatorFactories = query.getAggregatorSpecs().toArray(new AggregatorFactory[0]);
        final long requiredBufferCapacity = BufferArrayGrouper.requiredBufferCapacity(cardinality, aggregatorFactories);
        // Check that all keys and aggregated values can be contained in the buffer
        if (requiredBufferCapacity < 0 || requiredBufferCapacity > buffer.capacity()) {
            return -1;
        } else {
            return cardinality;
        }
    } else {
        return -1;
    }
}
Also used : DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 72 with ColumnCapabilities

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

the class DimensionHandlerUtilsTest method testGetHandlerFromDoubleCapabilities.

@Test
public void testGetHandlerFromDoubleCapabilities() {
    ColumnCapabilities capabilities = ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE);
    DimensionHandler handler = DimensionHandlerUtils.getHandlerFromCapabilities(DIM_NAME, capabilities, null);
    Assert.assertTrue(handler instanceof DoubleDimensionHandler);
    Assert.assertTrue(handler.getDimensionSchema(capabilities) instanceof DoubleDimensionSchema);
}
Also used : DoubleDimensionSchema(org.apache.druid.data.input.impl.DoubleDimensionSchema) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 73 with ColumnCapabilities

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

the class DimensionHandlerUtilsTest method testGetHandlerFromFloatCapabilities.

@Test
public void testGetHandlerFromFloatCapabilities() {
    ColumnCapabilities capabilities = ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.FLOAT);
    DimensionHandler handler = DimensionHandlerUtils.getHandlerFromCapabilities(DIM_NAME, capabilities, null);
    Assert.assertTrue(handler instanceof FloatDimensionHandler);
    Assert.assertTrue(handler.getDimensionSchema(capabilities) instanceof FloatDimensionSchema);
}
Also used : FloatDimensionSchema(org.apache.druid.data.input.impl.FloatDimensionSchema) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 74 with ColumnCapabilities

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

the class IndexBuilder method buildRowBasedSegmentWithTypeSignature.

public RowBasedSegment<InputRow> buildRowBasedSegmentWithTypeSignature() {
    // Determine row signature by building an mmapped index first.
    try (final QueryableIndex index = buildMMappedIndex()) {
        final RowSignature.Builder rowSignatureBuilder = RowSignature.builder();
        for (final String columnName : index.getColumnNames()) {
            final ColumnCapabilities capabilities = index.getColumnHolder(columnName).getCapabilities();
            rowSignatureBuilder.add(columnName, capabilities.toColumnType());
        }
        return new RowBasedSegment<>(SegmentId.dummy("IndexBuilder"), Sequences.simple(rows), RowAdapters.standardRow(), rowSignatureBuilder.build());
    }
}
Also used : RowSignature(org.apache.druid.segment.column.RowSignature) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities)

Example 75 with ColumnCapabilities

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

the class UseIndexesStrategy method partitionDimensionList.

/**
 * Split the given dimensions list into bitmap-supporting dimensions and non-bitmap supporting ones.
 * Note that the returned lists are free to modify.
 */
private static Pair<List<DimensionSpec>, List<DimensionSpec>> partitionDimensionList(StorageAdapter adapter, List<DimensionSpec> dimensions) {
    final List<DimensionSpec> bitmapDims = new ArrayList<>();
    final List<DimensionSpec> nonBitmapDims = new ArrayList<>();
    final List<DimensionSpec> dimsToSearch = getDimsToSearch(adapter.getAvailableDimensions(), dimensions);
    for (DimensionSpec spec : dimsToSearch) {
        ColumnCapabilities capabilities = adapter.getColumnCapabilities(spec.getDimension());
        if (capabilities == null) {
            continue;
        }
        if (capabilities.hasBitmapIndexes()) {
            bitmapDims.add(spec);
        } else {
            nonBitmapDims.add(spec);
        }
    }
    return new Pair<>(bitmapDims, nonBitmapDims);
}
Also used : DimensionSpec(org.apache.druid.query.dimension.DimensionSpec) ArrayList(java.util.ArrayList) ColumnCapabilities(org.apache.druid.segment.column.ColumnCapabilities) Pair(org.apache.druid.java.util.common.Pair)

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