Search in sources :

Example 6 with ValueType

use of org.apache.druid.segment.column.ValueType in project druid by druid-io.

the class SegmentAnalyzer method analyzeComplexColumn.

private ColumnAnalysis analyzeComplexColumn(@Nullable final ColumnCapabilities capabilities, @Nullable final ColumnHolder columnHolder) {
    final TypeSignature<ValueType> typeSignature = capabilities == null ? ColumnType.UNKNOWN_COMPLEX : capabilities;
    final String typeName = typeSignature.getComplexTypeName();
    try (final ComplexColumn complexColumn = columnHolder != null ? (ComplexColumn) columnHolder.getColumn() : null) {
        final boolean hasMultipleValues = capabilities != null && capabilities.hasMultipleValues().isTrue();
        final boolean hasNulls = capabilities != null && capabilities.hasNulls().isMaybeTrue();
        long size = 0;
        if (analyzingSize() && complexColumn != null) {
            final ComplexMetricSerde serde = typeName == null ? null : ComplexMetrics.getSerdeForType(typeName);
            if (serde == null) {
                return ColumnAnalysis.error(StringUtils.format("unknown_complex_%s", typeName));
            }
            final Function<Object, Long> inputSizeFn = serde.inputSizeFn();
            if (inputSizeFn == null) {
                return new ColumnAnalysis(ColumnTypeFactory.ofType(typeSignature), typeName, hasMultipleValues, hasNulls, 0, null, null, null, null);
            }
            final int length = complexColumn.getLength();
            for (int i = 0; i < length; ++i) {
                size += inputSizeFn.apply(complexColumn.getRowValue(i));
            }
        }
        return new ColumnAnalysis(ColumnTypeFactory.ofType(typeSignature), typeName, hasMultipleValues, hasNulls, size, null, null, null, null);
    }
}
Also used : ComplexMetricSerde(org.apache.druid.segment.serde.ComplexMetricSerde) ValueType(org.apache.druid.segment.column.ValueType) ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) ComplexColumn(org.apache.druid.segment.column.ComplexColumn)

Example 7 with ValueType

use of org.apache.druid.segment.column.ValueType in project druid by druid-io.

the class IndexMergerV9 method setupMetricsWriters.

private ArrayList<GenericColumnSerializer> setupMetricsWriters(final SegmentWriteOutMedium segmentWriteOutMedium, final List<String> mergedMetrics, final Map<String, ValueType> metricsValueTypes, final Map<String, String> metricTypeNames, final IndexSpec indexSpec) throws IOException {
    ArrayList<GenericColumnSerializer> metWriters = Lists.newArrayListWithCapacity(mergedMetrics.size());
    for (String metric : mergedMetrics) {
        ValueType type = metricsValueTypes.get(metric);
        GenericColumnSerializer writer;
        switch(type) {
            case LONG:
                writer = createLongColumnSerializer(segmentWriteOutMedium, metric, indexSpec);
                break;
            case FLOAT:
                writer = createFloatColumnSerializer(segmentWriteOutMedium, metric, indexSpec);
                break;
            case DOUBLE:
                writer = createDoubleColumnSerializer(segmentWriteOutMedium, metric, indexSpec);
                break;
            case COMPLEX:
                final String typeName = metricTypeNames.get(metric);
                ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(typeName);
                if (serde == null) {
                    throw new ISE("Unknown type[%s]", typeName);
                }
                writer = serde.getSerializer(segmentWriteOutMedium, metric);
                break;
            default:
                throw new ISE("Unknown type[%s]", type);
        }
        writer.open();
        // we will close these writers in another method after we added all the metrics
        metWriters.add(writer);
    }
    return metWriters;
}
Also used : ComplexMetricSerde(org.apache.druid.segment.serde.ComplexMetricSerde) ValueType(org.apache.druid.segment.column.ValueType) ISE(org.apache.druid.java.util.common.ISE)

Example 8 with ValueType

use of org.apache.druid.segment.column.ValueType in project druid by druid-io.

the class IndexMergerV9 method makeMetricsColumns.

private void makeMetricsColumns(final FileSmoosher v9Smoosher, final ProgressIndicator progress, final List<String> mergedMetrics, final Map<String, ValueType> metricsValueTypes, final Map<String, String> metricTypeNames, final List<GenericColumnSerializer> metWriters, final IndexSpec indexSpec) throws IOException {
    final String section = "make metric columns";
    progress.startSection(section);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < mergedMetrics.size(); ++i) {
        String metric = mergedMetrics.get(i);
        long metricStartTime = System.currentTimeMillis();
        GenericColumnSerializer writer = metWriters.get(i);
        final ColumnDescriptor.Builder builder = ColumnDescriptor.builder();
        ValueType type = metricsValueTypes.get(metric);
        switch(type) {
            case LONG:
                builder.setValueType(ValueType.LONG);
                builder.addSerde(createLongColumnPartSerde(writer, indexSpec));
                break;
            case FLOAT:
                builder.setValueType(ValueType.FLOAT);
                builder.addSerde(createFloatColumnPartSerde(writer, indexSpec));
                break;
            case DOUBLE:
                builder.setValueType(ValueType.DOUBLE);
                builder.addSerde(createDoubleColumnPartSerde(writer, indexSpec));
                break;
            case COMPLEX:
                final String typeName = metricTypeNames.get(metric);
                builder.setValueType(ValueType.COMPLEX);
                builder.addSerde(ComplexColumnPartSerde.serializerBuilder().withTypeName(typeName).withDelegate(writer).build());
                break;
            default:
                throw new ISE("Unknown type[%s]", type);
        }
        makeColumn(v9Smoosher, metric, builder.build());
        log.debug("Completed metric column[%s] in %,d millis.", metric, System.currentTimeMillis() - metricStartTime);
    }
    log.debug("Completed metric columns in %,d millis.", System.currentTimeMillis() - startTime);
    progress.stopSection(section);
}
Also used : ValueType(org.apache.druid.segment.column.ValueType) ColumnDescriptor(org.apache.druid.segment.column.ColumnDescriptor) ISE(org.apache.druid.java.util.common.ISE)

Aggregations

ValueType (org.apache.druid.segment.column.ValueType)8 ISE (org.apache.druid.java.util.common.ISE)3 ArrayList (java.util.ArrayList)2 AbstractIntegerDistribution (org.apache.commons.math3.distribution.AbstractIntegerDistribution)2 AbstractRealDistribution (org.apache.commons.math3.distribution.AbstractRealDistribution)2 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 ColumnCapabilities (org.apache.druid.segment.column.ColumnCapabilities)2 ColumnDescriptor (org.apache.druid.segment.column.ColumnDescriptor)2 ComplexMetricSerde (org.apache.druid.segment.serde.ComplexMetricSerde)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IntBuffer (java.nio.IntBuffer)1 TreeMap (java.util.TreeMap)1 Nullable (javax.annotation.Nullable)1 RexNode (org.apache.calcite.rex.RexNode)1 EnumeratedDistribution (org.apache.commons.math3.distribution.EnumeratedDistribution)1 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)1 UniformIntegerDistribution (org.apache.commons.math3.distribution.UniformIntegerDistribution)1 UniformRealDistribution (org.apache.commons.math3.distribution.UniformRealDistribution)1 ZipfDistribution (org.apache.commons.math3.distribution.ZipfDistribution)1