Search in sources :

Example 21 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class HiveTransactionManager method commit.

public void commit(ConnectorTransactionHandle transaction) {
    MemoizedMetadata transactionalMetadata = transactions.remove(transaction);
    checkArgument(transactionalMetadata != null, "no such transaction: %s", transaction);
    transactionalMetadata.optionalGet().ifPresent(metadata -> {
        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
            metadata.commit();
        }
    });
}
Also used : ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 22 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class HiveTransactionManager method rollback.

public void rollback(ConnectorTransactionHandle transaction) {
    MemoizedMetadata transactionalMetadata = transactions.remove(transaction);
    checkArgument(transactionalMetadata != null, "no such transaction: %s", transaction);
    transactionalMetadata.optionalGet().ifPresent(metadata -> {
        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {
            metadata.rollback();
        }
    });
}
Also used : ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 23 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class TestShardWriter method testWriter.

@Test
public void testWriter() throws Exception {
    List<Long> columnIds = ImmutableList.of(1L, 2L, 4L, 6L, 7L, 8L, 9L, 10L);
    ArrayType arrayType = new ArrayType(BIGINT);
    ArrayType arrayOfArrayType = new ArrayType(arrayType);
    Type mapType = TESTING_TYPE_MANAGER.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(createVarcharType(10).getTypeSignature()), TypeSignatureParameter.typeParameter(BOOLEAN.getTypeSignature())));
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DOUBLE, BOOLEAN, arrayType, mapType, arrayOfArrayType);
    File file = directory.resolve(System.nanoTime() + ".orc").toFile();
    byte[] bytes1 = octets(0x00, 0xFE, 0xFF);
    byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80);
    RowPagesBuilder rowPagesBuilder = RowPagesBuilder.rowPagesBuilder(columnTypes).row(123L, "hello", wrappedBuffer(bytes1), 123.456, true, arrayBlockOf(BIGINT, 1, 2), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5))).row(null, "world", null, Double.POSITIVE_INFINITY, null, arrayBlockOf(BIGINT, 3, null), mapBlockOf(createVarcharType(5), BOOLEAN, "k2", null), arrayBlockOf(arrayType, null, arrayBlockOf(BIGINT, 6, 7))).row(456L, "bye \u2603", wrappedBuffer(bytes3), Double.NaN, false, arrayBlockOf(BIGINT), mapBlockOf(createVarcharType(5), BOOLEAN, "k3", false), arrayBlockOf(arrayType, arrayBlockOf(BIGINT)));
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(new EmptyClassLoader());
        OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) {
        writer.appendPages(rowPagesBuilder.build());
    }
    try (OrcDataSource dataSource = fileOrcDataSource(file)) {
        OrcRecordReader reader = createReader(dataSource, columnIds, columnTypes);
        assertEquals(reader.getReaderRowCount(), 3);
        assertEquals(reader.getReaderPosition(), 0);
        assertEquals(reader.getFileRowCount(), reader.getReaderRowCount());
        assertEquals(reader.getFilePosition(), reader.getFilePosition());
        Page page = reader.nextPage();
        assertEquals(page.getPositionCount(), 3);
        assertEquals(reader.getReaderPosition(), 0);
        assertEquals(reader.getFilePosition(), reader.getFilePosition());
        Block column0 = page.getBlock(0);
        assertEquals(column0.isNull(0), false);
        assertEquals(column0.isNull(1), true);
        assertEquals(column0.isNull(2), false);
        assertEquals(BIGINT.getLong(column0, 0), 123L);
        assertEquals(BIGINT.getLong(column0, 2), 456L);
        Block column1 = page.getBlock(1);
        assertEquals(createVarcharType(10).getSlice(column1, 0), utf8Slice("hello"));
        assertEquals(createVarcharType(10).getSlice(column1, 1), utf8Slice("world"));
        assertEquals(createVarcharType(10).getSlice(column1, 2), utf8Slice("bye \u2603"));
        Block column2 = page.getBlock(2);
        assertEquals(VARBINARY.getSlice(column2, 0), wrappedBuffer(bytes1));
        assertEquals(column2.isNull(1), true);
        assertEquals(VARBINARY.getSlice(column2, 2), wrappedBuffer(bytes3));
        Block column3 = page.getBlock(3);
        assertEquals(column3.isNull(0), false);
        assertEquals(column3.isNull(1), false);
        assertEquals(column3.isNull(2), false);
        assertEquals(DOUBLE.getDouble(column3, 0), 123.456);
        assertEquals(DOUBLE.getDouble(column3, 1), Double.POSITIVE_INFINITY);
        assertEquals(DOUBLE.getDouble(column3, 2), Double.NaN);
        Block column4 = page.getBlock(4);
        assertEquals(column4.isNull(0), false);
        assertEquals(column4.isNull(1), true);
        assertEquals(column4.isNull(2), false);
        assertEquals(BOOLEAN.getBoolean(column4, 0), true);
        assertEquals(BOOLEAN.getBoolean(column4, 2), false);
        Block column5 = page.getBlock(5);
        assertEquals(column5.getPositionCount(), 3);
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column5, 0), arrayBlockOf(BIGINT, 1, 2)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column5, 1), arrayBlockOf(BIGINT, 3, null)));
        assertTrue(arrayBlocksEqual(BIGINT, arrayType.getObject(column5, 2), arrayBlockOf(BIGINT)));
        Block column6 = page.getBlock(6);
        assertEquals(column6.getPositionCount(), 3);
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column6, 0), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true)));
        Block object = arrayType.getObject(column6, 1);
        Block k2 = mapBlockOf(createVarcharType(5), BOOLEAN, "k2", null);
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, object, k2));
        assertTrue(mapBlocksEqual(createVarcharType(5), BOOLEAN, arrayType.getObject(column6, 2), mapBlockOf(createVarcharType(5), BOOLEAN, "k3", false)));
        Block column7 = page.getBlock(7);
        assertEquals(column7.getPositionCount(), 3);
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column7, 0), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column7, 1), arrayBlockOf(arrayType, null, arrayBlockOf(BIGINT, 6, 7))));
        assertTrue(arrayBlocksEqual(arrayType, arrayOfArrayType.getObject(column7, 2), arrayBlockOf(arrayType, arrayBlockOf(BIGINT))));
        assertNull(reader.nextPage());
        assertEquals(reader.getReaderPosition(), 3);
        assertEquals(reader.getFilePosition(), reader.getFilePosition());
        OrcFileMetadata orcFileMetadata = METADATA_CODEC.fromJson(reader.getUserMetadata().get(OrcFileMetadata.KEY).getBytes());
        assertEquals(orcFileMetadata, new OrcFileMetadata(ImmutableMap.<Long, TypeId>builder().put(1L, BIGINT.getTypeId()).put(2L, createVarcharType(10).getTypeId()).put(4L, VARBINARY.getTypeId()).put(6L, DOUBLE.getTypeId()).put(7L, BOOLEAN.getTypeId()).put(8L, arrayType.getTypeId()).put(9L, mapType.getTypeId()).put(10L, arrayOfArrayType.getTypeId()).buildOrThrow()));
    }
    File crcFile = new File(file.getParentFile(), "." + file.getName() + ".crc");
    assertFalse(crcFile.exists());
}
Also used : OrcTestingUtil.fileOrcDataSource(io.trino.plugin.raptor.legacy.storage.OrcTestingUtil.fileOrcDataSource) OrcDataSource(io.trino.orc.OrcDataSource) RowPagesBuilder(io.trino.RowPagesBuilder) Page(io.trino.spi.Page) OrcRecordReader(io.trino.orc.OrcRecordReader) ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) ArrayType(io.trino.spi.type.ArrayType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) Block(io.trino.spi.block.Block) File(java.io.File) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) Test(org.testng.annotations.Test)

Aggregations

ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)23 Injector (com.google.inject.Injector)7 Bootstrap (io.airlift.bootstrap.Bootstrap)7 JsonModule (io.airlift.json.JsonModule)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 CatalogName (io.trino.plugin.base.CatalogName)4 Connector (io.trino.spi.connector.Connector)4 ConnectorContext (io.trino.spi.connector.ConnectorContext)4 TypeManager (io.trino.spi.type.TypeManager)4 Map (java.util.Map)4 Key (com.google.inject.Key)3 Module (com.google.inject.Module)3 TypeLiteral (com.google.inject.TypeLiteral)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 EventModule (io.airlift.event.client.EventModule)3 CatalogNameModule (io.trino.plugin.base.CatalogNameModule)3 ClassLoaderSafeConnectorPageSinkProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider)3 ClassLoaderSafeConnectorPageSourceProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider)3 ClassLoaderSafeConnectorSplitManager (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager)3 ClassLoaderSafeNodePartitioningProvider (io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider)3