Search in sources :

Example 31 with BytecodeExpression

use of com.facebook.presto.bytecode.expression.BytecodeExpression in project presto by prestodb.

the class AccumulatorCompiler method generateSetGroupIdFromGroupIdsBlock.

private static void generateSetGroupIdFromGroupIdsBlock(Scope scope, FieldDefinition stateField, BytecodeBlock block) {
    Variable groupIdsBlock = scope.getVariable("groupIdsBlock");
    Variable position = scope.getVariable("position");
    BytecodeExpression state = scope.getThis().getField(stateField);
    block.append(state.invoke("setGroupId", void.class, groupIdsBlock.invoke("getGroupId", long.class, position)));
}
Also used : Variable(com.facebook.presto.bytecode.Variable) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 32 with BytecodeExpression

use of com.facebook.presto.bytecode.expression.BytecodeExpression in project presto by prestodb.

the class AccumulatorCompiler method generateEvaluateIntermediate.

private static void generateEvaluateIntermediate(ClassDefinition definition, FieldDefinition stateSerializerField, FieldDefinition stateField) {
    Parameter out = arg("out", BlockBuilder.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC), "evaluateIntermediate", type(void.class), out);
    Variable thisVariable = method.getThis();
    BytecodeExpression stateSerializer = thisVariable.getField(stateSerializerField);
    BytecodeExpression state = thisVariable.getField(stateField);
    method.getBody().append(stateSerializer.invoke("serialize", void.class, state.cast(Object.class), out)).ret();
}
Also used : Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 33 with BytecodeExpression

use of com.facebook.presto.bytecode.expression.BytecodeExpression in project presto by prestodb.

the class AccumulatorCompiler method generateGroupedEvaluateIntermediate.

private static void generateGroupedEvaluateIntermediate(ClassDefinition definition, FieldDefinition stateSerializerField, FieldDefinition stateField) {
    Parameter groupId = arg("groupId", int.class);
    Parameter out = arg("out", BlockBuilder.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC), "evaluateIntermediate", type(void.class), groupId, out);
    Variable thisVariable = method.getThis();
    BytecodeExpression state = thisVariable.getField(stateField);
    BytecodeExpression stateSerializer = thisVariable.getField(stateSerializerField);
    method.getBody().append(state.invoke("setGroupId", void.class, groupId.cast(long.class))).append(stateSerializer.invoke("serialize", void.class, state.cast(Object.class), out)).ret();
}
Also used : Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 34 with BytecodeExpression

use of com.facebook.presto.bytecode.expression.BytecodeExpression in project presto by prestodb.

the class AccumulatorCompiler method generateGetEstimatedSize.

private static void generateGetEstimatedSize(ClassDefinition definition, FieldDefinition stateField) {
    MethodDefinition method = definition.declareMethod(a(PUBLIC), "getEstimatedSize", type(long.class));
    BytecodeExpression state = method.getThis().getField(stateField);
    method.getBody().append(state.invoke("getEstimatedSize", long.class).ret());
}
Also used : MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 35 with BytecodeExpression

use of com.facebook.presto.bytecode.expression.BytecodeExpression in project presto by prestodb.

the class AbstractMinMaxBy method generateOutputMethod.

private void generateOutputMethod(ClassDefinition definition, CallSiteBinder binder, Type valueType, Class<?> stateClass) {
    Parameter state = arg("state", stateClass);
    Parameter out = arg("out", BlockBuilder.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC, STATIC), "output", type(void.class), state, out);
    IfStatement ifStatement = new IfStatement().condition(or(state.invoke("isFirstNull", boolean.class), state.invoke("isSecondNull", boolean.class))).ifTrue(new BytecodeBlock().append(out.invoke("appendNull", BlockBuilder.class)).pop());
    SqlTypeBytecodeExpression valueSqlType = constantType(binder, valueType);
    BytecodeExpression getValueExpression;
    if (valueType.getJavaType().isPrimitive()) {
        getValueExpression = state.invoke("getSecond", valueType.getJavaType());
    } else {
        getValueExpression = valueSqlType.getValue(state.invoke("getSecondBlock", Block.class), state.invoke("getSecondPosition", int.class));
    }
    ifStatement.ifFalse(valueSqlType.writeValue(out, getValueExpression));
    method.getBody().append(ifStatement).ret();
}
Also used : IfStatement(com.facebook.presto.bytecode.control.IfStatement) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) Signature.orderableTypeParameter(com.facebook.presto.spi.function.Signature.orderableTypeParameter) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression) SqlTypeBytecodeExpression(com.facebook.presto.sql.gen.SqlTypeBytecodeExpression) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlTypeBytecodeExpression(com.facebook.presto.sql.gen.SqlTypeBytecodeExpression)

Aggregations

BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)49 Variable (com.facebook.presto.bytecode.Variable)39 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)37 Parameter (com.facebook.presto.bytecode.Parameter)35 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)31 IfStatement (com.facebook.presto.bytecode.control.IfStatement)19 Scope (com.facebook.presto.bytecode.Scope)13 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)9 SqlTypeBytecodeExpression.constantType (com.facebook.presto.sql.gen.SqlTypeBytecodeExpression.constantType)9 ImmutableList (com.google.common.collect.ImmutableList)8 Type (com.facebook.presto.common.type.Type)7 ArrayList (java.util.ArrayList)7 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)6 Block (com.facebook.presto.common.block.Block)6 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)6 Block (com.facebook.presto.spi.block.Block)6 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)5 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)5 ForLoop (com.facebook.presto.bytecode.control.ForLoop)5 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)5