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;
}
}
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);
}
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);
}
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());
}
}
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);
}
Aggregations