Search in sources :

Example 26 with DynamicClassLoader

use of io.airlift.bytecode.DynamicClassLoader in project hetu-core by openlookeng.

the class JoinCompiler method internalCompileLookupSourceFactory.

private LookupSourceSupplierFactory internalCompileLookupSourceFactory(List<Type> types, List<Integer> outputChannels, List<Integer> joinChannels, Optional<Integer> sortChannel) {
    Class<? extends PagesHashStrategy> pagesHashStrategyClass = internalCompileHashStrategy(types, outputChannels, joinChannels, sortChannel);
    Class<? extends LookupSourceSupplier> joinHashSupplierClass = IsolatedClass.isolateClass(new DynamicClassLoader(getClass().getClassLoader()), LookupSourceSupplier.class, JoinHashSupplier.class, JoinHash.class, PagesHash.class);
    return new LookupSourceSupplierFactory(joinHashSupplierClass, new PagesHashStrategyFactory(pagesHashStrategyClass));
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader)

Example 27 with DynamicClassLoader

use of io.airlift.bytecode.DynamicClassLoader in project hetu-core by openlookeng.

the class Bootstrap method bootstrap.

public static CallSite bootstrap(MethodHandles.Lookup callerLookup, String name, MethodType type, long bindingId) {
    ClassLoader classLoader = callerLookup.lookupClass().getClassLoader();
    checkArgument(classLoader instanceof DynamicClassLoader, "Expected %s's classloader to be of type %s", callerLookup.lookupClass().getName(), DynamicClassLoader.class.getName());
    DynamicClassLoader dynamicClassLoader = (DynamicClassLoader) classLoader;
    MethodHandle target = dynamicClassLoader.getCallSiteBindings().get(bindingId);
    checkArgument(target != null, "Binding %s for function %s%s not found", bindingId, name, type.parameterList());
    return new ConstantCallSite(target);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) ConstantCallSite(java.lang.invoke.ConstantCallSite) MethodHandle(java.lang.invoke.MethodHandle)

Example 28 with DynamicClassLoader

use of io.airlift.bytecode.DynamicClassLoader in project hetu-core by openlookeng.

the class ArbitraryAggregationFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(ArbitraryAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface;
    AccumulatorStateSerializer<?> stateSerializer;
    if (type.getJavaType() == long.class) {
        stateInterface = NullableLongState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = LONG_INPUT_FUNCTION;
        combineFunction = LONG_COMBINE_FUNCTION;
        outputFunction = LONG_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == double.class) {
        stateInterface = NullableDoubleState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = DOUBLE_INPUT_FUNCTION;
        combineFunction = DOUBLE_COMBINE_FUNCTION;
        outputFunction = DOUBLE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == boolean.class) {
        stateInterface = NullableBooleanState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = BOOLEAN_INPUT_FUNCTION;
        combineFunction = BOOLEAN_COMBINE_FUNCTION;
        outputFunction = BOOLEAN_OUTPUT_FUNCTION;
    } else {
        // native container type is Slice or Block
        stateInterface = BlockPositionState.class;
        stateSerializer = new BlockPositionStateSerializer(type);
        inputFunction = BLOCK_POSITION_INPUT_FUNCTION;
        combineFunction = BLOCK_POSITION_COMBINE_FUNCTION;
        outputFunction = BLOCK_POSITION_OUTPUT_FUNCTION;
    }
    inputFunction = inputFunction.bindTo(type);
    Type intermediateType = stateSerializer.getSerializedType();
    List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction.bindTo(type), ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, StateCompiler.generateStateFactory(stateInterface, classLoader))), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), type, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BlockPositionStateSerializer(io.prestosql.operator.aggregation.state.BlockPositionStateSerializer) ParameterMetadata(io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata) Type(io.prestosql.spi.type.Type) NullableDoubleState(io.prestosql.operator.aggregation.state.NullableDoubleState) MethodHandle(java.lang.invoke.MethodHandle)

Example 29 with DynamicClassLoader

use of io.airlift.bytecode.DynamicClassLoader in project hetu-core by openlookeng.

the class MergeQuantileDigestFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type valueType, QuantileDigestType type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(MapAggregationFunction.class.getClassLoader());
    QuantileDigestStateSerializer stateSerializer = new QuantileDigestStateSerializer(valueType);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), ImmutableList.of(type.getTypeSignature())), createInputParameterMetadata(type), INPUT_FUNCTION.bindTo(type), COMBINE_FUNCTION, OUTPUT_FUNCTION.bindTo(stateSerializer), ImmutableList.of(new AccumulatorStateDescriptor(QuantileDigestState.class, stateSerializer, new QuantileDigestStateFactory())), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, ImmutableList.of(type), ImmutableList.of(intermediateType), type, true, true, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) QuantileDigestStateSerializer(io.prestosql.operator.aggregation.state.QuantileDigestStateSerializer) QuantileDigestType(io.prestosql.spi.type.QuantileDigestType) Type(io.prestosql.spi.type.Type) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) QuantileDigestStateFactory(io.prestosql.operator.aggregation.state.QuantileDigestStateFactory)

Example 30 with DynamicClassLoader

use of io.airlift.bytecode.DynamicClassLoader in project hetu-core by openlookeng.

the class MapUnionAggregation method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type keyType, Type valueType, MapType outputType) {
    DynamicClassLoader classLoader = new DynamicClassLoader(MapUnionAggregation.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(outputType);
    KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(outputType), INPUT_FUNCTION.bindTo(keyType).bindTo(valueType), COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor(KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
Also used : DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) MapType(io.prestosql.spi.type.MapType) Type(io.prestosql.spi.type.Type) KeyValuePairStateSerializer(io.prestosql.operator.aggregation.state.KeyValuePairStateSerializer) AccumulatorStateDescriptor(io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) KeyValuePairsStateFactory(io.prestosql.operator.aggregation.state.KeyValuePairsStateFactory)

Aggregations

DynamicClassLoader (io.airlift.bytecode.DynamicClassLoader)38 Type (io.prestosql.spi.type.Type)20 AccumulatorStateDescriptor (io.prestosql.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)19 MethodHandle (java.lang.invoke.MethodHandle)14 ClassDefinition (io.airlift.bytecode.ClassDefinition)11 ImmutableList (com.google.common.collect.ImmutableList)7 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)7 MethodDefinition (io.airlift.bytecode.MethodDefinition)7 Parameter (io.airlift.bytecode.Parameter)7 Variable (io.airlift.bytecode.Variable)7 ArrayType (io.prestosql.spi.type.ArrayType)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Scope (io.airlift.bytecode.Scope)5 AggregationMetadata (io.prestosql.operator.aggregation.AggregationMetadata)5 ParameterMetadata (io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata)5 GenericAccumulatorFactoryBinder (io.prestosql.operator.aggregation.GenericAccumulatorFactoryBinder)5 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)5 IfStatement (io.airlift.bytecode.control.IfStatement)4 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)4 CallSiteBinder (io.trino.sql.gen.CallSiteBinder)4