Search in sources :

Example 31 with ConnectorTransactionHandle

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

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
    JmxTableHandle tableHandle = (JmxTableHandle) table;
    // TODO is there a better way to get the node column?
    Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream().filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)).findFirst();
    checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);
    TupleDomain<ColumnHandle> nodeFilter = tableHandle.getNodeFilter();
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return nodeFilter.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) ImmutableMap(com.google.common.collect.ImmutableMap) NullableValue(io.trino.spi.predicate.NullableValue) NodeManager(io.trino.spi.NodeManager) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Inject(javax.inject.Inject) TupleDomain.fromFixedValues(io.trino.spi.predicate.TupleDomain.fromFixedValues) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) NODE_COLUMN_NAME(io.trino.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME) DynamicFilter(io.trino.spi.connector.DynamicFilter) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) NullableValue(io.trino.spi.predicate.NullableValue) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 32 with ConnectorTransactionHandle

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

the class TestKinesisPlugin method testCreateConnector.

@Test
public void testCreateConnector() {
    KinesisPlugin plugin = new KinesisPlugin();
    ConnectorFactory factory = getOnlyElement(plugin.getConnectorFactories());
    String accessKey = "kinesis.accessKey";
    String secretKey = "kinesis.secretKey";
    Connector c = factory.create("kinesis.test-connector", ImmutableMap.<String, String>builder().put("kinesis.hide-internal-columns", "false").put("kinesis.access-key", TestUtils.noneToBlank(accessKey)).put("kinesis.secret-key", TestUtils.noneToBlank(secretKey)).buildOrThrow(), new TestingConnectorContext());
    assertNotNull(c);
    // Verify that the key objects have been created on the connector
    assertNotNull(c.getRecordSetProvider());
    assertNotNull(c.getSplitManager());
    ConnectorMetadata md = c.getMetadata(SESSION, KinesisTransactionHandle.INSTANCE);
    assertNotNull(md);
    ConnectorTransactionHandle handle = c.beginTransaction(READ_COMMITTED, true, true);
    assertTrue(handle instanceof KinesisTransactionHandle);
    c.shutdown();
}
Also used : Connector(io.trino.spi.connector.Connector) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TestingConnectorContext(io.trino.testing.TestingConnectorContext) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) Test(org.testng.annotations.Test)

Example 33 with ConnectorTransactionHandle

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

the class TestKinesisTableDescriptionSupplier method testTableDefinition.

@Test
public void testTableDefinition() {
    KinesisMetadata metadata = (KinesisMetadata) connector.getMetadata(SESSION, new ConnectorTransactionHandle() {
    });
    SchemaTableName tblName = new SchemaTableName("prod", "test_table");
    KinesisTableHandle tableHandle = metadata.getTableHandle(SESSION, tblName);
    assertNotNull(metadata);
    SchemaTableName tableSchemaName = tableHandle.toSchemaTableName();
    assertEquals(tableSchemaName.getSchemaName(), "prod");
    assertEquals(tableSchemaName.getTableName(), "test_table");
    assertEquals(tableHandle.getStreamName(), "test_kinesis_stream");
    assertEquals(tableHandle.getMessageDataFormat(), "json");
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, tableHandle);
    assertEquals(columnHandles.size(), 14);
    assertEquals(columnHandles.values().stream().filter(x -> ((KinesisColumnHandle) x).isInternal()).count(), 10);
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 34 with ConnectorTransactionHandle

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

the class TestKinesisTableDescriptionSupplier method testRelatedObjects.

@Test
public void testRelatedObjects() {
    KinesisMetadata metadata = (KinesisMetadata) connector.getMetadata(SESSION, new ConnectorTransactionHandle() {
    });
    assertNotNull(metadata);
    SchemaTableName tblName = new SchemaTableName("prod", "test_table");
    List<String> schemas = metadata.listSchemaNames(null);
    assertEquals(schemas.size(), 1);
    assertEquals(schemas.get(0), "prod");
    KinesisTableHandle tblHandle = metadata.getTableHandle(null, tblName);
    assertNotNull(tblHandle);
    assertEquals(tblHandle.getSchemaName(), "prod");
    assertEquals(tblHandle.getTableName(), "test_table");
    assertEquals(tblHandle.getStreamName(), "test_kinesis_stream");
    assertEquals(tblHandle.getMessageDataFormat(), "json");
    ConnectorTableMetadata tblMeta = metadata.getTableMetadata(null, tblHandle);
    assertNotNull(tblMeta);
    assertEquals(tblMeta.getTable().getSchemaName(), "prod");
    assertEquals(tblMeta.getTable().getTableName(), "test_table");
    List<ColumnMetadata> columnList = tblMeta.getColumns();
    assertNotNull(columnList);
    boolean foundServiceType = false;
    boolean foundPartitionKey = false;
    for (ColumnMetadata column : columnList) {
        if (column.getName().equals("service_type")) {
            foundServiceType = true;
            assertEquals(column.getType().getDisplayName(), "varchar(20)");
        }
        if (column.getName().equals("_partition_key")) {
            foundPartitionKey = true;
            assertEquals(column.getType().getDisplayName(), "varchar");
        }
    }
    assertTrue(foundServiceType);
    assertTrue(foundPartitionKey);
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 35 with ConnectorTransactionHandle

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

the class RedisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<? extends ColumnHandle> columns) {
    RedisSplit redisSplit = (RedisSplit) split;
    List<RedisColumnHandle> redisColumns = columns.stream().map(RedisColumnHandle.class::cast).collect(toImmutableList());
    RowDecoder keyDecoder = decoderFactory.create(redisSplit.getKeyDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(RedisColumnHandle::isKeyDecoder).collect(toImmutableSet()));
    RowDecoder valueDecoder = decoderFactory.create(redisSplit.getValueDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(col -> !col.isKeyDecoder()).collect(toImmutableSet()));
    return new RedisRecordSet(redisSplit, jedisManager, redisColumns, keyDecoder, valueDecoder);
}
Also used : ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) Collections.emptyMap(java.util.Collections.emptyMap) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConnectorSession(io.trino.spi.connector.ConnectorSession) Inject(javax.inject.Inject) List(java.util.List) RowDecoder(io.trino.decoder.RowDecoder) DispatchingRowDecoderFactory(io.trino.decoder.DispatchingRowDecoderFactory) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) RowDecoder(io.trino.decoder.RowDecoder)

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