Search in sources :

Example 76 with Parameter

use of com.facebook.presto.bytecode.Parameter in project presto by prestodb.

the class TestArrayBytecodeExpressions method defineSetAndGetMethod.

private static MethodDefinition defineSetAndGetMethod(Class<?> aClass) {
    Parameter arr = arg("arr", type(aClass));
    Parameter index = arg("index", type(int.class));
    Class<?> componentType = aClass.getComponentType();
    Parameter value = arg("value", type(componentType));
    MethodDefinition methodDefinition = classDefinition.declareMethod(a(PUBLIC, STATIC), "setAndGetMethod_" + componentType.getSimpleName(), type(componentType), arr, index, value);
    methodDefinition.getBody().append(arr.setElement(index, value)).append(arr.getElement(index).ret());
    return methodDefinition;
}
Also used : MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter)

Example 77 with Parameter

use of com.facebook.presto.bytecode.Parameter in project presto by prestodb.

the class PageFunctionCompiler method generatePageFilterMethod.

private static MethodDefinition generatePageFilterMethod(ClassDefinition classDefinition, FieldDefinition selectedPositionsField) {
    Parameter properties = arg("properties", SqlFunctionProperties.class);
    Parameter page = arg("page", Page.class);
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "filter", type(SelectedPositions.class), ImmutableList.<Parameter>builder().add(properties).add(page).build());
    Scope scope = method.getScope();
    Variable thisVariable = method.getThis();
    BytecodeBlock body = method.getBody();
    Variable positionCount = scope.declareVariable("positionCount", body, page.invoke("getPositionCount", int.class));
    body.append(new IfStatement("grow selectedPositions if necessary").condition(lessThan(thisVariable.getField(selectedPositionsField).length(), positionCount)).ifTrue(thisVariable.setField(selectedPositionsField, newArray(type(boolean[].class), positionCount))));
    Variable selectedPositions = scope.declareVariable("selectedPositions", body, thisVariable.getField(selectedPositionsField));
    Variable position = scope.declareVariable(int.class, "position");
    body.append(new ForLoop().initialize(position.set(constantInt(0))).condition(lessThan(position, positionCount)).update(position.increment()).body(selectedPositions.setElement(position, thisVariable.invoke("filter", boolean.class, properties, page, position))));
    body.append(invokeStatic(PageFilter.class, "positionsArrayToSelectedPositions", SelectedPositions.class, selectedPositions, positionCount).ret());
    return method;
}
Also used : IfStatement(com.facebook.presto.bytecode.control.IfStatement) Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) ForLoop(com.facebook.presto.bytecode.control.ForLoop) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) SelectedPositions(com.facebook.presto.operator.project.SelectedPositions) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Parameter(com.facebook.presto.bytecode.Parameter)

Example 78 with Parameter

use of com.facebook.presto.bytecode.Parameter in project presto by prestodb.

the class PageFunctionCompiler method generateFilterMethod.

private MethodDefinition generateFilterMethod(ClassDefinition classDefinition, RowExpressionCompiler compiler, RowExpression filter, Map<VariableReferenceExpression, CommonSubExpressionFields> cseFields) {
    Parameter properties = arg("properties", SqlFunctionProperties.class);
    Parameter page = arg("page", Page.class);
    Parameter position = arg("position", int.class);
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "filter", type(boolean.class), ImmutableList.<Parameter>builder().add(properties).add(page).add(position).build());
    method.comment("Filter: %s", filter.toString());
    Scope scope = method.getScope();
    BytecodeBlock body = method.getBody();
    Variable thisVariable = scope.getThis();
    declareBlockVariables(ImmutableList.of(filter), page, scope, body);
    cseFields.values().forEach(fields -> body.append(thisVariable.setField(fields.getEvaluatedField(), constantBoolean(false))));
    Variable wasNullVariable = scope.declareVariable("wasNull", body, constantFalse());
    Variable result = scope.declareVariable(boolean.class, "result");
    body.append(compiler.compile(filter, scope, Optional.empty())).putVariable(result).append(and(not(wasNullVariable), result).ret());
    return method;
}
Also used : Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Parameter(com.facebook.presto.bytecode.Parameter)

Example 79 with Parameter

use of com.facebook.presto.bytecode.Parameter in project presto by prestodb.

the class PageFunctionCompiler method generateEvaluateMethod.

private MethodDefinition generateEvaluateMethod(ClassDefinition classDefinition, RowExpressionCompiler compiler, List<RowExpression> projections, FieldDefinition blockBuilders, Map<VariableReferenceExpression, CommonSubExpressionFields> cseFields) {
    Parameter properties = arg("properties", SqlFunctionProperties.class);
    Parameter page = arg("page", Page.class);
    Parameter position = arg("position", int.class);
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "evaluate", type(void.class), ImmutableList.<Parameter>builder().add(properties).add(page).add(position).build());
    method.comment("Projections: %s", Joiner.on(", ").join(projections));
    Scope scope = method.getScope();
    BytecodeBlock body = method.getBody();
    Variable thisVariable = method.getThis();
    declareBlockVariables(projections, page, scope, body);
    Variable wasNull = scope.declareVariable("wasNull", body, constantFalse());
    cseFields.values().forEach(fields -> body.append(thisVariable.setField(fields.getEvaluatedField(), constantBoolean(false))));
    Variable outputBlockVariable = scope.createTempVariable(BlockBuilder.class);
    for (int i = 0; i < projections.size(); i++) {
        body.append(outputBlockVariable.set(thisVariable.getField(blockBuilders).invoke("get", Object.class, constantInt(i)))).append(compiler.compile(projections.get(i), scope, Optional.of(outputBlockVariable))).append(constantBoolean(false)).putVariable(wasNull);
    }
    body.ret();
    return method;
}
Also used : Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Parameter(com.facebook.presto.bytecode.Parameter)

Example 80 with Parameter

use of com.facebook.presto.bytecode.Parameter in project presto by prestodb.

the class RowExpressionPredicateCompiler method generatePredicateMethod.

private MethodDefinition generatePredicateMethod(SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, ClassDefinition classDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, RowExpression predicate) {
    Map<LambdaDefinitionExpression, LambdaBytecodeGenerator.CompiledLambda> compiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, predicate, metadata, sqlFunctionProperties, sessionFunctions);
    Parameter properties = arg("properties", SqlFunctionProperties.class);
    Parameter page = arg("page", Page.class);
    Parameter position = arg("position", int.class);
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "evaluate", type(boolean.class), ImmutableList.<Parameter>builder().add(properties).add(page).add(position).build());
    method.comment("Predicate: %s", predicate.toString());
    Scope scope = method.getScope();
    BytecodeBlock body = method.getBody();
    declareBlockVariables(predicate, page, scope, body);
    Variable wasNullVariable = scope.declareVariable("wasNull", body, constantFalse());
    RowExpressionCompiler compiler = new RowExpressionCompiler(classDefinition, callSiteBinder, cachedInstanceBinder, fieldReferenceCompiler(callSiteBinder), metadata, sqlFunctionProperties, sessionFunctions, compiledLambdaMap);
    Variable result = scope.declareVariable(boolean.class, "result");
    body.append(compiler.compile(predicate, scope, Optional.empty())).putVariable(result).append(and(not(wasNullVariable), result).ret());
    return method;
}
Also used : Variable(com.facebook.presto.bytecode.Variable) Scope(com.facebook.presto.bytecode.Scope) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Parameter(com.facebook.presto.bytecode.Parameter) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression)

Aggregations

Parameter (com.facebook.presto.bytecode.Parameter)94 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)91 Variable (com.facebook.presto.bytecode.Variable)73 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)70 Scope (com.facebook.presto.bytecode.Scope)52 IfStatement (com.facebook.presto.bytecode.control.IfStatement)42 BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)36 ImmutableList (com.google.common.collect.ImmutableList)24 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)21 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)17 ForLoop (com.facebook.presto.bytecode.control.ForLoop)15 Block (com.facebook.presto.spi.block.Block)15 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)13 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)13 List (java.util.List)13 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)12 Block (com.facebook.presto.common.block.Block)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11