Search in sources :

Example 56 with ConnectorTableHandle

use of io.trino.spi.connector.ConnectorTableHandle in project trino by trinodb.

the class RaptorPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<ColumnHandle> columns, DynamicFilter dynamicFilter) {
    RaptorSplit raptorSplit = (RaptorSplit) split;
    RaptorTableHandle raptorTable = (RaptorTableHandle) table;
    OptionalInt bucketNumber = raptorSplit.getBucketNumber();
    TupleDomain<RaptorColumnHandle> predicate = raptorTable.getConstraint();
    OrcReaderOptions options = new OrcReaderOptions().withMaxMergeDistance(getReaderMaxMergeDistance(session)).withMaxBufferSize(getReaderMaxReadSize(session)).withStreamBufferSize(getReaderStreamBufferSize(session)).withTinyStripeThreshold(getReaderTinyStripeThreshold(session)).withLazyReadSmallRanges(isReaderLazyReadSmallRanges(session));
    OptionalLong transactionId = raptorSplit.getTransactionId();
    if (raptorSplit.getShardUuids().size() == 1) {
        UUID shardUuid = raptorSplit.getShardUuids().iterator().next();
        return createPageSource(shardUuid, bucketNumber, columns, predicate, options, transactionId);
    }
    Iterator<ConnectorPageSource> iterator = raptorSplit.getShardUuids().stream().map(shardUuid -> createPageSource(shardUuid, bucketNumber, columns, predicate, options, transactionId)).iterator();
    return new ConcatPageSource(iterator);
}
Also used : StorageManager(io.trino.plugin.raptor.legacy.storage.StorageManager) RaptorSessionProperties.getReaderTinyStripeThreshold(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getReaderTinyStripeThreshold) Type(io.trino.spi.type.Type) OptionalInt(java.util.OptionalInt) ConcatPageSource(io.trino.plugin.raptor.legacy.util.ConcatPageSource) Inject(javax.inject.Inject) RaptorSessionProperties.getReaderStreamBufferSize(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getReaderStreamBufferSize) OptionalLong(java.util.OptionalLong) OrcReaderOptions(io.trino.orc.OrcReaderOptions) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource) RaptorSessionProperties.isReaderLazyReadSmallRanges(io.trino.plugin.raptor.legacy.RaptorSessionProperties.isReaderLazyReadSmallRanges) Iterator(java.util.Iterator) RaptorSessionProperties.getReaderMaxMergeDistance(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getReaderMaxMergeDistance) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) ConnectorSession(io.trino.spi.connector.ConnectorSession) UUID(java.util.UUID) RaptorSessionProperties.getReaderMaxReadSize(io.trino.plugin.raptor.legacy.RaptorSessionProperties.getReaderMaxReadSize) TupleDomain(io.trino.spi.predicate.TupleDomain) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DynamicFilter(io.trino.spi.connector.DynamicFilter) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ConcatPageSource(io.trino.plugin.raptor.legacy.util.ConcatPageSource) OrcReaderOptions(io.trino.orc.OrcReaderOptions) OptionalLong(java.util.OptionalLong) OptionalInt(java.util.OptionalInt) UUID(java.util.UUID) ConnectorPageSource(io.trino.spi.connector.ConnectorPageSource)

Example 57 with ConnectorTableHandle

use of io.trino.spi.connector.ConnectorTableHandle in project trino by trinodb.

the class TestRaptorMetadata method testRenameTable.

@Test
public void testRenameTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable(), false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    SchemaTableName renamedTable = new SchemaTableName(raptorTableHandle.getSchemaName(), "orders_renamed");
    metadata.renameTable(SESSION, raptorTableHandle, renamedTable);
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableHandle renamedTableHandle = metadata.getTableHandle(SESSION, renamedTable);
    assertNotNull(renamedTableHandle);
    assertEquals(((RaptorTableHandle) renamedTableHandle).getTableName(), renamedTable.getTableName());
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 58 with ConnectorTableHandle

use of io.trino.spi.connector.ConnectorTableHandle in project trino by trinodb.

the class TestRaptorMetadata method testDropColumn.

@Test
public void testDropColumn() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, buildTable(ImmutableMap.of(), tableMetadataBuilder(DEFAULT_TEST_ORDERS).column("orderkey", BIGINT).column("price", BIGINT)), false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    ColumnHandle lastColumn = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
    metadata.dropColumn(SESSION, raptorTableHandle, lastColumn);
    assertNull(metadata.getColumnHandles(SESSION, tableHandle).get("orderkey"));
}
Also used : RaptorColumnHandle(io.trino.plugin.raptor.legacy.RaptorColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 59 with ConnectorTableHandle

use of io.trino.spi.connector.ConnectorTableHandle in project trino by trinodb.

the class TestRaptorMetadata method testTransactionInsert.

@Test
public void testTransactionInsert() {
    // creating a table allocates a transaction
    long transactionId = 1;
    metadata.createTable(SESSION, getOrdersTable(), false);
    assertTrue(transactionSuccessful(transactionId));
    // start insert
    transactionId++;
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    ConnectorInsertTableHandle insertHandle = metadata.beginInsert(SESSION, tableHandle);
    // transaction is in progress
    assertTrue(transactionExists(transactionId));
    assertNull(transactionSuccessful(transactionId));
    // commit insert
    metadata.finishInsert(SESSION, insertHandle, ImmutableList.of(), ImmutableList.of());
    assertTrue(transactionExists(transactionId));
    assertTrue(transactionSuccessful(transactionId));
}
Also used : ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 60 with ConnectorTableHandle

use of io.trino.spi.connector.ConnectorTableHandle in project trino by trinodb.

the class TestRaptorMetadata method testTablePropertiesWithOrganization.

@Test
public void testTablePropertiesWithOrganization() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey"), ORGANIZED_PROPERTY, true));
    metadata.createTable(SESSION, ordersTable, false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // verify sort columns
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertTableColumnsEqual(sortColumns, ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderdate", DATE, 4, 3, OptionalInt.empty(), OptionalInt.of(0), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify organization
    assertTrue(metadataDao.getTableInformation(tableId).isOrganized());
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(io.trino.plugin.raptor.legacy.RaptorTableHandle) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)133 ConnectorSession (io.trino.spi.connector.ConnectorSession)82 ColumnHandle (io.trino.spi.connector.ColumnHandle)77 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)67 Test (org.testng.annotations.Test)65 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)52 SchemaTableName (io.trino.spi.connector.SchemaTableName)51 Constraint (io.trino.spi.connector.Constraint)45 TestingConnectorSession (io.trino.testing.TestingConnectorSession)44 List (java.util.List)40 Optional (java.util.Optional)40 ConnectorInsertTableHandle (io.trino.spi.connector.ConnectorInsertTableHandle)39 TupleDomain (io.trino.spi.predicate.TupleDomain)39 ImmutableList (com.google.common.collect.ImmutableList)38 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)37 ImmutableMap (com.google.common.collect.ImmutableMap)36 TrinoException (io.trino.spi.TrinoException)36 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)36 Map (java.util.Map)36 Objects.requireNonNull (java.util.Objects.requireNonNull)36