Search in sources :

Example 11 with ColumnAnalysis

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");
}
Also used : SegmentMetadataQuery(org.apache.druid.query.metadata.metadata.SegmentMetadataQuery) ListColumnIncluderator(org.apache.druid.query.metadata.metadata.ListColumnIncluderator) Druids(org.apache.druid.query.Druids) ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) SegmentAnalysis(org.apache.druid.query.metadata.metadata.SegmentAnalysis) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 12 with ColumnAnalysis

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());
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) RowSignature(org.apache.druid.segment.column.RowSignature) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) TreeMap(java.util.TreeMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with ColumnAnalysis

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);
}
Also used : ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) SegmentAnalysis(org.apache.druid.query.metadata.metadata.SegmentAnalysis) RowSignature(org.apache.druid.segment.column.RowSignature) Test(org.junit.Test)

Example 14 with ColumnAnalysis

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 });
}
Also used : ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) SegmentAnalysis(org.apache.druid.query.metadata.metadata.SegmentAnalysis)

Example 15 with ColumnAnalysis

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);
}
Also used : BitmapIndex(org.apache.druid.segment.column.BitmapIndex) ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) BaseColumn(org.apache.druid.segment.column.BaseColumn) DictionaryEncodedColumn(org.apache.druid.segment.column.DictionaryEncodedColumn) IOException(java.io.IOException)

Aggregations

ColumnAnalysis (org.apache.druid.query.metadata.metadata.ColumnAnalysis)30 SegmentAnalysis (org.apache.druid.query.metadata.metadata.SegmentAnalysis)19 Test (org.junit.Test)18 SegmentMetadataQuery (org.apache.druid.query.metadata.metadata.SegmentMetadataQuery)12 QueryRunner (org.apache.druid.query.QueryRunner)9 ListColumnIncluderator (org.apache.druid.query.metadata.metadata.ListColumnIncluderator)9 ExecutorService (java.util.concurrent.ExecutorService)8 FinalizeResultsQueryRunner (org.apache.druid.query.FinalizeResultsQueryRunner)8 QueryToolChest (org.apache.druid.query.QueryToolChest)8 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)4 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)4 RowSignature (org.apache.druid.segment.column.RowSignature)4 HashMap (java.util.HashMap)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 List (java.util.List)2 DimensionSchema (org.apache.druid.data.input.impl.DimensionSchema)2 Granularity (org.apache.druid.java.util.common.granularity.Granularity)2