@OutputFunction(StandardTypes.HYPER_LOG_LOG) public static void output(@AggregationState HyperLogLogState state, BlockBuilder out) { serializer.serialize(state, out); } }
@Test public void testGetSerializedType() { AccumulatorStateSerializer<LongState> serializer = StateCompiler.generateStateSerializer(LongState.class); assertEquals(serializer.getSerializedType(), BIGINT); }
@Test public void testPrimitiveBooleanSerialization() { AccumulatorStateFactory<BooleanState> factory = StateCompiler.generateStateFactory(BooleanState.class); AccumulatorStateSerializer<BooleanState> serializer = StateCompiler.generateStateSerializer(BooleanState.class); BooleanState state = factory.createSingleState(); BooleanState deserializedState = factory.createSingleState(); state.setBoolean(true); BlockBuilder builder = BOOLEAN.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.isBoolean(), state.isBoolean()); }
@Test public void testPrimitiveByteSerialization() { AccumulatorStateFactory<ByteState> factory = StateCompiler.generateStateFactory(ByteState.class); AccumulatorStateSerializer<ByteState> serializer = StateCompiler.generateStateSerializer(ByteState.class); ByteState state = factory.createSingleState(); ByteState deserializedState = factory.createSingleState(); state.setByte((byte) 3); BlockBuilder builder = TINYINT.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getByte(), state.getByte()); }
@Test public void testPrimitiveByteSerialization() { AccumulatorStateFactory<ByteState> factory = StateCompiler.generateStateFactory(ByteState.class); AccumulatorStateSerializer<ByteState> serializer = StateCompiler.generateStateSerializer(ByteState.class); ByteState state = factory.createSingleState(); ByteState deserializedState = factory.createSingleState(); state.setByte((byte) 3); BlockBuilder builder = TINYINT.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getByte(), state.getByte()); }
@Test public void testGetSerializedType() { AccumulatorStateSerializer<LongState> serializer = StateCompiler.generateStateSerializer(LongState.class); assertEquals(serializer.getSerializedType(), BIGINT); }
@OutputFunction(StandardTypes.HYPER_LOG_LOG) public static void evaluateFinal(@AggregationState HyperLogLogState state, BlockBuilder out) { SERIALIZER.serialize(state, out); } }
@Test public void testPrimitiveBooleanSerialization() { AccumulatorStateFactory<BooleanState> factory = StateCompiler.generateStateFactory(BooleanState.class); AccumulatorStateSerializer<BooleanState> serializer = StateCompiler.generateStateSerializer(BooleanState.class); BooleanState state = factory.createSingleState(); BooleanState deserializedState = factory.createSingleState(); state.setBoolean(true); BlockBuilder builder = BOOLEAN.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.isBoolean(), state.isBoolean()); }
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); }
@OutputFunction(StandardTypes.HYPER_LOG_LOG) public static void output(@AggregationState HyperLogLogState state, BlockBuilder out) { serializer.serialize(state, out); } }
@Test public void testNonPrimitiveSerialization() { AccumulatorStateFactory<SliceState> factory = StateCompiler.generateStateFactory(SliceState.class); AccumulatorStateSerializer<SliceState> serializer = StateCompiler.generateStateSerializer(SliceState.class); SliceState state = factory.createSingleState(); SliceState deserializedState = factory.createSingleState(); state.setSlice(null); BlockBuilder nullBlockBuilder = VARCHAR.createBlockBuilder(null, 1); serializer.serialize(state, nullBlockBuilder); Block nullBlock = nullBlockBuilder.build(); serializer.deserialize(nullBlock, 0, deserializedState); assertEquals(deserializedState.getSlice(), state.getSlice()); state.setSlice(utf8Slice("test")); BlockBuilder builder = VARCHAR.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getSlice(), state.getSlice()); }
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); }
@OutputFunction(StandardTypes.HYPER_LOG_LOG) public static void evaluateFinal(@AggregationState HyperLogLogState state, BlockBuilder out) { SERIALIZER.serialize(state, out); } }
@Test public void testNonPrimitiveSerialization() { AccumulatorStateFactory<SliceState> factory = StateCompiler.generateStateFactory(SliceState.class); AccumulatorStateSerializer<SliceState> serializer = StateCompiler.generateStateSerializer(SliceState.class); SliceState state = factory.createSingleState(); SliceState deserializedState = factory.createSingleState(); state.setSlice(null); BlockBuilder nullBlockBuilder = VARCHAR.createBlockBuilder(null, 1); serializer.serialize(state, nullBlockBuilder); Block nullBlock = nullBlockBuilder.build(); serializer.deserialize(nullBlock, 0, deserializedState); assertEquals(deserializedState.getSlice(), state.getSlice()); state.setSlice(utf8Slice("test")); BlockBuilder builder = VARCHAR.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getSlice(), state.getSlice()); }
private static InternalAggregationFunction generateAggregation(Type type, ArrayAggGroupImplementation groupMode) { DynamicClassLoader classLoader = new DynamicClassLoader(ArrayAggregationFunction.class.getClassLoader()); AccumulatorStateSerializer<?> stateSerializer = new ArrayAggregationStateSerializer(type); AccumulatorStateFactory<?> stateFactory = new ArrayAggregationStateFactory(type, groupMode); List<Type> inputTypes = ImmutableList.of(type); Type outputType = new ArrayType(type); Type intermediateType = stateSerializer.getSerializedType(); List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type); MethodHandle inputFunction = INPUT_FUNCTION.bindTo(type); MethodHandle combineFunction = COMBINE_FUNCTION.bindTo(type); MethodHandle outputFunction = OUTPUT_FUNCTION.bindTo(type); Class<? extends AccumulatorState> stateInterface = ArrayAggregationState.class; AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer, stateFactory)), outputType); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory); }
@Test public void testPrimitiveLongSerialization() { AccumulatorStateFactory<LongState> factory = StateCompiler.generateStateFactory(LongState.class); AccumulatorStateSerializer<LongState> serializer = StateCompiler.generateStateSerializer(LongState.class); LongState state = factory.createSingleState(); LongState deserializedState = factory.createSingleState(); state.setLong(2); BlockBuilder builder = BIGINT.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); assertEquals(BIGINT.getLong(block, 0), state.getLong()); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getLong(), state.getLong()); }
private static InternalAggregationFunction generateAggregation(Type type, ArrayAggGroupImplementation groupMode) { DynamicClassLoader classLoader = new DynamicClassLoader(ArrayAggregationFunction.class.getClassLoader()); AccumulatorStateSerializer<?> stateSerializer = new ArrayAggregationStateSerializer(type); AccumulatorStateFactory<?> stateFactory = new ArrayAggregationStateFactory(type, groupMode); List<Type> inputTypes = ImmutableList.of(type); Type outputType = new ArrayType(type); Type intermediateType = stateSerializer.getSerializedType(); List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type); MethodHandle inputFunction = INPUT_FUNCTION.bindTo(type); MethodHandle combineFunction = COMBINE_FUNCTION.bindTo(type); MethodHandle outputFunction = OUTPUT_FUNCTION.bindTo(type); Class<? extends AccumulatorState> stateInterface = ArrayAggregationState.class; AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction, ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer, stateFactory)), outputType); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, true, factory); }
@Test public void testPrimitiveLongSerialization() { AccumulatorStateFactory<LongState> factory = StateCompiler.generateStateFactory(LongState.class); AccumulatorStateSerializer<LongState> serializer = StateCompiler.generateStateSerializer(LongState.class); LongState state = factory.createSingleState(); LongState deserializedState = factory.createSingleState(); state.setLong(2); BlockBuilder builder = BIGINT.createBlockBuilder(null, 1); serializer.serialize(state, builder); Block block = builder.build(); assertEquals(BIGINT.getLong(block, 0), state.getLong()); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getLong(), state.getLong()); }
private static InternalAggregationFunction generateAggregation(Type inputType, Type outputType) { checkArgument(inputType instanceof DecimalType, "type must be Decimal"); DynamicClassLoader classLoader = new DynamicClassLoader(DecimalSumAggregation.class.getClassLoader()); List<Type> inputTypes = ImmutableList.of(inputType); MethodHandle inputFunction; Class<? extends AccumulatorState> stateInterface = LongDecimalWithOverflowState.class; AccumulatorStateSerializer<?> stateSerializer = new LongDecimalWithOverflowStateSerializer(); if (((DecimalType) inputType).isShort()) { inputFunction = SHORT_DECIMAL_INPUT_FUNCTION; } else { inputFunction = LONG_DECIMAL_INPUT_FUNCTION; } AggregationMetadata metadata = new AggregationMetadata( generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(inputType), inputFunction.bindTo(inputType), COMBINE_FUNCTION, LONG_DECIMAL_OUTPUT_FUNCTION.bindTo(outputType), ImmutableList.of(new AccumulatorStateDescriptor( stateInterface, stateSerializer, new LongDecimalWithOverflowStateFactory())), outputType); Type intermediateType = stateSerializer.getSerializedType(); GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader); return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory); }
@Test public void testPrimitiveNullableLongSerialization() { AccumulatorStateFactory<NullableLongState> factory = StateCompiler.generateStateFactory(NullableLongState.class); AccumulatorStateSerializer<NullableLongState> serializer = StateCompiler.generateStateSerializer(NullableLongState.class); NullableLongState state = factory.createSingleState(); NullableLongState deserializedState = factory.createSingleState(); state.setLong(2); state.setNull(false); BlockBuilder builder = BIGINT.createBlockBuilder(null, 2); serializer.serialize(state, builder); state.setNull(true); serializer.serialize(state, builder); Block block = builder.build(); assertEquals(block.isNull(0), false); assertEquals(BIGINT.getLong(block, 0), state.getLong()); serializer.deserialize(block, 0, deserializedState); assertEquals(deserializedState.getLong(), state.getLong()); assertEquals(block.isNull(1), true); }