private static InternalAggregationFunction generateAggregation(Type type) { DynamicClassLoader classLoader = new DynamicClassLoader(ChecksumAggregationFunction.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(type); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), INPUT_FUNCTION.bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( NullableLongState.class, StateCompiler.generateStateSerializer(NullableLongState.class, classLoader), StateCompiler.generateStateFactory(NullableLongState.class, classLoader))), VARBINARY); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(BIGINT), VARBINARY, true, false, factory); }
@CombineFunction public static void combine(@AggregationState CorrelationState state, @AggregationState CorrelationState otherState) { mergeCorrelationState(state, otherState); }
@CombineFunction public static void combine(@AggregationState CovarianceState state, @AggregationState CovarianceState otherState) { mergeCovarianceState(state, otherState); }
public static void mergeCovarianceState(CovarianceState state, CovarianceState otherState) { if (otherState.getCount() == 0) { return; } updateCovarianceState(state, otherState); }
for (String name : getNames(outputFunction, aggregationAnnotation)) { List<Type> inputTypes = getInputTypes(inputFunction); Type outputType = AggregationUtils.getOutputType(outputFunction, stateSerializer, typeManager); MethodHandle outputHandle = outputFunction == null ? null : lookup().unreflect(outputFunction); metadata = new AggregationMetadata( generateAggregationName(name, outputType, inputTypes), getParameterMetadata(inputFunction, aggregationAnnotation.approximate()), inputHandle,
@InputFunction public static void doubleInput(@AggregationState VarianceState state, @SqlType(StandardTypes.DOUBLE) double value) { updateVarianceState(state, value); }
@CombineFunction public static void combine(@AggregationState VarianceState state, @AggregationState VarianceState otherState) { mergeVarianceState(state, otherState); }
@CombineFunction public static void combine(@AggregationState RegressionState state, @AggregationState RegressionState otherState) { mergeRegressionState(state, otherState); }
@InputFunction public static void input(@AggregationState RegressionState state, @SqlType(StandardTypes.DOUBLE) double dependentValue, @SqlType(StandardTypes.DOUBLE) double independentValue) { updateRegressionState(state, independentValue, dependentValue); }
@InputFunction public static void input(@AggregationState CorrelationState state, @SqlType(StandardTypes.DOUBLE) double dependentValue, @SqlType(StandardTypes.DOUBLE) double independentValue) { updateCorrelationState(state, independentValue, dependentValue); }
@InputFunction public static void input(@AggregationState CovarianceState state, @SqlType(StandardTypes.DOUBLE) double dependentValue, @SqlType(StandardTypes.DOUBLE) double independentValue) { updateCovarianceState(state, independentValue, dependentValue); }
@InputFunction public static void bigintInput(@AggregationState VarianceState state, @SqlType(StandardTypes.BIGINT) long value) { updateVarianceState(state, (double) value); }
@CombineFunction public static void combine(VarianceState state, VarianceState otherState) { mergeVarianceState(state, otherState); }
@CombineFunction public static void combine(RegressionState state, RegressionState otherState) { mergeRegressionState(state, otherState); }
@InputFunction public static void input(RegressionState state, @SqlType(StandardTypes.DOUBLE) double dependentValue, @SqlType(StandardTypes.DOUBLE) double independentValue) { updateRegressionState(state, independentValue, dependentValue); }
@InputFunction public static void input(CorrelationState state, @SqlType(StandardTypes.DOUBLE) double dependentValue, @SqlType(StandardTypes.DOUBLE) double independentValue) { updateCorrelationState(state, independentValue, dependentValue); }
private static InternalAggregationFunction generateAggregation(Type type) { DynamicClassLoader classLoader = new DynamicClassLoader(CountColumn.class.getClassLoader()); AccumulatorStateSerializer<LongState> stateSerializer = StateCompiler.generateStateSerializer(LongState.class, classLoader); AccumulatorStateFactory<LongState> stateFactory = StateCompiler.generateStateFactory(LongState.class, classLoader); Type intermediateType = stateSerializer.getSerializedType(); List<Type> inputTypes = ImmutableList.of(type); AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, BIGINT.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), INPUT_FUNCTION, COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor( LongState.class, stateSerializer, stateFactory)), BIGINT); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), BIGINT, true, false, factory); }
public static void updateRegressionState(RegressionState state, double x, double y) { double oldMeanX = state.getMeanX(); updateCovarianceState(state, x, y); state.setM2X(state.getM2X() + (x - oldMeanX) * (x - state.getMeanX())); }
@InputFunction public static void bigintInput(VarianceState state, @SqlType(StandardTypes.BIGINT) long value) { updateVarianceState(state, (double) value); }
@CombineFunction public static void combine(ApproximateLongSumState state, ApproximateLongSumState otherState) { state.setSum(state.getSum() + otherState.getSum()); state.setWeightedCount(state.getWeightedCount() + otherState.getWeightedCount()); mergeVarianceState(state, otherState); }