Search in sources :

Example 36 with ConnectorTransactionHandle

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

the class TestRaptorConnector method testMaintenanceBlocked.

@Test
public void testMaintenanceBlocked() {
    long tableId1 = createTable("test1");
    long tableId2 = createTable("test2");
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // begin delete for table1
    ConnectorTransactionHandle txn1 = beginTransaction();
    ConnectorTableHandle handle1 = getTableHandle(connector.getMetadata(SESSION, txn1), "test1");
    connector.getMetadata(SESSION, txn1).beginDelete(SESSION, handle1);
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // begin delete for table2
    ConnectorTransactionHandle txn2 = beginTransaction();
    ConnectorTableHandle handle2 = getTableHandle(connector.getMetadata(SESSION, txn2), "test2");
    connector.getMetadata(SESSION, txn2).beginDelete(SESSION, handle2);
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // begin another delete for table1
    ConnectorTransactionHandle txn3 = beginTransaction();
    ConnectorTableHandle handle3 = getTableHandle(connector.getMetadata(SESSION, txn3), "test1");
    connector.getMetadata(SESSION, txn3).beginDelete(SESSION, handle3);
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // commit first delete for table1
    connector.commit(txn1);
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // rollback second delete for table1
    connector.rollback(txn3);
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertTrue(metadataDao.isMaintenanceBlockedLocked(tableId2));
    // commit delete for table2
    connector.commit(txn2);
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId1));
    assertFalse(metadataDao.isMaintenanceBlockedLocked(tableId2));
}
Also used : ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 37 with ConnectorTransactionHandle

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

the class TestS3TableConfigClient method testTableReading.

@Parameters({ "kinesis.test-table-description-location", "kinesis.awsAccessKey", "kinesis.awsSecretKey" })
@Test
public void testTableReading(String tableDescriptionS3, String accessKey, String secretKey) {
    // To run this test: setup an S3 bucket with a folder for unit testing, and put
    // MinimalTable.json in that folder.
    // Create dependent objects, including the minimal config needed for this test
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("kinesis.table-description-location", tableDescriptionS3).put("kinesis.default-schema", "kinesis").put("kinesis.hide-internal-columns", "false").put("kinesis.access-key", TestUtils.noneToBlank(accessKey)).put("kinesis.secret-key", TestUtils.noneToBlank(secretKey)).buildOrThrow();
    KinesisPlugin kinesisPlugin = new KinesisPlugin();
    KinesisConnector kinesisConnector = TestUtils.createConnector(kinesisPlugin, properties, false);
    // Sleep for 10 seconds to ensure that we've loaded the tables:
    try {
        Thread.sleep(10000);
        log.info("done sleeping, will now try to read the tables.");
    } catch (InterruptedException e) {
        log.error("interrupted ...");
    }
    KinesisMetadata metadata = (KinesisMetadata) kinesisConnector.getMetadata(SESSION, new ConnectorTransactionHandle() {
    });
    SchemaTableName tblName = new SchemaTableName("default", "test123");
    KinesisTableHandle tableHandle = metadata.getTableHandle(SESSION, tblName);
    assertNotNull(metadata);
    SchemaTableName tableSchemaName = tableHandle.toSchemaTableName();
    assertEquals(tableSchemaName.getSchemaName(), "default");
    assertEquals(tableSchemaName.getTableName(), "test123");
    assertEquals(tableHandle.getStreamName(), "test123");
    assertEquals(tableHandle.getMessageDataFormat(), "json");
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, tableHandle);
    assertEquals(columnHandles.size(), 12);
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) KinesisMetadata(io.trino.plugin.kinesis.KinesisMetadata) KinesisConnector(io.trino.plugin.kinesis.KinesisConnector) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) KinesisPlugin(io.trino.plugin.kinesis.KinesisPlugin) SchemaTableName(io.trino.spi.connector.SchemaTableName) KinesisTableHandle(io.trino.plugin.kinesis.KinesisTableHandle) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 38 with ConnectorTransactionHandle

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

the class TpchIndexProvider method getIndex.

@Override
public ConnectorIndex getIndex(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorIndexHandle indexHandle, List<ColumnHandle> lookupSchema, List<ColumnHandle> outputSchema) {
    TpchIndexHandle tpchIndexHandle = (TpchIndexHandle) indexHandle;
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tpchIndexHandle.getFixedValues()).get();
    checkArgument(lookupSchema.stream().noneMatch(handle -> fixedValues.keySet().contains(handle)), "Lookup columnHandles are not expected to overlap with the fixed value predicates");
    // Establish an order for the fixedValues
    List<ColumnHandle> fixedValueColumns = ImmutableList.copyOf(fixedValues.keySet());
    // Extract the fixedValues as their raw values and types
    List<Object> rawFixedValues = new ArrayList<>(fixedValueColumns.size());
    List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size());
    for (ColumnHandle fixedValueColumn : fixedValueColumns) {
        rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue());
        rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
    }
    // Establish the schema after we append the fixed values to the lookup keys.
    List<ColumnHandle> finalLookupSchema = ImmutableList.<ColumnHandle>builder().addAll(lookupSchema).addAll(fixedValueColumns).build();
    Optional<TpchIndexedData.IndexedTable> indexedTable = indexedData.getIndexedTable(tpchIndexHandle.getTableName(), tpchIndexHandle.getScaleFactor(), tpchIndexHandle.getIndexColumnNames());
    checkState(indexedTable.isPresent());
    TpchIndexedData.IndexedTable table = indexedTable.get();
    // Compute how to map from the final lookup schema to the table index key order
    List<Integer> keyRemap = computeRemap(handleToNames(finalLookupSchema), table.getKeyColumns());
    Function<RecordSet, RecordSet> keyFormatter = key -> new MappedRecordSet(new AppendingRecordSet(key, rawFixedValues, rawFixedTypes), keyRemap);
    // Compute how to map from the output of the indexed data to the expected output schema
    List<Integer> outputRemap = computeRemap(table.getOutputColumns(), handleToNames(outputSchema));
    Function<RecordSet, RecordSet> outputFormatter = output -> new MappedRecordSet(output, outputRemap);
    return new TpchConnectorIndex(keyFormatter, outputFormatter, table);
}
Also used : TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) Function(java.util.function.Function) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) Optional(java.util.Optional) ConnectorIndexHandle(io.trino.spi.connector.ConnectorIndexHandle) ConnectorIndex(io.trino.spi.connector.ConnectorIndex) MappedRecordSet(io.trino.split.MappedRecordSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) ArrayList(java.util.ArrayList) NullableValue(io.trino.spi.predicate.NullableValue) Type(io.trino.spi.type.Type) MappedRecordSet(io.trino.split.MappedRecordSet) RecordSet(io.trino.spi.connector.RecordSet) MappedRecordSet(io.trino.split.MappedRecordSet)

Example 39 with ConnectorTransactionHandle

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

the class IndexedTpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    TpchIndexedData indexedData = new TpchIndexedData(indexSpec);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transactionHandle) {
            return new TpchIndexMetadata(indexedData);
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpchRecordSetProvider(DecimalTypeMapping.DOUBLE);
        }

        @Override
        public ConnectorIndexProvider getIndexProvider() {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables() {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TpchSplitManager(io.trino.plugin.tpch.TpchSplitManager) NodeManager(io.trino.spi.NodeManager) TpchNodePartitioningProvider(io.trino.plugin.tpch.TpchNodePartitioningProvider) ConnectorSession(io.trino.spi.connector.ConnectorSession) SystemTable(io.trino.spi.connector.SystemTable) TpchRecordSetProvider(io.trino.plugin.tpch.TpchRecordSetProvider)

Example 40 with ConnectorTransactionHandle

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

the class PhoenixSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    JdbcTableHandle tableHandle = (JdbcTableHandle) table;
    try (Connection connection = phoenixClient.getConnection(session)) {
        List<JdbcColumnHandle> columns = tableHandle.getColumns().map(columnSet -> columnSet.stream().map(JdbcColumnHandle.class::cast).collect(toList())).orElseGet(() -> phoenixClient.getColumns(session, tableHandle));
        PhoenixPreparedStatement inputQuery = (PhoenixPreparedStatement) phoenixClient.prepareStatement(session, connection, tableHandle, columns, Optional.empty());
        int maxScansPerSplit = session.getProperty(PhoenixSessionProperties.MAX_SCANS_PER_SPLIT, Integer.class);
        List<ConnectorSplit> splits = getSplits(inputQuery, maxScansPerSplit).stream().map(PhoenixInputSplit.class::cast).map(split -> new PhoenixSplit(getSplitAddresses(split), SerializedPhoenixInputSplit.serialize(split))).collect(toImmutableList());
        return new FixedSplitSource(splits);
    } catch (IOException | SQLException e) {
        throw new TrinoException(PHOENIX_SPLIT_ERROR, "Couldn't get Phoenix splits", e);
    }
}
Also used : ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) KeyRange(org.apache.phoenix.query.KeyRange) Connection(java.sql.Connection) Logger(io.airlift.log.Logger) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) QueryPlan(org.apache.phoenix.compile.QueryPlan) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) InputSplit(org.apache.hadoop.mapreduce.InputSplit) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoException(io.trino.spi.TrinoException) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) IOException(java.io.IOException) ConnectorSession(io.trino.spi.connector.ConnectorSession) Scan(org.apache.hadoop.hbase.client.Scan) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DynamicFilter(io.trino.spi.connector.DynamicFilter) PHOENIX_INTERNAL_ERROR(io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_INTERNAL_ERROR) Optional(java.util.Optional) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) PHOENIX_SPLIT_ERROR(io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_SPLIT_ERROR) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) HostAddress(io.trino.spi.HostAddress) EXPECTED_UPPER_REGION_KEY(org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EXPECTED_UPPER_REGION_KEY) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) IOException(java.io.IOException) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) TrinoException(io.trino.spi.TrinoException) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Aggregations

ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)44 ConnectorSession (io.trino.spi.connector.ConnectorSession)23 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)21 ColumnHandle (io.trino.spi.connector.ColumnHandle)15 List (java.util.List)14 Objects.requireNonNull (java.util.Objects.requireNonNull)14 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)13 ImmutableList (com.google.common.collect.ImmutableList)12 Optional (java.util.Optional)12 Inject (javax.inject.Inject)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 CatalogName (io.trino.connector.CatalogName)9 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)9 DynamicFilter (io.trino.spi.connector.DynamicFilter)9 Test (org.testng.annotations.Test)9 SchemaTableName (io.trino.spi.connector.SchemaTableName)8 Map (java.util.Map)8 ConnectorSplitSource (io.trino.spi.connector.ConnectorSplitSource)7 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)7 TupleDomain (io.trino.spi.predicate.TupleDomain)7