Search in sources :

Example 16 with ObjectColumnSelector

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

the class ApproximateHistogramFoldingAggregatorFactory method factorize.

@Override
public Aggregator factorize(ColumnSelectorFactory metricFactory) {
    ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(fieldName);
    if (selector == null) {
        // gracefully handle undefined metrics
        selector = new ObjectColumnSelector<ApproximateHistogram>() {

            @Override
            public Class<ApproximateHistogram> classOfObject() {
                return ApproximateHistogram.class;
            }

            @Override
            public ApproximateHistogram get() {
                return new ApproximateHistogram(0);
            }
        };
    }
    final Class cls = selector.classOfObject();
    if (cls.equals(Object.class) || ApproximateHistogram.class.isAssignableFrom(cls)) {
        return new ApproximateHistogramFoldingAggregator(selector, resolution, lowerLimit, upperLimit);
    }
    throw new IAE("Incompatible type for metric[%s], expected a ApproximateHistogram, got a %s", fieldName, cls);
}
Also used : IAE(io.druid.java.util.common.IAE) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Example 17 with ObjectColumnSelector

use of io.druid.segment.ObjectColumnSelector 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 18 with ObjectColumnSelector

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

the class VirtualColumnsTest method testMakeSelectorsWithDotSupportBaseNameOnly.

@Test
public void testMakeSelectorsWithDotSupportBaseNameOnly() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("foo", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("foo", "x"), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("foo", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("foo", null);
    Assert.assertEquals(-1L, objectSelector.get());
    Assert.assertEquals("-1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals(-1.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(-1L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) Test(org.junit.Test)

Example 19 with ObjectColumnSelector

use of io.druid.segment.ObjectColumnSelector 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 20 with ObjectColumnSelector

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

the class ApproximateHistogramFoldingAggregatorFactory method factorizeBuffered.

@Override
public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory) {
    ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(fieldName);
    if (selector == null) {
        // gracefully handle undefined metrics
        selector = new ObjectColumnSelector<ApproximateHistogram>() {

            @Override
            public Class<ApproximateHistogram> classOfObject() {
                return ApproximateHistogram.class;
            }

            @Override
            public ApproximateHistogram get() {
                return new ApproximateHistogram(0);
            }
        };
    }
    final Class cls = selector.classOfObject();
    if (cls.equals(Object.class) || ApproximateHistogram.class.isAssignableFrom(cls)) {
        return new ApproximateHistogramFoldingBufferAggregator(selector, resolution, lowerLimit, upperLimit);
    }
    throw new IAE("Incompatible type for metric[%s], expected a ApproximateHistogram, got a %s", fieldName, cls);
}
Also used : IAE(io.druid.java.util.common.IAE) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector)

Aggregations

ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)20 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)6 LongColumnSelector (io.druid.segment.LongColumnSelector)6 RuntimeShapeInspector (io.druid.query.monomorphicprocessing.RuntimeShapeInspector)5 ColumnSelectorFactory (io.druid.segment.ColumnSelectorFactory)5 DimensionSelector (io.druid.segment.DimensionSelector)5 SerializablePair (io.druid.collections.SerializablePair)4 IAE (io.druid.java.util.common.IAE)4 DimensionSpec (io.druid.query.dimension.DimensionSpec)4 Cursor (io.druid.segment.Cursor)4 FloatColumnSelector (io.druid.segment.FloatColumnSelector)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 ISE (io.druid.java.util.common.ISE)3 TestFloatColumnSelector (io.druid.segment.TestFloatColumnSelector)3 TestLongColumnSelector (io.druid.segment.TestLongColumnSelector)3 VirtualColumns (io.druid.segment.VirtualColumns)3 List (java.util.List)3 Map (java.util.Map)3 DateTime (org.joda.time.DateTime)3