Search in sources :

Example 31 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class JoinCompiler method generatePositionNotDistinctFromRowWithPageMethod.

private void generatePositionNotDistinctFromRowWithPageMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields) {
    Parameter leftBlockIndex = arg("leftBlockIndex", int.class);
    Parameter leftBlockPosition = arg("leftBlockPosition", int.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter page = arg("page", Page.class);
    Parameter rightChannels = arg("rightChannels", int[].class);
    MethodDefinition positionNotDistinctFromRowMethod = classDefinition.declareMethod(a(PUBLIC), "positionNotDistinctFromRow", type(boolean.class), leftBlockIndex, leftBlockPosition, rightPosition, page, rightChannels);
    Variable thisVariable = positionNotDistinctFromRowMethod.getThis();
    Scope scope = positionNotDistinctFromRowMethod.getScope();
    BytecodeBlock body = positionNotDistinctFromRowMethod.getBody();
    scope.declareVariable("wasNull", body, constantFalse());
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        BytecodeExpression leftBlock = thisVariable.getField(joinChannelFields.get(index)).invoke("get", Object.class, leftBlockIndex).cast(Block.class);
        BytecodeExpression rightBlock = page.invoke("getBlock", Block.class, rightChannels.getElement(index));
        Type type = joinChannelTypes.get(index);
        body.append(new IfStatement().condition(typeDistinctFrom(callSiteBinder, type, leftBlock, leftBlockPosition, rightBlock, rightPosition)).ifTrue(constantFalse().ret()));
    }
    body.append(constantTrue().ret());
}
Also used : IfStatement(io.airlift.bytecode.control.IfStatement) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) Variable(io.airlift.bytecode.Variable) Scope(io.airlift.bytecode.Scope) MethodDefinition(io.airlift.bytecode.MethodDefinition) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 32 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class JoinCompiler method internalCompileHashStrategy.

private Class<? extends PagesHashStrategy> internalCompileHashStrategy(List<Type> types, List<Integer> outputChannels, List<Integer> joinChannels, Optional<Integer> sortChannel) {
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("PagesHashStrategy"), type(Object.class), type(PagesHashStrategy.class));
    FieldDefinition instanceSizeField = generateInstanceSize(classDefinition);
    FieldDefinition sizeField = classDefinition.declareField(a(PRIVATE, FINAL), "size", type(long.class));
    List<FieldDefinition> channelFields = new ArrayList<>();
    for (int i = 0; i < types.size(); i++) {
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "channel_" + i, type(List.class, Block.class));
        channelFields.add(channelField);
    }
    List<Type> joinChannelTypes = new ArrayList<>();
    List<FieldDefinition> joinChannelFields = new ArrayList<>();
    for (int i = 0; i < joinChannels.size(); i++) {
        joinChannelTypes.add(types.get(joinChannels.get(i)));
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "joinChannel_" + i, type(List.class, Block.class));
        joinChannelFields.add(channelField);
    }
    FieldDefinition hashChannelField = classDefinition.declareField(a(PRIVATE, FINAL), "hashChannel", type(List.class, Block.class));
    generateConstructor(classDefinition, joinChannels, sizeField, instanceSizeField, channelFields, joinChannelFields, hashChannelField);
    generateGetChannelCountMethod(classDefinition, outputChannels.size());
    generateGetSizeInBytesMethod(classDefinition, sizeField);
    generateAppendToMethod(classDefinition, callSiteBinder, types, outputChannels, channelFields);
    generateHashPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, hashChannelField);
    generateHashRowMethod(classDefinition, callSiteBinder, joinChannelTypes);
    generateRowEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes);
    generateRowNotDistinctFromRowMethod(classDefinition, callSiteBinder, joinChannelTypes);
    generatePositionEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, true);
    generatePositionEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, false);
    generatePositionNotDistinctFromRowMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields);
    generatePositionNotDistinctFromRowWithPageMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields);
    generatePositionEqualsPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, true);
    generatePositionEqualsPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, false);
    generatePositionNotDistinctFromPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields);
    generateIsPositionNull(classDefinition, joinChannelFields);
    generateCompareSortChannelPositionsMethod(classDefinition, callSiteBinder, types, channelFields, sortChannel);
    generateIsSortChannelPositionNull(classDefinition, channelFields, sortChannel);
    return defineClass(classDefinition, PagesHashStrategy.class, callSiteBinder.getBindings(), getClass().getClassLoader());
}
Also used : SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) PagesHashStrategy(io.trino.operator.PagesHashStrategy) FieldDefinition(io.airlift.bytecode.FieldDefinition) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Block(io.trino.spi.block.Block) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ClassDefinition(io.airlift.bytecode.ClassDefinition)

Example 33 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class JoinCompiler method generateRowEqualsRowMethod.

private void generateRowEqualsRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) {
    Parameter leftPosition = arg("leftPosition", int.class);
    Parameter leftPage = arg("leftPage", Page.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    MethodDefinition rowEqualsRowMethod = classDefinition.declareMethod(a(PUBLIC), "rowEqualsRow", type(boolean.class), leftPosition, leftPage, rightPosition, rightPage);
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        Type type = joinChannelTypes.get(index);
        BytecodeExpression leftBlock = leftPage.invoke("getBlock", Block.class, constantInt(index));
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index));
        LabelNode checkNextField = new LabelNode("checkNextField");
        rowEqualsRowMethod.getBody().append(typeEquals(callSiteBinder, type, leftBlock, leftPosition, rightBlock, rightPosition)).ifTrueGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    rowEqualsRowMethod.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 34 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class JoinCompiler method generateRowNotDistinctFromRowMethod.

private void generateRowNotDistinctFromRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) {
    Parameter leftPosition = arg("leftPosition", int.class);
    Parameter leftPage = arg("leftPage", Page.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    MethodDefinition rowNotDistinctFromRowMethod = classDefinition.declareMethod(a(PUBLIC), "rowNotDistinctFromRow", type(boolean.class), leftPosition, leftPage, rightPosition, rightPage);
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        Type type = joinChannelTypes.get(index);
        BytecodeExpression leftBlock = leftPage.invoke("getBlock", Block.class, constantInt(index));
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index));
        LabelNode checkNextField = new LabelNode("checkNextField");
        rowNotDistinctFromRowMethod.getBody().append(typeDistinctFrom(callSiteBinder, type, leftBlock, leftPosition, rightBlock, rightPosition)).ifFalseGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    rowNotDistinctFromRowMethod.getBody().push(true).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 35 with Type

use of io.trino.spi.type.Type in project trino by trinodb.

the class JoinCompiler method generateHashRowMethod.

private void generateHashRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) {
    Parameter position = arg("position", int.class);
    Parameter page = arg("blocks", Page.class);
    MethodDefinition hashRowMethod = classDefinition.declareMethod(a(PUBLIC), "hashRow", type(long.class), position, page);
    Variable resultVariable = hashRowMethod.getScope().declareVariable(long.class, "result");
    hashRowMethod.getBody().push(0L).putVariable(resultVariable);
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        Type type = joinChannelTypes.get(index);
        BytecodeExpression block = page.invoke("getBlock", Block.class, constantInt(index));
        hashRowMethod.getBody().getVariable(resultVariable).push(31L).append(OpCode.LMUL).append(typeHashCode(callSiteBinder, type, block, position)).append(OpCode.LADD).putVariable(resultVariable);
    }
    hashRowMethod.getBody().getVariable(resultVariable).retLong();
}
Also used : SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) BigintType(io.trino.spi.type.BigintType) Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Aggregations

Type (io.trino.spi.type.Type)688 Test (org.testng.annotations.Test)266 ArrayType (io.trino.spi.type.ArrayType)218 ImmutableList (com.google.common.collect.ImmutableList)191 RowType (io.trino.spi.type.RowType)177 List (java.util.List)155 VarcharType (io.trino.spi.type.VarcharType)134 Page (io.trino.spi.Page)126 ArrayList (java.util.ArrayList)126 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)114 Block (io.trino.spi.block.Block)110 MapType (io.trino.spi.type.MapType)107 DecimalType (io.trino.spi.type.DecimalType)102 TrinoException (io.trino.spi.TrinoException)98 Optional (java.util.Optional)98 Map (java.util.Map)97 ImmutableMap (com.google.common.collect.ImmutableMap)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)92 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)86 BlockBuilder (io.trino.spi.block.BlockBuilder)72