Search in sources :

Example 6 with CallSiteBinder

use of io.prestosql.sql.gen.CallSiteBinder in project hetu-core by openlookeng.

the class AbstractMinMaxBy method generateAggregation.

private InternalAggregationFunction generateAggregation(Type valueType, Type keyType, FunctionAndTypeManager functionAndTypeManager) {
    Class<?> stateClazz = getStateClass(keyType.getJavaType(), valueType.getJavaType());
    DynamicClassLoader classLoader = new DynamicClassLoader(getClass().getClassLoader());
    // Generate states and serializers:
    // For value that is a Block or Slice, we store them as Block/position combination
    // to avoid generating long-living objects through getSlice or getObject.
    // This can also help reducing cross-region reference in G1GC engine.
    // TODO: keys can have the same problem. But usually they are primitive types (given the nature of comparison).
    AccumulatorStateFactory<?> stateFactory;
    AccumulatorStateSerializer<?> stateSerializer;
    if (valueType.getJavaType().isPrimitive()) {
        Map<String, Type> stateFieldTypes = ImmutableMap.of("First", keyType, "Second", valueType);
        stateFactory = StateCompiler.generateStateFactory(stateClazz, stateFieldTypes, classLoader);
        stateSerializer = StateCompiler.generateStateSerializer(stateClazz, stateFieldTypes, classLoader);
    } else {
        // StateCompiler checks type compatibility.
        // Given "Second" in this case is always a Block, we only need to make sure the getter and setter of the Blocks are properly generated.
        // We deliberately make "SecondBlock" an array type so that the compiler will treat it as a block to workaround the sanity check.
        stateFactory = StateCompiler.generateStateFactory(stateClazz, ImmutableMap.of("First", keyType, "SecondBlock", new ArrayType(valueType)), classLoader);
        // States can be generated by StateCompiler given the they are simply classes with getters and setters.
        // However, serializers have logic in it. Creating serializers is better than generating them.
        stateSerializer = getStateSerializer(keyType, valueType);
    }
    Type intermediateType = stateSerializer.getSerializedType();
    List<Type> inputTypes = ImmutableList.of(valueType, keyType);
    CallSiteBinder binder = new CallSiteBinder();
    OperatorType operator = min ? LESS_THAN : GREATER_THAN;
    MethodHandle compareMethod = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionAndTypeManager.resolveOperatorFunctionHandle(operator, TypeSignatureProvider.fromTypes(keyType, keyType))).getMethodHandle();
    ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("processMaxOrMinBy"), type(Object.class));
    definition.declareDefaultConstructor(a(PRIVATE));
    generateInputMethod(definition, binder, compareMethod, keyType, valueType, stateClazz);
    generateCombineMethod(definition, binder, compareMethod, keyType, valueType, stateClazz);
    generateOutputMethod(definition, binder, valueType, stateClazz);
    Class<?> generatedClass = defineClass(definition, Object.class, binder.getBindings(), classLoader);
    MethodHandle inputMethod = methodHandle(generatedClass, "input", stateClazz, Block.class, Block.class, int.class);
    MethodHandle combineMethod = methodHandle(generatedClass, "combine", stateClazz, stateClazz);
    MethodHandle outputMethod = methodHandle(generatedClass, "output", stateClazz, BlockBuilder.class);
    AggregationMetadata aggregationMetadata = new AggregationMetadata(generateAggregationName(getSignature().getNameSuffix(), valueType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(valueType, keyType), inputMethod, combineMethod, outputMethod, ImmutableList.of(new AccumulatorStateDescriptor(stateClazz, stateSerializer, stateFactory)), valueType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(aggregationMetadata, classLoader);
    return new InternalAggregationFunction(getSignature().getNameSuffix(), inputTypes, ImmutableList.of(intermediateType), valueType, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericAccumulatorFactoryBinder(io.prestosql.operator.aggregation.GenericAccumulatorFactoryBinder) ClassDefinition(io.airlift.bytecode.ClassDefinition) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) OperatorType(io.prestosql.spi.function.OperatorType) ArrayType(io.prestosql.spi.type.ArrayType) SqlTypeBytecodeExpression.constantType(io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder) AggregationMetadata(io.prestosql.operator.aggregation.AggregationMetadata) MethodHandle(java.lang.invoke.MethodHandle)

Example 7 with CallSiteBinder

use of io.prestosql.sql.gen.CallSiteBinder in project hetu-core by openlookeng.

the class MapTransformKeyFunction method generateTransformKey.

private static MethodHandle generateTransformKey(Type keyType, Type transformedKeyType, Type valueType, Type resultMapType) {
    CallSiteBinder binder = new CallSiteBinder();
    Class<?> keyJavaType = Primitives.wrap(keyType.getJavaType());
    Class<?> transformedKeyJavaType = Primitives.wrap(transformedKeyType.getJavaType());
    Class<?> valueJavaType = Primitives.wrap(valueType.getJavaType());
    ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("MapTransformKey"), type(Object.class));
    definition.declareDefaultConstructor(a(PRIVATE));
    Parameter state = arg("state", Object.class);
    Parameter session = arg("session", ConnectorSession.class);
    Parameter block = arg("block", Block.class);
    Parameter function = arg("function", BinaryFunctionInterface.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "transform", type(Block.class), ImmutableList.of(state, session, block, function));
    BytecodeBlock body = method.getBody();
    Scope scope = method.getScope();
    Variable positionCount = scope.declareVariable(int.class, "positionCount");
    Variable position = scope.declareVariable(int.class, "position");
    Variable pageBuilder = scope.declareVariable(PageBuilder.class, "pageBuilder");
    Variable mapBlockBuilder = scope.declareVariable(BlockBuilder.class, "mapBlockBuilder");
    Variable blockBuilder = scope.declareVariable(BlockBuilder.class, "blockBuilder");
    Variable typedSet = scope.declareVariable(TypedSet.class, "typeSet");
    Variable keyElement = scope.declareVariable(keyJavaType, "keyElement");
    Variable transformedKeyElement = scope.declareVariable(transformedKeyJavaType, "transformedKeyElement");
    Variable valueElement = scope.declareVariable(valueJavaType, "valueElement");
    // invoke block.getPositionCount()
    body.append(positionCount.set(block.invoke("getPositionCount", int.class)));
    // prepare the single map block builder
    body.append(pageBuilder.set(state.cast(PageBuilder.class)));
    body.append(new IfStatement().condition(pageBuilder.invoke("isFull", boolean.class)).ifTrue(pageBuilder.invoke("reset", void.class)));
    body.append(mapBlockBuilder.set(pageBuilder.invoke("getBlockBuilder", BlockBuilder.class, constantInt(0))));
    body.append(blockBuilder.set(mapBlockBuilder.invoke("beginBlockEntry", BlockBuilder.class)));
    // create typed set
    body.append(typedSet.set(newInstance(TypedSet.class, constantType(binder, transformedKeyType), divide(positionCount, constantInt(2)), constantString(MAP_TRANSFORM_KEY_FUNCTION.getSignature().getNameSuffix()))));
    // throw null key exception block
    BytecodeNode throwNullKeyException = new BytecodeBlock().append(newInstance(PrestoException.class, getStatic(INVALID_FUNCTION_ARGUMENT.getDeclaringClass(), "INVALID_FUNCTION_ARGUMENT").cast(ErrorCodeSupplier.class), constantString("map key cannot be null"))).throwObject();
    SqlTypeBytecodeExpression keySqlType = constantType(binder, keyType);
    BytecodeNode loadKeyElement;
    if (!keyType.equals(UNKNOWN)) {
        loadKeyElement = new BytecodeBlock().append(keyElement.set(keySqlType.getValue(block, position).cast(keyJavaType)));
    } else {
        // make sure invokeExact will not take uninitialized keys during compile time
        // but if we reach this point during runtime, it is an exception
        // also close the block builder before throwing as we may be in a TRY() call
        // so that subsequent calls do not find it in an inconsistent state
        loadKeyElement = new BytecodeBlock().append(mapBlockBuilder.invoke("closeEntry", BlockBuilder.class).pop()).append(keyElement.set(constantNull(keyJavaType))).append(throwNullKeyException);
    }
    SqlTypeBytecodeExpression valueSqlType = constantType(binder, valueType);
    BytecodeNode loadValueElement;
    if (!valueType.equals(UNKNOWN)) {
        loadValueElement = new IfStatement().condition(block.invoke("isNull", boolean.class, add(position, constantInt(1)))).ifTrue(valueElement.set(constantNull(valueJavaType))).ifFalse(valueElement.set(valueSqlType.getValue(block, add(position, constantInt(1))).cast(valueJavaType)));
    } else {
        // make sure invokeExact will not take uninitialized keys during compile time
        loadValueElement = new BytecodeBlock().append(valueElement.set(constantNull(valueJavaType)));
    }
    SqlTypeBytecodeExpression transformedKeySqlType = constantType(binder, transformedKeyType);
    BytecodeNode writeKeyElement;
    BytecodeNode throwDuplicatedKeyException;
    if (!transformedKeyType.equals(UNKNOWN)) {
        writeKeyElement = new BytecodeBlock().append(transformedKeyElement.set(function.invoke("apply", Object.class, keyElement.cast(Object.class), valueElement.cast(Object.class)).cast(transformedKeyJavaType))).append(new IfStatement().condition(equal(transformedKeyElement, constantNull(transformedKeyJavaType))).ifTrue(throwNullKeyException).ifFalse(new BytecodeBlock().append(constantType(binder, transformedKeyType).writeValue(blockBuilder, transformedKeyElement.cast(transformedKeyType.getJavaType()))).append(valueSqlType.invoke("appendTo", void.class, block, add(position, constantInt(1)), blockBuilder))));
        // make sure getObjectValue takes a known key type
        throwDuplicatedKeyException = new BytecodeBlock().append(mapBlockBuilder.invoke("closeEntry", BlockBuilder.class).pop()).append(newInstance(PrestoException.class, getStatic(INVALID_FUNCTION_ARGUMENT.getDeclaringClass(), "INVALID_FUNCTION_ARGUMENT").cast(ErrorCodeSupplier.class), invokeStatic(String.class, "format", String.class, constantString("Duplicate keys (%s) are not allowed"), newArray(type(Object[].class), ImmutableList.of(transformedKeySqlType.invoke("getObjectValue", Object.class, session, blockBuilder.cast(Block.class), position)))))).throwObject();
    } else {
        // key cannot be unknown
        // if we reach this point during runtime, it is an exception
        writeKeyElement = throwNullKeyException;
        throwDuplicatedKeyException = throwNullKeyException;
    }
    body.append(new ForLoop().initialize(position.set(constantInt(0))).condition(lessThan(position, positionCount)).update(incrementVariable(position, (byte) 2)).body(new BytecodeBlock().append(loadKeyElement).append(loadValueElement).append(writeKeyElement).append(new IfStatement().condition(typedSet.invoke("contains", boolean.class, blockBuilder.cast(Block.class), position)).ifTrue(throwDuplicatedKeyException).ifFalse(typedSet.invoke("add", void.class, blockBuilder.cast(Block.class), position)))));
    body.append(mapBlockBuilder.invoke("closeEntry", BlockBuilder.class).pop());
    body.append(pageBuilder.invoke("declarePosition", void.class));
    body.append(constantType(binder, resultMapType).invoke("getObject", Object.class, mapBlockBuilder.cast(Block.class), subtract(mapBlockBuilder.invoke("getPositionCount", int.class), constantInt(1))).ret());
    Class<?> generatedClass = defineClass(definition, Object.class, binder.getBindings(), MapTransformKeyFunction.class.getClassLoader());
    return methodHandle(generatedClass, "transform", Object.class, ConnectorSession.class, Block.class, BinaryFunctionInterface.class);
}
Also used : Variable(io.airlift.bytecode.Variable) VariableInstruction.incrementVariable(io.airlift.bytecode.instruction.VariableInstruction.incrementVariable) Signature.typeVariable(io.prestosql.spi.function.Signature.typeVariable) ErrorCodeSupplier(io.prestosql.spi.ErrorCodeSupplier) ForLoop(io.airlift.bytecode.control.ForLoop) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) PrestoException(io.prestosql.spi.PrestoException) ClassDefinition(io.airlift.bytecode.ClassDefinition) IfStatement(io.airlift.bytecode.control.IfStatement) Scope(io.airlift.bytecode.Scope) MethodDefinition(io.airlift.bytecode.MethodDefinition) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) Parameter(io.airlift.bytecode.Parameter) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Block(io.prestosql.spi.block.Block) BytecodeNode(io.airlift.bytecode.BytecodeNode) SqlTypeBytecodeExpression(io.prestosql.sql.gen.SqlTypeBytecodeExpression) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 8 with CallSiteBinder

use of io.prestosql.sql.gen.CallSiteBinder in project hetu-core by openlookeng.

the class RowIndeterminateOperator method generateIndeterminate.

private static Class<?> generateIndeterminate(Type type, FunctionAndTypeManager functionAndTypeManager) {
    CallSiteBinder binder = new CallSiteBinder();
    ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("RowIndeterminateOperator"), type(Object.class));
    Parameter value = arg("value", type.getJavaType());
    Parameter isNull = arg("isNull", boolean.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "indeterminate", type(boolean.class), value, isNull);
    Scope scope = method.getScope();
    BytecodeBlock body = method.getBody();
    Variable wasNull = scope.declareVariable(boolean.class, "wasNull");
    body.append(wasNull.set(constantFalse()));
    CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(definition, binder);
    LabelNode end = new LabelNode("end");
    List<Type> fieldTypes = type.getTypeParameters();
    boolean hasUnknownFields = fieldTypes.stream().anyMatch(fieldType -> fieldType.equals(UNKNOWN));
    body.append(new IfStatement("if isNull is true...").condition(isNull).ifTrue(new BytecodeBlock().push(true).gotoLabel(end)));
    if (hasUnknownFields) {
        // if the current field type is UNKNOWN which means this field is null, directly return true
        body.push(true).gotoLabel(end);
    } else {
        for (int i = 0; i < fieldTypes.size(); i++) {
            IfStatement ifNullField = new IfStatement("if the field is null...");
            ifNullField.condition(value.invoke("isNull", boolean.class, constantInt(i))).ifTrue(new BytecodeBlock().push(true).gotoLabel(end));
            FunctionHandle functionHandle = functionAndTypeManager.resolveOperatorFunctionHandle(INDETERMINATE, fromTypes(fieldTypes.get(i)));
            BuiltInScalarFunctionImplementation function = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionHandle);
            BytecodeExpression element = constantType(binder, fieldTypes.get(i)).getValue(value, constantInt(i));
            ifNullField.ifFalse(new IfStatement("if the field is not null but indeterminate...").condition(invokeFunction(scope, cachedInstanceBinder, functionAndTypeManager.getFunctionMetadata(functionHandle).getName().getObjectName(), function, element)).ifTrue(new BytecodeBlock().push(true).gotoLabel(end)));
            body.append(ifNullField);
        }
        // if none of the fields is indeterminate, then push false
        body.push(false);
    }
    body.visitLabel(end).retBoolean();
    // create constructor
    MethodDefinition constructorDefinition = definition.declareConstructor(a(PUBLIC));
    BytecodeBlock constructorBody = constructorDefinition.getBody();
    Variable thisVariable = constructorDefinition.getThis();
    constructorBody.comment("super();").append(thisVariable).invokeConstructor(Object.class);
    cachedInstanceBinder.generateInitializations(thisVariable, constructorBody);
    constructorBody.ret();
    return defineClass(definition, Object.class, binder.getBindings(), RowIndeterminateOperator.class.getClassLoader());
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) Variable(io.airlift.bytecode.Variable) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) ClassDefinition(io.airlift.bytecode.ClassDefinition) IfStatement(io.airlift.bytecode.control.IfStatement) SqlTypeBytecodeExpression.constantType(io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.prestosql.spi.type.Type) CachedInstanceBinder(io.prestosql.sql.gen.CachedInstanceBinder) Scope(io.airlift.bytecode.Scope) MethodDefinition(io.airlift.bytecode.MethodDefinition) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 9 with CallSiteBinder

use of io.prestosql.sql.gen.CallSiteBinder in project hetu-core by openlookeng.

the class RowToRowCast method generateRowCast.

private static Class<?> generateRowCast(Type fromType, Type toType, FunctionAndTypeManager functionAndTypeManager) {
    List<Type> toTypes = toType.getTypeParameters();
    List<Type> fromTypes = fromType.getTypeParameters();
    CallSiteBinder binder = new CallSiteBinder();
    // Embed the MD5 hash code of input and output types into the generated class name instead of the raw type names,
    // which could prevent the class name from hitting the length limitation and invalid characters.
    byte[] md5Suffix = Hashing.md5().hashBytes((fromType + "$" + toType).getBytes()).asBytes();
    ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName(Joiner.on("$").join("RowCast", BaseEncoding.base16().encode(md5Suffix))), type(Object.class));
    Parameter session = arg("session", ConnectorSession.class);
    Parameter value = arg("value", Block.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "castRow", type(Block.class), session, value);
    Scope scope = method.getScope();
    BytecodeBlock body = method.getBody();
    Variable wasNull = scope.declareVariable(boolean.class, "wasNull");
    Variable blockBuilder = scope.createTempVariable(BlockBuilder.class);
    Variable singleRowBlockWriter = scope.createTempVariable(BlockBuilder.class);
    body.append(wasNull.set(constantBoolean(false)));
    CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(definition, binder);
    // create the row block builder
    body.append(blockBuilder.set(constantType(binder, toType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(1))));
    body.append(singleRowBlockWriter.set(blockBuilder.invoke("beginBlockEntry", BlockBuilder.class)));
    // loop through to append member blocks
    for (int i = 0; i < toTypes.size(); i++) {
        FunctionHandle functionHandle = functionAndTypeManager.lookupCast(CastType.CAST, fromTypes.get(i).getTypeSignature(), toTypes.get(i).getTypeSignature());
        BuiltInScalarFunctionImplementation function = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionHandle);
        Type currentFromType = fromTypes.get(i);
        if (currentFromType.equals(UNKNOWN)) {
            body.append(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop());
            continue;
        }
        BytecodeExpression fromElement = constantType(binder, currentFromType).getValue(value, constantInt(i));
        BytecodeExpression toElement = invokeFunction(scope, cachedInstanceBinder, CAST.name(), function, fromElement);
        IfStatement ifElementNull = new IfStatement("if the element in the row type is null...");
        ifElementNull.condition(value.invoke("isNull", boolean.class, constantInt(i))).ifTrue(singleRowBlockWriter.invoke("appendNull", BlockBuilder.class).pop()).ifFalse(constantType(binder, toTypes.get(i)).writeValue(singleRowBlockWriter, toElement));
        body.append(ifElementNull);
    }
    // call blockBuilder.closeEntry() and return the single row block
    body.append(blockBuilder.invoke("closeEntry", BlockBuilder.class).pop());
    body.append(constantType(binder, toType).invoke("getObject", Object.class, blockBuilder.cast(Block.class), constantInt(0)).cast(Block.class).ret());
    // create constructor
    MethodDefinition constructorDefinition = definition.declareConstructor(a(PUBLIC));
    BytecodeBlock constructorBody = constructorDefinition.getBody();
    Variable thisVariable = constructorDefinition.getThis();
    constructorBody.comment("super();").append(thisVariable).invokeConstructor(Object.class);
    cachedInstanceBinder.generateInitializations(thisVariable, constructorBody);
    constructorBody.ret();
    return defineClass(definition, Object.class, binder.getBindings(), RowToRowCast.class.getClassLoader());
}
Also used : Variable(io.airlift.bytecode.Variable) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) ClassDefinition(io.airlift.bytecode.ClassDefinition) IfStatement(io.airlift.bytecode.control.IfStatement) SqlTypeBytecodeExpression.constantType(io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.prestosql.spi.type.Type) CastType(io.prestosql.metadata.CastType) CachedInstanceBinder(io.prestosql.sql.gen.CachedInstanceBinder) Scope(io.airlift.bytecode.Scope) MethodDefinition(io.airlift.bytecode.MethodDefinition) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder) Parameter(io.airlift.bytecode.Parameter) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Block(io.prestosql.spi.block.Block) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression) FunctionHandle(io.prestosql.spi.function.FunctionHandle) BlockBuilderStatus(io.prestosql.spi.block.BlockBuilderStatus) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 10 with CallSiteBinder

use of io.prestosql.sql.gen.CallSiteBinder in project hetu-core by openlookeng.

the class StateCompiler method generateStateSerializer.

public static <T> AccumulatorStateSerializer<T> generateStateSerializer(Class<T> clazz, Map<String, Type> fieldTypes, DynamicClassLoader classLoader) {
    AccumulatorStateMetadata metadata = getMetadataAnnotation(clazz);
    if (metadata != null && metadata.stateSerializerClass() != void.class) {
        try {
            return (AccumulatorStateSerializer<T>) metadata.stateSerializerClass().getConstructor().newInstance();
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
    ClassDefinition definition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName(clazz.getSimpleName() + "Serializer"), type(Object.class), type(AccumulatorStateSerializer.class));
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    // Generate constructor
    definition.declareDefaultConstructor(a(PUBLIC));
    List<StateField> fields = enumerateFields(clazz, fieldTypes);
    generateGetSerializedType(definition, fields, callSiteBinder);
    generateSerialize(definition, callSiteBinder, clazz, fields);
    generateDeserialize(definition, callSiteBinder, clazz, fields);
    Class<?> serializerClass = defineClass(definition, AccumulatorStateSerializer.class, callSiteBinder.getBindings(), classLoader);
    try {
        return (AccumulatorStateSerializer<T>) serializerClass.getConstructor().newInstance();
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
Also used : AccumulatorStateMetadata(io.prestosql.spi.function.AccumulatorStateMetadata) AccumulatorStateSerializer(io.prestosql.spi.function.AccumulatorStateSerializer) ClassDefinition(io.airlift.bytecode.ClassDefinition) InvocationTargetException(java.lang.reflect.InvocationTargetException) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder)

Aggregations

ClassDefinition (io.airlift.bytecode.ClassDefinition)12 CallSiteBinder (io.prestosql.sql.gen.CallSiteBinder)12 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)9 MethodDefinition (io.airlift.bytecode.MethodDefinition)9 Parameter (io.airlift.bytecode.Parameter)9 Scope (io.airlift.bytecode.Scope)9 Variable (io.airlift.bytecode.Variable)9 IfStatement (io.airlift.bytecode.control.IfStatement)8 Block (io.prestosql.spi.block.Block)7 Signature.typeVariable (io.prestosql.spi.function.Signature.typeVariable)6 Type (io.prestosql.spi.type.Type)6 BlockBuilder (io.prestosql.spi.block.BlockBuilder)5 ImmutableList (com.google.common.collect.ImmutableList)4 BytecodeNode (io.airlift.bytecode.BytecodeNode)4 ForLoop (io.airlift.bytecode.control.ForLoop)4 VariableInstruction.incrementVariable (io.airlift.bytecode.instruction.VariableInstruction.incrementVariable)4 SqlTypeBytecodeExpression.constantType (io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 DynamicClassLoader (io.airlift.bytecode.DynamicClassLoader)3 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)3