use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateLongPercentileArrayAggregations method output.
@OutputFunction("array(bigint)")
public static void output(@AggregationState TDigestAndPercentileArrayState state, BlockBuilder out) {
TDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
List<Double> valuesAtPercentiles = valuesAtPercentiles(digest, percentiles);
for (double value : valuesAtPercentiles) {
BIGINT.writeLong(blockBuilder, Math.round(value));
}
out.closeEntry();
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateRealPercentileArrayAggregations method output.
@OutputFunction("array(real)")
public static void output(@AggregationState TDigestAndPercentileArrayState state, BlockBuilder out) {
TDigest digest = state.getDigest();
List<Double> percentiles = state.getPercentiles();
if (percentiles == null || digest == null) {
out.appendNull();
return;
}
BlockBuilder blockBuilder = out.beginBlockEntry();
List<Double> valuesAtPercentiles = valuesAtPercentiles(digest, percentiles);
for (double value : valuesAtPercentiles) {
REAL.writeLong(blockBuilder, floatToRawIntBits((float) value));
}
out.closeEntry();
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class SpatialPartitioningInternalAggregateFunction method output.
@OutputFunction(StandardTypes.VARCHAR)
public static void output(SpatialPartitioningState state, BlockBuilder out) {
if (state.getCount() == 0) {
out.appendNull();
return;
}
List<Rectangle> samples = state.getSamples();
int partitionCount = state.getPartitionCount();
int maxItemsPerNode = (samples.size() + partitionCount - 1) / partitionCount;
Rectangle envelope = state.getExtent();
// Add a small buffer on the right and upper sides
Rectangle paddedExtent = new Rectangle(envelope.getXMin(), envelope.getYMin(), Math.nextUp(envelope.getXMax()), Math.nextUp(envelope.getYMax()));
VARCHAR.writeString(out, KdbTreeUtils.toJson(buildKdbTree(maxItemsPerNode, paddedExtent, samples)));
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class RealHistogramAggregation method output.
@OutputFunction("map(real,real)")
public static void output(@AggregationState DoubleHistogramAggregation.State state, BlockBuilder out) {
if (state.get() == null) {
out.appendNull();
} else {
Map<Double, Double> value = state.get().getBuckets();
BlockBuilder entryBuilder = out.beginBlockEntry();
for (Map.Entry<Double, Double> entry : value.entrySet()) {
REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getKey().floatValue()));
REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getValue().floatValue()));
}
out.closeEntry();
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class VarcharApproximateMostFrequent method output.
@OutputFunction("map(varchar,bigint)")
public static void output(@AggregationState State state, BlockBuilder out) {
if (state.get() == null) {
out.appendNull();
} else {
BlockBuilder entryBuilder = out.beginBlockEntry();
state.get().forEachBucket((key, value) -> {
VarcharType.VARCHAR.writeSlice(entryBuilder, key);
BigintType.BIGINT.writeLong(entryBuilder, value);
});
out.closeEntry();
}
}
Aggregations