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); }
switch (metadata.getParameterType()) { case STATE: checkArgument(stateDescriptors.get(stateIndex).getStateInterface() == parameters[i], String.format("State argument must be of type %s", stateDescriptors.get(stateIndex).getStateInterface())); stateIndex++; break;
definition.declareField(a(PRIVATE, FINAL), "stateSerializer_" + i, AccumulatorStateSerializer.class), definition.declareField(a(PRIVATE, FINAL), "stateFactory_" + i, AccumulatorStateFactory.class), definition.declareField(a(PRIVATE, FINAL), "state_" + i, grouped ? stateDescriptors.get(i).getFactory().getGroupedStateClass() : stateDescriptors.get(i).getFactory().getSingleStateClass()), stateDescriptors.get(i))); callSiteBinder, stateDescriptors.stream() .map(stateDescriptor -> stateDescriptor.getSerializer().getSerializedType()) .collect(toImmutableList()));
List<Variable> scratchStates = new ArrayList<>(); for (int i = 0; i < stateCount; i++) { Class<?> scratchStateClass = stateFieldAndDescriptors.get(i).getStateDescriptor().getFactory().getSingleStateClass(); scratchStates.add(scope.declareVariable(scratchStateClass, "scratchState_" + i));
definition.declareField(a(PRIVATE, FINAL), "stateSerializer_" + i, AccumulatorStateSerializer.class), definition.declareField(a(PRIVATE, FINAL), "stateFactory_" + i, AccumulatorStateFactory.class), definition.declareField(a(PRIVATE, FINAL), "state_" + i, grouped ? stateDescriptors.get(i).getFactory().getGroupedStateClass() : stateDescriptors.get(i).getFactory().getSingleStateClass()), stateDescriptors.get(i))); callSiteBinder, stateDescriptors.stream() .map(stateDescriptor -> stateDescriptor.getSerializer().getSerializedType()) .collect(toImmutableList()));
List<Variable> scratchStates = new ArrayList<>(); for (int i = 0; i < stateCount; i++) { Class<?> scratchStateClass = stateFieldAndDescriptors.get(i).getStateDescriptor().getFactory().getSingleStateClass(); scratchStates.add(scope.declareVariable(scratchStateClass, "scratchState_" + i));
combineMethodHandle = LONG_STATE_COMBINE_FUNCTION; outputMethodHandle = LONG_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableLongState.class, StateCompiler.generateStateSerializer(NullableLongState.class, classLoader), combineMethodHandle = DOUBLE_STATE_COMBINE_FUNCTION; outputMethodHandle = DOUBLE_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableDoubleState.class, StateCompiler.generateStateSerializer(NullableDoubleState.class, classLoader), combineMethodHandle = BOOLEAN_STATE_COMBINE_FUNCTION; outputMethodHandle = BOOLEAN_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableBooleanState.class, StateCompiler.generateStateSerializer(NullableBooleanState.class, classLoader),
combineMethod, outputMethod, ImmutableList.of(new AccumulatorStateDescriptor( stateClazz, stateSerializer,
combineMethodHandle = LONG_STATE_COMBINE_FUNCTION; outputMethodHandle = LONG_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableLongState.class, StateCompiler.generateStateSerializer(NullableLongState.class, classLoader), combineMethodHandle = DOUBLE_STATE_COMBINE_FUNCTION; outputMethodHandle = DOUBLE_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableDoubleState.class, StateCompiler.generateStateSerializer(NullableDoubleState.class, classLoader), combineMethodHandle = BOOLEAN_STATE_COMBINE_FUNCTION; outputMethodHandle = BOOLEAN_STATE_OUTPUT_FUNCTION.bindTo(stateType); stateDescriptor = new AccumulatorStateDescriptor( NullableBooleanState.class, StateCompiler.generateStateSerializer(NullableBooleanState.class, classLoader),
combineFunction, outputFunction.bindTo(type), ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer,
combineMethod, outputMethod, ImmutableList.of(new AccumulatorStateDescriptor( stateClazz, stateSerializer,
combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer,
combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer,
combineFunction, outputFunction.bindTo(type), ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer,
combineHandle, outputHandle, ImmutableList.of(new AccumulatorStateDescriptor( stateClass, stateSerializer,
combineHandle, outputHandle, ImmutableList.of(new AccumulatorStateDescriptor( stateClass, stateSerializer,
switch (metadata.getParameterType()) { case STATE: checkArgument(stateDescriptors.get(stateIndex).getStateInterface() == parameters[i], String.format("State argument must be of type %s", stateDescriptors.get(stateIndex).getStateInterface())); stateIndex++; break;
COMBINE_FUNCTION, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer,
OUTPUT_FUNCTION, ImmutableList.of( new AccumulatorStateDescriptor( longStateInterface, longStateSerializer, StateCompiler.generateStateFactory(longStateInterface, classLoader)), new AccumulatorStateDescriptor( doubleStateInterface, doubleStateSerializer,
OUTPUT_FUNCTION, ImmutableList.of( new AccumulatorStateDescriptor( longStateInterface, longStateSerializer, StateCompiler.generateStateFactory(longStateInterface, classLoader)), new AccumulatorStateDescriptor( doubleStateInterface, doubleStateSerializer,