Search in sources :

Example 6 with LambdaDefinitionExpression

use of io.trino.sql.relational.LambdaDefinitionExpression in project trino by trinodb.

the class PageFunctionCompiler method defineFilterClass.

private ClassDefinition defineFilterClass(RowExpression filter, InputChannels inputChannels, CallSiteBinder callSiteBinder, Optional<String> classNameSuffix) {
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), generateFilterClassName(classNameSuffix), type(Object.class), type(PageFilter.class));
    CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder);
    Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, filter);
    generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, compiledLambdaMap, filter);
    FieldDefinition selectedPositions = classDefinition.declareField(a(PRIVATE), "selectedPositions", boolean[].class);
    generatePageFilterMethod(classDefinition, selectedPositions);
    // isDeterministic
    classDefinition.declareMethod(a(PUBLIC), "isDeterministic", type(boolean.class)).getBody().append(constantBoolean(isDeterministic(filter))).retBoolean();
    // getInputChannels
    classDefinition.declareMethod(a(PUBLIC), "getInputChannels", type(InputChannels.class)).getBody().append(invoke(callSiteBinder.bind(inputChannels, InputChannels.class), "getInputChannels")).retObject();
    // toString
    String toStringResult = toStringHelper(classDefinition.getType().getJavaClassName()).add("filter", filter).toString();
    classDefinition.declareMethod(a(PUBLIC), "toString", type(String.class)).getBody().append(invoke(callSiteBinder.bind(toStringResult, String.class), "toString")).retObject();
    // constructor
    generateConstructor(classDefinition, cachedInstanceBinder, method -> {
        Variable thisVariable = method.getScope().getThis();
        method.getBody().append(thisVariable.setField(selectedPositions, newArray(type(boolean[].class), 0)));
    });
    return classDefinition;
}
Also used : CompiledLambda(io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda) Variable(io.airlift.bytecode.Variable) FieldDefinition(io.airlift.bytecode.FieldDefinition) PageFilter(io.trino.operator.project.PageFilter) InputChannels(io.trino.operator.project.InputChannels) ClassDefinition(io.airlift.bytecode.ClassDefinition) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression)

Example 7 with LambdaDefinitionExpression

use of io.trino.sql.relational.LambdaDefinitionExpression in project trino by trinodb.

the class CursorProcessorCompiler method generateMethodsForLambda.

private Map<LambdaDefinitionExpression, CompiledLambda> generateMethodsForLambda(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression projection, String methodPrefix) {
    Set<LambdaDefinitionExpression> lambdaExpressions = ImmutableSet.copyOf(extractLambdaExpressions(projection));
    ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder();
    int counter = 0;
    for (LambdaDefinitionExpression lambdaExpression : lambdaExpressions) {
        String methodName = methodPrefix + "_lambda_" + counter;
        CompiledLambda compiledLambda = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, methodName, containerClassDefinition, compiledLambdaMap.buildOrThrow(), callSiteBinder, cachedInstanceBinder, functionManager);
        compiledLambdaMap.put(lambdaExpression, compiledLambda);
        counter++;
    }
    return compiledLambdaMap.buildOrThrow();
}
Also used : CompiledLambda(io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda) ImmutableMap(com.google.common.collect.ImmutableMap) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression)

Example 8 with LambdaDefinitionExpression

use of io.trino.sql.relational.LambdaDefinitionExpression in project trino by trinodb.

the class JoinFilterFunctionCompiler method generateMethodsForLambda.

private Map<LambdaDefinitionExpression, CompiledLambda> generateMethodsForLambda(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression filter) {
    Set<LambdaDefinitionExpression> lambdaExpressions = ImmutableSet.copyOf(extractLambdaExpressions(filter));
    ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder();
    int counter = 0;
    for (LambdaDefinitionExpression lambdaExpression : lambdaExpressions) {
        CompiledLambda compiledLambda = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, "lambda_" + counter, containerClassDefinition, compiledLambdaMap.buildOrThrow(), callSiteBinder, cachedInstanceBinder, functionManager);
        compiledLambdaMap.put(lambdaExpression, compiledLambda);
        counter++;
    }
    return compiledLambdaMap.buildOrThrow();
}
Also used : CompiledLambda(io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda) ImmutableMap(com.google.common.collect.ImmutableMap) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression)

Example 9 with LambdaDefinitionExpression

use of io.trino.sql.relational.LambdaDefinitionExpression in project trino by trinodb.

the class JoinFilterFunctionCompiler method generateMethods.

private void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, int leftBlocksSize) {
    CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder);
    FieldDefinition sessionField = classDefinition.declareField(a(PRIVATE, FINAL), "session", ConnectorSession.class);
    Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, filter);
    generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, compiledLambdaMap, filter, leftBlocksSize, sessionField);
    generateConstructor(classDefinition, sessionField, cachedInstanceBinder);
}
Also used : CompiledLambda(io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda) FieldDefinition(io.airlift.bytecode.FieldDefinition) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression)

Example 10 with LambdaDefinitionExpression

use of io.trino.sql.relational.LambdaDefinitionExpression in project trino by trinodb.

the class LambdaBytecodeGenerator method generateMethodsForLambda.

public static Map<LambdaDefinitionExpression, CompiledLambda> generateMethodsForLambda(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression expression, FunctionManager functionManager) {
    Set<LambdaDefinitionExpression> lambdaExpressions = ImmutableSet.copyOf(extractLambdaExpressions(expression));
    ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder();
    int counter = 0;
    for (LambdaDefinitionExpression lambdaExpression : lambdaExpressions) {
        CompiledLambda compiledLambda = preGenerateLambdaExpression(lambdaExpression, "lambda_" + counter, containerClassDefinition, compiledLambdaMap.buildOrThrow(), callSiteBinder, cachedInstanceBinder, functionManager);
        compiledLambdaMap.put(lambdaExpression, compiledLambda);
        counter++;
    }
    return compiledLambdaMap.buildOrThrow();
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression)

Aggregations

LambdaDefinitionExpression (io.trino.sql.relational.LambdaDefinitionExpression)11 CompiledLambda (io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda)7 Variable (io.airlift.bytecode.Variable)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)4 FieldDefinition (io.airlift.bytecode.FieldDefinition)4 ClassDefinition (io.airlift.bytecode.ClassDefinition)3 MethodDefinition (io.airlift.bytecode.MethodDefinition)3 Parameter (io.airlift.bytecode.Parameter)3 Scope (io.airlift.bytecode.Scope)3 CallExpression (io.trino.sql.relational.CallExpression)2 ConstantExpression (io.trino.sql.relational.ConstantExpression)2 InputReferenceExpression (io.trino.sql.relational.InputReferenceExpression)2 RowExpressionVisitor (io.trino.sql.relational.RowExpressionVisitor)2 SpecialForm (io.trino.sql.relational.SpecialForm)2 VariableReferenceExpression (io.trino.sql.relational.VariableReferenceExpression)2 IfStatement (io.airlift.bytecode.control.IfStatement)1 Slice (io.airlift.slice.Slice)1 Work (io.trino.operator.Work)1 InputChannels (io.trino.operator.project.InputChannels)1