Search in sources :

Example 51 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class FunctionAssertions method getRetainedSizeOf.

private long getRetainedSizeOf(Object object) {
    if (object instanceof PageBuilder) {
        return ((PageBuilder) object).getRetainedSizeInBytes();
    }
    if (object instanceof Block) {
        return ((Block) object).getRetainedSizeInBytes();
    }
    Class<?> type = object.getClass();
    if (type.isArray()) {
        if (type == int[].class) {
            return sizeOf((int[]) object);
        }
        if (type == boolean[].class) {
            return sizeOf((boolean[]) object);
        }
        if (type == byte[].class) {
            return sizeOf((byte[]) object);
        }
        if (type == long[].class) {
            return sizeOf((long[]) object);
        }
        if (type == short[].class) {
            return sizeOf((short[]) object);
        }
        if (type == Block[].class) {
            Object[] objects = (Object[]) object;
            return Arrays.stream(objects).mapToLong(this::getRetainedSizeOf).sum();
        }
        throw new IllegalArgumentException(format("Unknown type encountered: %s", type));
    }
    long retainedSize = ClassLayout.parseClass(type).instanceSize();
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
        try {
            if (field.getType().isPrimitive() || Modifier.isStatic(field.getModifiers())) {
                continue;
            }
            field.setAccessible(true);
            retainedSize += getRetainedSizeOf(field.get(object));
        } catch (IllegalAccessException t) {
            throw new RuntimeException(t);
        }
    }
    return retainedSize;
}
Also used : Field(java.lang.reflect.Field) BlockAssertions.createShortDecimalsBlock(io.trino.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createDoublesBlock(io.trino.block.BlockAssertions.createDoublesBlock) BlockAssertions.createIntsBlock(io.trino.block.BlockAssertions.createIntsBlock) BlockAssertions.createRowBlock(io.trino.block.BlockAssertions.createRowBlock) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) BlockAssertions.createSlicesBlock(io.trino.block.BlockAssertions.createSlicesBlock) BlockAssertions.createTimestampsWithTimeZoneMillisBlock(io.trino.block.BlockAssertions.createTimestampsWithTimeZoneMillisBlock) Block(io.trino.spi.block.Block) BlockAssertions.createLongDecimalsBlock(io.trino.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) BlockAssertions.createBooleansBlock(io.trino.block.BlockAssertions.createBooleansBlock) PageBuilder(io.trino.spi.PageBuilder)

Example 52 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestJoinCompiler method testMultiChannel.

@Test(dataProvider = "hashEnabledValues")
public void testMultiChannel(boolean hashEnabled) {
    // compile a single channel hash strategy
    List<Type> types = ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR);
    List<Type> joinTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN);
    List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR);
    List<Integer> joinChannels = Ints.asList(1, 2, 3, 4);
    List<Integer> outputChannels = Ints.asList(1, 2, 3, 4, 0);
    // crate hash strategy with a single channel blocks -- make sure there is some overlap in values
    List<Block> extraChannel = ImmutableList.of(BlockAssertions.createStringSequenceBlock(10, 20), BlockAssertions.createStringSequenceBlock(20, 30), BlockAssertions.createStringSequenceBlock(15, 25));
    List<Block> varcharChannel = ImmutableList.of(BlockAssertions.createStringSequenceBlock(10, 20), BlockAssertions.createStringSequenceBlock(20, 30), BlockAssertions.createStringSequenceBlock(15, 25));
    List<Block> longChannel = ImmutableList.of(BlockAssertions.createLongSequenceBlock(10, 20), BlockAssertions.createLongSequenceBlock(20, 30), BlockAssertions.createLongSequenceBlock(15, 25));
    List<Block> doubleChannel = ImmutableList.of(BlockAssertions.createDoubleSequenceBlock(10, 20), BlockAssertions.createDoubleSequenceBlock(20, 30), BlockAssertions.createDoubleSequenceBlock(15, 25));
    List<Block> booleanChannel = ImmutableList.of(BlockAssertions.createBooleanSequenceBlock(10, 20), BlockAssertions.createBooleanSequenceBlock(20, 30), BlockAssertions.createBooleanSequenceBlock(15, 25));
    List<Block> extraUnusedChannel = ImmutableList.of(BlockAssertions.createBooleanSequenceBlock(10, 20), BlockAssertions.createBooleanSequenceBlock(20, 30), BlockAssertions.createBooleanSequenceBlock(15, 25));
    OptionalInt hashChannel = OptionalInt.empty();
    ImmutableList<List<Block>> channels = ImmutableList.of(extraChannel, varcharChannel, longChannel, doubleChannel, booleanChannel, extraUnusedChannel);
    List<Block> precomputedHash = ImmutableList.of();
    if (hashEnabled) {
        ImmutableList.Builder<Block> hashChannelBuilder = ImmutableList.builder();
        for (int i = 0; i < 3; i++) {
            hashChannelBuilder.add(TypeTestUtils.getHashBlock(joinTypes, varcharChannel.get(i), longChannel.get(i), doubleChannel.get(i), booleanChannel.get(i)));
        }
        hashChannel = OptionalInt.of(6);
        precomputedHash = hashChannelBuilder.build();
        channels = ImmutableList.of(extraChannel, varcharChannel, longChannel, doubleChannel, booleanChannel, extraUnusedChannel, precomputedHash);
        types = ImmutableList.of(VARCHAR, VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR, BIGINT);
        outputTypes = ImmutableList.of(VARCHAR, BIGINT, DOUBLE, BOOLEAN, VARCHAR, BIGINT);
        outputChannels = Ints.asList(1, 2, 3, 4, 0, 6);
    }
    PagesHashStrategyFactory pagesHashStrategyFactory = joinCompiler.compilePagesHashStrategyFactory(types, joinChannels, Optional.of(outputChannels));
    PagesHashStrategy hashStrategy = pagesHashStrategyFactory.createPagesHashStrategy(channels, hashChannel);
    // todo add tests for filter function
    PagesHashStrategy expectedHashStrategy = new SimplePagesHashStrategy(types, outputChannels, channels, joinChannels, hashChannel, Optional.empty(), blockTypeOperators);
    // verify channel count
    assertEquals(hashStrategy.getChannelCount(), outputChannels.size());
    // verify size
    int instanceSize = ClassLayout.parseClass(hashStrategy.getClass()).instanceSize();
    long sizeInBytes = instanceSize + channels.stream().flatMap(List::stream).mapToLong(Block::getRetainedSizeInBytes).sum();
    assertEquals(hashStrategy.getSizeInBytes(), sizeInBytes);
    // verify hashStrategy is consistent with equals and hash code from block
    for (int leftBlockIndex = 0; leftBlockIndex < varcharChannel.size(); leftBlockIndex++) {
        PageBuilder pageBuilder = new PageBuilder(outputTypes);
        Block[] leftBlocks = new Block[4];
        leftBlocks[0] = varcharChannel.get(leftBlockIndex);
        leftBlocks[1] = longChannel.get(leftBlockIndex);
        leftBlocks[2] = doubleChannel.get(leftBlockIndex);
        leftBlocks[3] = booleanChannel.get(leftBlockIndex);
        int leftPositionCount = varcharChannel.get(leftBlockIndex).getPositionCount();
        for (int leftBlockPosition = 0; leftBlockPosition < leftPositionCount; leftBlockPosition++) {
            // hash code of position must match block hash
            assertEquals(hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition), expectedHashStrategy.hashPosition(leftBlockIndex, leftBlockPosition));
            // position must be equal to itself
            assertTrue(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            assertTrue(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            assertTrue(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            // check equality of every position against every other position in the block
            for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                Block rightBlock = varcharChannel.get(rightBlockIndex);
                for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                    assertEquals(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedHashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                    assertEquals(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedHashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                    assertEquals(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedHashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition));
                }
            }
            // check equality of every position against every other position in the block cursor
            for (int rightBlockIndex = 0; rightBlockIndex < varcharChannel.size(); rightBlockIndex++) {
                Block[] rightBlocks = new Block[4];
                rightBlocks[0] = varcharChannel.get(rightBlockIndex);
                rightBlocks[1] = longChannel.get(rightBlockIndex);
                rightBlocks[2] = doubleChannel.get(rightBlockIndex);
                rightBlocks[3] = booleanChannel.get(rightBlockIndex);
                int rightPositionCount = varcharChannel.get(rightBlockIndex).getPositionCount();
                for (int rightPosition = 0; rightPosition < rightPositionCount; rightPosition++) {
                    boolean expected = expectedHashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks));
                    boolean expectedNotDistinct = expectedHashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks));
                    assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks)), expected);
                    assertEquals(hashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks)), expectedNotDistinct);
                    assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlocks), rightPosition, new Page(rightBlocks)), expected);
                    assertEquals(hashStrategy.rowNotDistinctFromRow(leftBlockPosition, new Page(leftBlocks), rightPosition, new Page(rightBlocks)), expectedNotDistinct);
                    assertEquals(hashStrategy.positionEqualsRowIgnoreNulls(leftBlockIndex, leftBlockPosition, rightPosition, new Page(rightBlocks)), expected);
                }
            }
            // write position to output block
            pageBuilder.declarePosition();
            hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
        }
        // verify output block matches
        Page page = pageBuilder.build();
        if (hashEnabled) {
            assertPageEquals(outputTypes, page, new Page(varcharChannel.get(leftBlockIndex), longChannel.get(leftBlockIndex), doubleChannel.get(leftBlockIndex), booleanChannel.get(leftBlockIndex), extraChannel.get(leftBlockIndex), precomputedHash.get(leftBlockIndex)));
        } else {
            assertPageEquals(outputTypes, page, new Page(varcharChannel.get(leftBlockIndex), longChannel.get(leftBlockIndex), doubleChannel.get(leftBlockIndex), booleanChannel.get(leftBlockIndex), extraChannel.get(leftBlockIndex)));
        }
    }
}
Also used : PagesHashStrategyFactory(io.trino.sql.gen.JoinCompiler.PagesHashStrategyFactory) ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) OptionalInt(java.util.OptionalInt) PageBuilder(io.trino.spi.PageBuilder) SimplePagesHashStrategy(io.trino.operator.SimplePagesHashStrategy) Type(io.trino.spi.type.Type) PagesHashStrategy(io.trino.operator.PagesHashStrategy) SimplePagesHashStrategy(io.trino.operator.SimplePagesHashStrategy) Block(io.trino.spi.block.Block) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 53 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestJoinCompiler method testSingleChannel.

@Test(dataProvider = "hashEnabledValues")
public void testSingleChannel(boolean hashEnabled) {
    List<Type> joinTypes = ImmutableList.of(VARCHAR);
    List<Integer> joinChannels = Ints.asList(0);
    // compile a single channel hash strategy
    PagesHashStrategyFactory pagesHashStrategyFactory = joinCompiler.compilePagesHashStrategyFactory(joinTypes, joinChannels);
    // create hash strategy with a single channel blocks -- make sure there is some overlap in values
    List<Block> channel = ImmutableList.of(BlockAssertions.createStringSequenceBlock(10, 20), BlockAssertions.createStringSequenceBlock(20, 30), BlockAssertions.createStringSequenceBlock(15, 25));
    OptionalInt hashChannel = OptionalInt.empty();
    List<List<Block>> channels = ImmutableList.of(channel);
    if (hashEnabled) {
        ImmutableList.Builder<Block> hashChannelBuilder = ImmutableList.builder();
        for (Block block : channel) {
            hashChannelBuilder.add(TypeTestUtils.getHashBlock(joinTypes, block));
        }
        hashChannel = OptionalInt.of(1);
        channels = ImmutableList.of(channel, hashChannelBuilder.build());
    }
    PagesHashStrategy hashStrategy = pagesHashStrategyFactory.createPagesHashStrategy(channels, hashChannel);
    // verify channel count
    assertEquals(hashStrategy.getChannelCount(), 1);
    BlockTypeOperators blockTypeOperators = new BlockTypeOperators();
    BlockPositionEqual equalOperator = blockTypeOperators.getEqualOperator(VARCHAR);
    BlockPositionIsDistinctFrom distinctFromOperator = blockTypeOperators.getDistinctFromOperator(VARCHAR);
    BlockPositionHashCode hashCodeOperator = blockTypeOperators.getHashCodeOperator(VARCHAR);
    // verify hashStrategy is consistent with equals and hash code from block
    for (int leftBlockIndex = 0; leftBlockIndex < channel.size(); leftBlockIndex++) {
        Block leftBlock = channel.get(leftBlockIndex);
        PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(VARCHAR));
        for (int leftBlockPosition = 0; leftBlockPosition < leftBlock.getPositionCount(); leftBlockPosition++) {
            // hash code of position must match block hash
            assertEquals(hashStrategy.hashPosition(leftBlockIndex, leftBlockPosition), hashCodeOperator.hashCodeNullSafe(leftBlock, leftBlockPosition));
            // position must be equal to itself
            assertTrue(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
            // check equality of every position against every other position in the block
            for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
                Block rightBlock = channel.get(rightBlockIndex);
                for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                    boolean expected = equalOperator.equalNullSafe(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
                    boolean expectedNotDistinct = !distinctFromOperator.isDistinctFrom(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
                    assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
                    assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.rowNotDistinctFromRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
                    assertEquals(hashStrategy.positionEqualsRowIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expected);
                    assertEquals(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expected);
                    assertEquals(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedNotDistinct);
                }
            }
            // check equality of every position against every other position in the block cursor
            for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
                Block rightBlock = channel.get(rightBlockIndex);
                for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
                    boolean expected = equalOperator.equalNullSafe(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
                    boolean expectedNotDistinct = !distinctFromOperator.isDistinctFrom(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
                    assertEquals(hashStrategy.positionEqualsRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
                    assertEquals(hashStrategy.rowEqualsRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.rowNotDistinctFromRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
                    assertEquals(hashStrategy.positionEqualsRowIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expected);
                    assertEquals(hashStrategy.positionEqualsPositionIgnoreNulls(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expected);
                    assertEquals(hashStrategy.positionEqualsPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expected);
                    assertEquals(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedNotDistinct);
                }
            }
            // write position to output block
            pageBuilder.declarePosition();
            hashStrategy.appendTo(leftBlockIndex, leftBlockPosition, pageBuilder, 0);
        }
        // verify output block matches
        assertBlockEquals(VARCHAR, pageBuilder.build().getBlock(0), leftBlock);
    }
}
Also used : PagesHashStrategyFactory(io.trino.sql.gen.JoinCompiler.PagesHashStrategyFactory) ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) OptionalInt(java.util.OptionalInt) PageBuilder(io.trino.spi.PageBuilder) BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) PagesHashStrategy(io.trino.operator.PagesHashStrategy) SimplePagesHashStrategy(io.trino.operator.SimplePagesHashStrategy) BlockTypeOperators(io.trino.type.BlockTypeOperators) BlockPositionIsDistinctFrom(io.trino.type.BlockTypeOperators.BlockPositionIsDistinctFrom) Block(io.trino.spi.block.Block) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) Test(org.testng.annotations.Test)

Example 54 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestDeltaLakePageSink method testPageSinkStats.

@Test
public void testPageSinkStats() throws Exception {
    File tempDir = Files.createTempDir();
    try {
        DeltaLakeWriterStats stats = new DeltaLakeWriterStats();
        String tablePath = tempDir.getAbsolutePath() + "/test_table";
        ConnectorPageSink pageSink = createPageSink(new Path(tablePath), stats);
        List<LineItemColumn> columns = ImmutableList.copyOf(LineItemColumn.values());
        List<Type> columnTypes = columns.stream().map(LineItemColumn::getType).map(TestDeltaLakePageSink::getTrinoType).collect(toList());
        PageBuilder pageBuilder = new PageBuilder(columnTypes);
        long rows = 0;
        for (LineItem lineItem : new LineItemGenerator(0.01, 1, 1)) {
            if (rows >= NUM_ROWS) {
                break;
            }
            rows++;
            pageBuilder.declarePosition();
            for (int i = 0; i < columns.size(); i++) {
                LineItemColumn column = columns.get(i);
                BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
                writeToBlock(blockBuilder, column, lineItem);
            }
        }
        Page page = pageBuilder.build();
        pageSink.appendPage(page);
        JsonCodec<DataFileInfo> dataFileInfoCodec = new JsonCodecFactory().jsonCodec(DataFileInfo.class);
        Collection<Slice> fragments = getFutureValue(pageSink.finish());
        List<DataFileInfo> dataFileInfos = fragments.stream().map(Slice::getBytes).map(dataFileInfoCodec::fromJson).collect(toImmutableList());
        assertEquals(dataFileInfos.size(), 1);
        DataFileInfo dataFileInfo = dataFileInfos.get(0);
        List<File> files = ImmutableList.copyOf(new File(tablePath).listFiles((dir, name) -> !name.endsWith(".crc")));
        assertEquals(files.size(), 1);
        File outputFile = files.get(0);
        assertEquals(round(stats.getInputPageSizeInBytes().getAllTime().getMax()), page.getRetainedSizeInBytes());
        assertEquals(dataFileInfo.getStatistics().getNumRecords(), Optional.of(rows));
        assertEquals(dataFileInfo.getPartitionValues(), ImmutableList.of());
        assertEquals(dataFileInfo.getSize(), outputFile.length());
        assertEquals(dataFileInfo.getPath(), outputFile.getName());
        Instant now = Instant.now();
        assertTrue(dataFileInfo.getCreationTime() < now.toEpochMilli());
        assertTrue(dataFileInfo.getCreationTime() > now.minus(1, MINUTES).toEpochMilli());
    } finally {
        deleteRecursively(tempDir.toPath(), ALLOW_INSECURE);
    }
}
Also used : Slice(io.airlift.slice.Slice) PageBuilder(io.trino.spi.PageBuilder) MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) Test(org.testng.annotations.Test) TypeOperators(io.trino.spi.type.TypeOperators) JoinCompiler(io.trino.sql.gen.JoinCompiler) GroupByHashPageIndexerFactory(io.trino.operator.GroupByHashPageIndexerFactory) TpchColumnType(io.trino.tpch.TpchColumnType) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) NodeVersion(io.trino.plugin.hive.NodeVersion) MINUTES(java.time.temporal.ChronoUnit.MINUTES) Math.round(java.lang.Math.round) Slices(io.airlift.slice.Slices) Path(org.apache.hadoop.fs.Path) LineItemColumn(io.trino.tpch.LineItemColumn) INTEGER(io.trino.spi.type.IntegerType.INTEGER) Assert.assertEquals(io.trino.testing.assertions.Assert.assertEquals) ConnectorPageSink(io.trino.spi.connector.ConnectorPageSink) BlockTypeOperators(io.trino.type.BlockTypeOperators) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Instant(java.time.Instant) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) HDFS_ENVIRONMENT(io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT) File(java.io.File) LineItemGenerator(io.trino.tpch.LineItemGenerator) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) LineItem(io.trino.tpch.LineItem) SESSION(io.trino.plugin.hive.HiveTestUtils.SESSION) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BIGINT(io.trino.spi.type.BigintType.BIGINT) JsonCodecFactory(io.airlift.json.JsonCodecFactory) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) BlockBuilder(io.trino.spi.block.BlockBuilder) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle) REGULAR(io.trino.plugin.deltalake.DeltaLakeColumnType.REGULAR) DATE(io.trino.spi.type.DateType.DATE) JsonCodec(io.airlift.json.JsonCodec) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) Path(org.apache.hadoop.fs.Path) LineItemColumn(io.trino.tpch.LineItemColumn) Instant(java.time.Instant) LineItem(io.trino.tpch.LineItem) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) TpchColumnType(io.trino.tpch.TpchColumnType) Slice(io.airlift.slice.Slice) ConnectorPageSink(io.trino.spi.connector.ConnectorPageSink) File(java.io.File) JsonCodecFactory(io.airlift.json.JsonCodecFactory) LineItemGenerator(io.trino.tpch.LineItemGenerator) Test(org.testng.annotations.Test)

Example 55 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class JoinCompiler method generateAppendToMethod.

private static void generateAppendToMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> types, List<Integer> outputChannels, List<FieldDefinition> channelFields) {
    Parameter blockIndex = arg("blockIndex", int.class);
    Parameter blockPosition = arg("blockPosition", int.class);
    Parameter pageBuilder = arg("pageBuilder", PageBuilder.class);
    Parameter outputChannelOffset = arg("outputChannelOffset", int.class);
    MethodDefinition appendToMethod = classDefinition.declareMethod(a(PUBLIC), "appendTo", type(void.class), blockIndex, blockPosition, pageBuilder, outputChannelOffset);
    Variable thisVariable = appendToMethod.getThis();
    BytecodeBlock appendToBody = appendToMethod.getBody();
    int pageBuilderOutputChannel = 0;
    for (int outputChannel : outputChannels) {
        Type type = types.get(outputChannel);
        BytecodeExpression typeExpression = constantType(callSiteBinder, type);
        BytecodeExpression block = thisVariable.getField(channelFields.get(outputChannel)).invoke("get", Object.class, blockIndex).cast(Block.class);
        appendToBody.comment("%s.appendTo(channel_%s.get(outputChannel), blockPosition, pageBuilder.getBlockBuilder(outputChannelOffset + %s));", type.getClass(), outputChannel, pageBuilderOutputChannel).append(typeExpression).append(block).append(blockPosition).append(pageBuilder).append(outputChannelOffset).push(pageBuilderOutputChannel++).append(OpCode.IADD).invokeVirtual(PageBuilder.class, "getBlockBuilder", BlockBuilder.class, int.class).invokeInterface(Type.class, "appendTo", void.class, Block.class, int.class, BlockBuilder.class);
    }
    appendToBody.ret();
}
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) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Parameter(io.airlift.bytecode.Parameter) PageBuilder(io.trino.spi.PageBuilder) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

PageBuilder (io.trino.spi.PageBuilder)58 BlockBuilder (io.trino.spi.block.BlockBuilder)24 Page (io.trino.spi.Page)23 Type (io.trino.spi.type.Type)22 ImmutableList (com.google.common.collect.ImmutableList)14 Block (io.trino.spi.block.Block)11 Test (org.testng.annotations.Test)10 List (java.util.List)8 Slice (io.airlift.slice.Slice)6 ArrayType (io.trino.spi.type.ArrayType)6 INTEGER (io.trino.spi.type.IntegerType.INTEGER)5 Slices (io.airlift.slice.Slices)4 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)4 DictionaryBlock (io.trino.spi.block.DictionaryBlock)4 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)4 BIGINT (io.trino.spi.type.BigintType.BIGINT)4 DOUBLE (io.trino.spi.type.DoubleType.DOUBLE)4 MapType (io.trino.spi.type.MapType)4 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)4 RowType (io.trino.spi.type.RowType)3