use of org.apache.druid.query.metadata.metadata.ColumnAnalysis in project druid by druid-io.
the class SegmentMetadataUnionQueryTest method testSegmentMetadataUnionQuery.
@Test
public void testSegmentMetadataUnionQuery() {
SegmentAnalysis expected = new SegmentAnalysis(QueryRunnerTestHelper.SEGMENT_ID.toString(), Collections.singletonList(Intervals.of("2011-01-12T00:00:00.000Z/2011-04-15T00:00:00.001Z")), ImmutableMap.of("placement", new ColumnAnalysis(ColumnType.STRING, ValueType.STRING.toString(), false, false, mmap ? 43524 : 43056, 1, "preferred", "preferred", null)), mmap ? 800544 : 803324, 4836, null, null, null, null);
SegmentMetadataQuery query = new Druids.SegmentMetadataQueryBuilder().dataSource(QueryRunnerTestHelper.UNION_DATA_SOURCE).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).toInclude(new ListColumnIncluderator(Collections.singletonList("placement"))).analysisTypes(SegmentMetadataQuery.AnalysisType.CARDINALITY, SegmentMetadataQuery.AnalysisType.SIZE, SegmentMetadataQuery.AnalysisType.INTERVAL, SegmentMetadataQuery.AnalysisType.MINMAX).build();
List result = runner.run(QueryPlus.wrap(query)).toList();
TestHelper.assertExpectedObjects(ImmutableList.of(expected), result, "failed SegmentMetadata union query");
}
use of org.apache.druid.query.metadata.metadata.ColumnAnalysis in project druid by druid-io.
the class DruidSchema method analysisToRowSignature.
@VisibleForTesting
static RowSignature analysisToRowSignature(final SegmentAnalysis analysis) {
final RowSignature.Builder rowSignatureBuilder = RowSignature.builder();
for (Map.Entry<String, ColumnAnalysis> entry : analysis.getColumns().entrySet()) {
if (entry.getValue().isError()) {
// Skip columns with analysis errors.
continue;
}
ColumnType valueType = entry.getValue().getTypeSignature();
// flavor of COMPLEX.
if (valueType == null) {
// likelyhood of upgrading from some version lower than 0.23 is low
try {
valueType = ColumnType.fromString(entry.getValue().getType());
} catch (IllegalArgumentException ignored) {
valueType = ColumnType.UNKNOWN_COMPLEX;
}
}
rowSignatureBuilder.add(entry.getKey(), valueType);
}
return ROW_SIGNATURE_INTERNER.intern(rowSignatureBuilder.build());
}
use of org.apache.druid.query.metadata.metadata.ColumnAnalysis in project druid by druid-io.
the class DruidSchemaTest method testSegmentMetadataColumnType.
@Test
public void testSegmentMetadataColumnType() {
RowSignature signature = DruidSchema.analysisToRowSignature(new SegmentAnalysis("id", ImmutableList.of(Intervals.utc(1L, 2L)), ImmutableMap.of("a", new ColumnAnalysis(ColumnType.STRING, ColumnType.STRING.asTypeString(), false, true, 1234, 26, "a", "z", null), "count", new ColumnAnalysis(ColumnType.LONG, ColumnType.LONG.asTypeString(), false, true, 1234, 26, "a", "z", null)), 1234, 100, null, null, null, null));
Assert.assertEquals(RowSignature.builder().add("a", ColumnType.STRING).add("count", ColumnType.LONG).build(), signature);
}
use of org.apache.druid.query.metadata.metadata.ColumnAnalysis in project druid by druid-io.
the class DoubleStorageTest method dataFeeder.
@Parameterized.Parameters
public static Collection<?> dataFeeder() {
SegmentAnalysis expectedSegmentAnalysisDouble = new SegmentAnalysis(SEGMENT_ID.toString(), ImmutableList.of(INTERVAL), ImmutableMap.of(TIME_COLUMN, new ColumnAnalysis(ColumnType.LONG, ValueType.LONG.name(), false, false, 100, null, null, null, null), DIM_NAME, new ColumnAnalysis(ColumnType.STRING, ValueType.STRING.name(), false, false, 120, 1, DIM_VALUE, DIM_VALUE, null), DIM_FLOAT_NAME, new ColumnAnalysis(ColumnType.DOUBLE, ValueType.DOUBLE.name(), false, false, 80, null, null, null, null)), 330, MAX_ROWS, null, null, null, null);
SegmentAnalysis expectedSegmentAnalysisFloat = new SegmentAnalysis(SEGMENT_ID.toString(), ImmutableList.of(INTERVAL), ImmutableMap.of(TIME_COLUMN, new ColumnAnalysis(ColumnType.LONG, ValueType.LONG.name(), false, false, 100, null, null, null, null), DIM_NAME, new ColumnAnalysis(ColumnType.STRING, ValueType.STRING.name(), false, false, 120, 1, DIM_VALUE, DIM_VALUE, null), DIM_FLOAT_NAME, new ColumnAnalysis(ColumnType.FLOAT, ValueType.FLOAT.name(), false, false, 80, null, null, null, null)), 330, MAX_ROWS, null, null, null, null);
return ImmutableList.of(new Object[] { "double", expectedSegmentAnalysisDouble }, new Object[] { "float", expectedSegmentAnalysisFloat });
}
use of org.apache.druid.query.metadata.metadata.ColumnAnalysis in project druid by druid-io.
the class SegmentAnalyzer method analyzeStringColumn.
private ColumnAnalysis analyzeStringColumn(final ColumnCapabilities capabilities, final ColumnHolder columnHolder) {
Comparable min = null;
Comparable max = null;
long size = 0;
final int cardinality;
if (capabilities.hasBitmapIndexes()) {
final BitmapIndex bitmapIndex = columnHolder.getBitmapIndex();
cardinality = bitmapIndex.getCardinality();
if (analyzingSize()) {
for (int i = 0; i < cardinality; ++i) {
String value = bitmapIndex.getValue(i);
if (value != null) {
size += StringUtils.estimatedBinaryLengthAsUTF8(value) * ((long) bitmapIndex.getBitmap(bitmapIndex.getIndex(value)).size());
}
}
}
if (analyzingMinMax() && cardinality > 0) {
min = NullHandling.nullToEmptyIfNeeded(bitmapIndex.getValue(0));
max = NullHandling.nullToEmptyIfNeeded(bitmapIndex.getValue(cardinality - 1));
}
} else if (capabilities.isDictionaryEncoded().isTrue()) {
// fallback if no bitmap index
try (BaseColumn column = columnHolder.getColumn()) {
DictionaryEncodedColumn<String> theColumn = (DictionaryEncodedColumn<String>) column;
cardinality = theColumn.getCardinality();
if (analyzingMinMax() && cardinality > 0) {
min = NullHandling.nullToEmptyIfNeeded(theColumn.lookupName(0));
max = NullHandling.nullToEmptyIfNeeded(theColumn.lookupName(cardinality - 1));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
cardinality = 0;
}
return new ColumnAnalysis(capabilities.toColumnType(), capabilities.getType().name(), capabilities.hasMultipleValues().isTrue(), // if we don't know for sure, then we should plan to check for nulls
capabilities.hasNulls().isMaybeTrue(), size, analyzingCardinality() ? cardinality : 0, min, max, null);
}
Aggregations