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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations