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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations