Search in sources :

Example 6 with ColumnSelectorFactory

use of io.druid.segment.ColumnSelectorFactory in project druid by druid-io.

the class DoubleFirstAggregatorFactory method getCombiningFactory.

@Override
public AggregatorFactory getCombiningFactory() {
    return new DoubleFirstAggregatorFactory(name, name) {

        @Override
        public Aggregator factorize(ColumnSelectorFactory metricFactory) {
            final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
            return new DoubleFirstAggregator(name, null, null) {

                @Override
                public void aggregate() {
                    SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) selector.get();
                    if (pair.lhs < firstTime) {
                        firstTime = pair.lhs;
                        firstValue = pair.rhs;
                    }
                }
            };
        }

        @Override
        public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
            final ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(name);
            return new DoubleFirstBufferAggregator(null, null) {

                @Override
                public void aggregate(ByteBuffer buf, int position) {
                    SerializablePair<Long, Double> pair = (SerializablePair<Long, Double>) selector.get();
                    long firstTime = buf.getLong(position);
                    if (pair.lhs < firstTime) {
                        buf.putLong(position, pair.lhs);
                        buf.putDouble(position + Longs.BYTES, pair.rhs);
                    }
                }

                @Override
                public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                    inspector.visit("selector", selector);
                }
            };
        }
    };
}
Also used : SerializablePair(io.druid.collections.SerializablePair) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) RuntimeShapeInspector(io.druid.query.monomorphicprocessing.RuntimeShapeInspector) ByteBuffer(java.nio.ByteBuffer) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Example 7 with ColumnSelectorFactory

use of io.druid.segment.ColumnSelectorFactory in project druid by druid-io.

the class BaseFilterTest method selectColumnValuesMatchingFilterUsingPostFiltering.

private List<String> selectColumnValuesMatchingFilterUsingPostFiltering(final DimFilter filter, final String selectColumn) {
    final Filter theFilter = makeFilter(filter);
    final Filter postFilteringFilter = new Filter() {

        @Override
        public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ValueMatcher makeMatcher(ColumnSelectorFactory factory) {
            return theFilter.makeMatcher(factory);
        }

        @Override
        public boolean supportsBitmapIndex(BitmapIndexSelector selector) {
            return false;
        }

        @Override
        public boolean supportsSelectivityEstimation(ColumnSelector columnSelector, BitmapIndexSelector indexSelector) {
            return false;
        }

        @Override
        public double estimateSelectivity(BitmapIndexSelector indexSelector) {
            return 1.0;
        }
    };
    final Sequence<Cursor> cursors = makeCursorSequence(postFilteringFilter);
    Sequence<List<String>> seq = Sequences.map(cursors, new Function<Cursor, List<String>>() {

        @Override
        public List<String> apply(Cursor input) {
            final DimensionSelector selector = input.makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn));
            final List<String> values = Lists.newArrayList();
            while (!input.isDone()) {
                IndexedInts row = selector.getRow();
                Preconditions.checkState(row.size() == 1);
                values.add(selector.lookupName(row.get(0)));
                input.advance();
            }
            return values;
        }
    });
    return Sequences.toList(seq, new ArrayList<List<String>>()).get(0);
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) RowBasedColumnSelectorFactory(io.druid.query.groupby.RowBasedColumnSelectorFactory) ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) ArrayList(java.util.ArrayList) Cursor(io.druid.segment.Cursor) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DimFilter(io.druid.query.filter.DimFilter) Filter(io.druid.query.filter.Filter) ColumnSelector(io.druid.segment.ColumnSelector) IndexedInts(io.druid.segment.data.IndexedInts) BitmapIndexSelector(io.druid.query.filter.BitmapIndexSelector) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Example 8 with ColumnSelectorFactory

use of io.druid.segment.ColumnSelectorFactory 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)

Example 9 with ColumnSelectorFactory

use of io.druid.segment.ColumnSelectorFactory in project druid by druid-io.

the class OffheapIncrementalIndex method initAggs.

@Override
protected BufferAggregator[] initAggs(AggregatorFactory[] metrics, Supplier<InputRow> rowSupplier, boolean deserializeComplexMetrics) {
    selectors = Maps.newHashMap();
    aggOffsetInBuffer = new int[metrics.length];
    for (int i = 0; i < metrics.length; i++) {
        AggregatorFactory agg = metrics[i];
        ColumnSelectorFactory columnSelectorFactory = makeColumnSelectorFactory(agg, rowSupplier, deserializeComplexMetrics);
        selectors.put(agg.getName(), new OnheapIncrementalIndex.ObjectCachingColumnSelectorFactory(columnSelectorFactory));
        if (i == 0) {
            aggOffsetInBuffer[i] = 0;
        } else {
            aggOffsetInBuffer[i] = aggOffsetInBuffer[i - 1] + metrics[i - 1].getMaxIntermediateSize();
        }
    }
    aggsTotalSize = aggOffsetInBuffer[metrics.length - 1] + metrics[metrics.length - 1].getMaxIntermediateSize();
    return new BufferAggregator[metrics.length];
}
Also used : ColumnSelectorFactory(io.druid.segment.ColumnSelectorFactory) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) BufferAggregator(io.druid.query.aggregation.BufferAggregator)

Aggregations

ColumnSelectorFactory (io.druid.segment.ColumnSelectorFactory)9 RuntimeShapeInspector (io.druid.query.monomorphicprocessing.RuntimeShapeInspector)5 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)5 SerializablePair (io.druid.collections.SerializablePair)4 ByteBuffer (java.nio.ByteBuffer)4 RowBasedColumnSelectorFactory (io.druid.query.groupby.RowBasedColumnSelectorFactory)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)2 DimensionSelector (io.druid.segment.DimensionSelector)2 IndexedInts (io.druid.segment.data.IndexedInts)2 ImmutableList (com.google.common.collect.ImmutableList)1 MapBasedRow (io.druid.data.input.MapBasedRow)1 Row (io.druid.data.input.Row)1 ISE (io.druid.java.util.common.ISE)1 Pair (io.druid.java.util.common.Pair)1 Accumulator (io.druid.java.util.common.guava.Accumulator)1 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)1 BufferAggregator (io.druid.query.aggregation.BufferAggregator)1 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)1 ExtractionFn (io.druid.query.extraction.ExtractionFn)1 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)1