Search in sources :

Example 6 with ComplexMetricSerde

use of io.druid.segment.serde.ComplexMetricSerde in project druid by druid-io.

the class IndexMergerV9 method setupMetricsWriters.

private ArrayList<GenericColumnSerializer> setupMetricsWriters(final IOPeon ioPeon, 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());
    final CompressedObjectStrategy.CompressionStrategy metCompression = indexSpec.getMetricCompression();
    final CompressionFactory.LongEncodingStrategy longEncoding = indexSpec.getLongEncoding();
    for (String metric : mergedMetrics) {
        ValueType type = metricsValueTypes.get(metric);
        GenericColumnSerializer writer;
        switch(type) {
            case LONG:
                writer = LongColumnSerializer.create(ioPeon, metric, metCompression, longEncoding);
                break;
            case FLOAT:
                writer = FloatColumnSerializer.create(ioPeon, metric, metCompression);
                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(ioPeon, 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(io.druid.segment.serde.ComplexMetricSerde) ValueType(io.druid.segment.column.ValueType) CompressionFactory(io.druid.segment.data.CompressionFactory) ISE(io.druid.java.util.common.ISE) CompressedObjectStrategy(io.druid.segment.data.CompressedObjectStrategy)

Example 7 with ComplexMetricSerde

use of io.druid.segment.serde.ComplexMetricSerde in project druid by druid-io.

the class IncrementalIndex method makeColumnSelectorFactory.

/**
   * Column selector used at ingestion time for inputs to aggregators.
   *
   * @param agg                       the aggregator
   * @param in                        ingestion-time input row supplier
   * @param deserializeComplexMetrics whether complex objects should be deserialized by a {@link ComplexMetricExtractor}
   *
   * @return column selector factory
   */
public static ColumnSelectorFactory makeColumnSelectorFactory(final VirtualColumns virtualColumns, final AggregatorFactory agg, final Supplier<InputRow> in, final boolean deserializeComplexMetrics) {
    final RowBasedColumnSelectorFactory baseSelectorFactory = RowBasedColumnSelectorFactory.create(in, null);
    class IncrementalIndexInputRowColumnSelectorFactory implements ColumnSelectorFactory {

        @Override
        public LongColumnSelector makeLongColumnSelector(final String columnName) {
            return baseSelectorFactory.makeLongColumnSelector(columnName);
        }

        @Override
        public FloatColumnSelector makeFloatColumnSelector(final String columnName) {
            return baseSelectorFactory.makeFloatColumnSelector(columnName);
        }

        @Override
        public ObjectColumnSelector makeObjectColumnSelector(final String column) {
            final String typeName = agg.getTypeName();
            final ObjectColumnSelector rawColumnSelector = baseSelectorFactory.makeObjectColumnSelector(column);
            if ((Enums.getIfPresent(ValueType.class, typeName.toUpperCase()).isPresent() && !typeName.equalsIgnoreCase(ValueType.COMPLEX.name())) || !deserializeComplexMetrics) {
                return rawColumnSelector;
            } else {
                final ComplexMetricSerde serde = ComplexMetrics.getSerdeForType(typeName);
                if (serde == null) {
                    throw new ISE("Don't know how to handle type[%s]", typeName);
                }
                final ComplexMetricExtractor extractor = serde.getExtractor();
                return new ObjectColumnSelector() {

                    @Override
                    public Class classOfObject() {
                        return extractor.extractedClass();
                    }

                    @Override
                    public Object get() {
                        return extractor.extractValue(in.get(), column);
                    }
                };
            }
        }

        @Override
        public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec) {
            return baseSelectorFactory.makeDimensionSelector(dimensionSpec);
        }

        @Nullable
        @Override
        public ColumnCapabilities getColumnCapabilities(String columnName) {
            return baseSelectorFactory.getColumnCapabilities(columnName);
        }
    }
    return virtualColumns.wrap(new IncrementalIndexInputRowColumnSelectorFactory());
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) ComplexMetricSerde(io.druid.segment.serde.ComplexMetricSerde) RowBasedColumnSelectorFactory(io.druid.query.groupby.RowBasedColumnSelectorFactory) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) ComplexMetricExtractor(io.druid.segment.serde.ComplexMetricExtractor) ISE(io.druid.java.util.common.ISE) RowBasedColumnSelectorFactory(io.druid.query.groupby.RowBasedColumnSelectorFactory) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Aggregations

ComplexMetricSerde (io.druid.segment.serde.ComplexMetricSerde)7 ISE (io.druid.java.util.common.ISE)4 IOException (java.io.IOException)3 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)2 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)2 ValueType (io.druid.segment.column.ValueType)2 CompressedObjectStrategy (io.druid.segment.data.CompressedObjectStrategy)2 CompressionFactory (io.druid.segment.data.CompressionFactory)2 Function (com.google.common.base.Function)1 Supplier (com.google.common.base.Supplier)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 ByteSink (com.google.common.io.ByteSink)1 Closer (com.google.common.io.Closer)1 FileOutputSupplier (io.druid.common.guava.FileOutputSupplier)1 InputRow (io.druid.data.input.InputRow)1 ParseException (io.druid.java.util.common.parsers.ParseException)1 Aggregator (io.druid.query.aggregation.Aggregator)1 DimensionSpec (io.druid.query.dimension.DimensionSpec)1 RowBasedColumnSelectorFactory (io.druid.query.groupby.RowBasedColumnSelectorFactory)1 ColumnAnalysis (io.druid.query.metadata.metadata.ColumnAnalysis)1