use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateDoublePercentileAggregations method output.
@OutputFunction(StandardTypes.DOUBLE)
public static void output(@AggregationState TDigestAndPercentileState state, BlockBuilder out) {
TDigest digest = state.getDigest();
double percentile = state.getPercentile();
if (digest == null || digest.getCount() == 0.0) {
out.appendNull();
} else {
checkState(percentile != -1.0, "Percentile is missing");
checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
DOUBLE.writeDouble(out, digest.valueAt(percentile));
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateDoublePercentileArrayAggregations method output.
@OutputFunction("array(double)")
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) {
DOUBLE.writeDouble(blockBuilder, value);
}
out.closeEntry();
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateRealPercentileAggregations method output.
@OutputFunction(StandardTypes.REAL)
public static void output(@AggregationState TDigestAndPercentileState state, BlockBuilder out) {
TDigest digest = state.getDigest();
double percentile = state.getPercentile();
if (digest == null || digest.getCount() == 0.0) {
out.appendNull();
} else {
checkState(percentile != -1.0, "Percentile is missing");
checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
REAL.writeLong(out, floatToRawIntBits((float) digest.valueAt(percentile)));
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class BigintApproximateMostFrequent method output.
@OutputFunction("map(bigint,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) -> {
BigintType.BIGINT.writeLong(entryBuilder, key);
BigintType.BIGINT.writeLong(entryBuilder, value);
});
out.closeEntry();
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class LegacyApproximateLongPercentileAggregations method output.
@OutputFunction(StandardTypes.BIGINT)
public static void output(@AggregationState QuantileDigestAndPercentileState state, BlockBuilder out) {
QuantileDigest digest = state.getDigest();
double percentile = state.getPercentile();
if (digest == null || digest.getCount() == 0.0) {
out.appendNull();
} else {
checkState(percentile != -1.0, "Percentile is missing");
checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
BIGINT.writeLong(out, digest.getQuantile(percentile));
}
}
Aggregations