Search in sources :

Example 1 with InputChannels

use of io.trino.operator.project.InputChannels 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)

Aggregations

ClassDefinition (io.airlift.bytecode.ClassDefinition)1 FieldDefinition (io.airlift.bytecode.FieldDefinition)1 Variable (io.airlift.bytecode.Variable)1 InputChannels (io.trino.operator.project.InputChannels)1 PageFilter (io.trino.operator.project.PageFilter)1 CompiledLambda (io.trino.sql.gen.LambdaBytecodeGenerator.CompiledLambda)1 LambdaDefinitionExpression (io.trino.sql.relational.LambdaDefinitionExpression)1