@Override public void append(JsonParser parser, BlockBuilder blockBuilder) throws IOException { Long result = currentTokenAsReal(parser); if (result == null) { blockBuilder.appendNull(); } else { REAL.writeLong(blockBuilder, result); } } }
public static Block createTestBlock() { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, 30); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F)); REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F)); REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F)); REAL.writeLong(blockBuilder, floatToRawIntBits(44.44F)); return blockBuilder.build(); }
@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(); } } }
public static void output(LongState count, DoubleState sum, BlockBuilder out) { if (count.getLong() == 0) { out.appendNull(); } else { REAL.writeLong(out, floatToIntBits((float) (sum.getDouble() / count.getLong()))); } } }
@OutputFunction(StandardTypes.REAL) public static void output(@AggregationState LongAndDoubleState state, BlockBuilder out) { long count = state.getLong(); if (count == 0) { out.appendNull(); } else { REAL.writeLong(out, floatToRawIntBits((float) Math.exp(state.getDouble() / count))); } } }
@OutputFunction(StandardTypes.REAL) public static void output(@AggregationState NullableDoubleState state, BlockBuilder out) { if (state.isNull()) { out.appendNull(); } else { REAL.writeLong(out, floatToRawIntBits((float) state.getDouble())); } } }
@OutputFunction(StandardTypes.REAL) public static void corr(@AggregationState CorrelationState state, BlockBuilder out) { double result = getCorrelation(state); if (Double.isFinite(result)) { long resultBits = floatToRawIntBits((float) result); REAL.writeLong(out, resultBits); } else { out.appendNull(); } } }
public static Block createSequenceBlockOfReal(int start, int end) { BlockBuilder builder = REAL.createFixedSizeBlockBuilder(end - start); for (int i = start; i < end; i++) { REAL.writeLong(builder, floatToRawIntBits((float) i)); } return builder.build(); }
@Override public Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }
@Override public Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }
@AggregationFunction("covar_samp") @OutputFunction(StandardTypes.REAL) public static void covarSamp(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() <= 1) { out.appendNull(); } else { double result = getCovarianceSample(state); REAL.writeLong(out, Float.floatToRawIntBits((float) result)); } }
@AggregationFunction("regr_slope") @OutputFunction(StandardTypes.REAL) public static void regrSlope(@AggregationState RegressionState state, BlockBuilder out) { double result = getRegressionSlope(state); if (Double.isFinite(result)) { REAL.writeLong(out, floatToRawIntBits((float) result)); } else { out.appendNull(); } }
@Override public Block[] getSequenceBlocks(int start, int length) { BlockBuilder blockBuilder = REAL.createBlockBuilder(null, length); for (int i = start; i < start + length; i++) { REAL.writeLong(blockBuilder, floatToRawIntBits((float) i)); } return new Block[] {blockBuilder.build()}; }
@AggregationFunction("covar_pop") @OutputFunction(StandardTypes.REAL) public static void covarPop(@AggregationState CovarianceState state, BlockBuilder out) { if (state.getCount() == 0) { out.appendNull(); } else { double result = getCovariancePopulation(state); REAL.writeLong(out, Float.floatToRawIntBits((float) result)); } } }
@AggregationFunction("regr_intercept") @OutputFunction(StandardTypes.REAL) public static void regrIntercept(@AggregationState RegressionState state, BlockBuilder out) { double result = getRegressionIntercept(state); if (Double.isFinite(result)) { REAL.writeLong(out, floatToRawIntBits((float) result)); } else { out.appendNull(); } } }
@OutputFunction("array(real)") public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) { QuantileDigest digest = state.getDigest(); List<Double> percentiles = state.getPercentiles(); if (percentiles == null || digest == null) { out.appendNull(); return; } BlockBuilder blockBuilder = out.beginBlockEntry(); for (int i = 0; i < percentiles.size(); i++) { Double percentile = percentiles.get(i); REAL.writeLong(blockBuilder, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile)))); } out.closeEntry(); } }
@OutputFunction(StandardTypes.REAL) public static void output(@AggregationState DigestAndPercentileState 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"); REAL.writeLong(out, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile)))); } } }
private static Block createBlockOfReals(Iterable<Float> values) { BlockBuilder builder = REAL.createBlockBuilder(null, 100); for (Float value : values) { if (value == null) { builder.appendNull(); } else { REAL.writeLong(builder, floatToRawIntBits(value)); } } return builder.build(); }
@ScalarFunction("values_at_quantiles") @Description("For each input q between [0, 1], find the value whose rank in the sorted sequence of the n values represented by the qdigest is qn.") @SqlType("array(real)") public static Block valuesAtQuantilesReal(@SqlType("qdigest(real)") Slice input, @SqlType("array(double)") Block percentilesArrayBlock) { QuantileDigest digest = new QuantileDigest(input); BlockBuilder output = REAL.createBlockBuilder(null, percentilesArrayBlock.getPositionCount()); for (int i = 0; i < percentilesArrayBlock.getPositionCount(); i++) { REAL.writeLong(output, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(DOUBLE.getDouble(percentilesArrayBlock, i))))); } return output.build(); }
private static Page makeInput(int numberOfBuckets) { PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, REAL, DOUBLE)); for (int i = 0; i < 100; i++) { builder.declarePosition(); BIGINT.writeLong(builder.getBlockBuilder(0), numberOfBuckets); REAL.writeLong(builder.getBlockBuilder(1), i); // value DOUBLE.writeDouble(builder.getBlockBuilder(2), 1); // weight } return builder.build(); } }