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);
}
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);
}
};
}
};
}
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());
}
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());
}
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);
}
Aggregations