use of io.trino.sql.planner.PartitioningHandle in project trino by trinodb.
the class MetadataManager method getCommonPartitioning.
@Override
public Optional<PartitioningHandle> getCommonPartitioning(Session session, PartitioningHandle left, PartitioningHandle right) {
Optional<CatalogName> leftConnectorId = left.getConnectorId();
Optional<CatalogName> rightConnectorId = right.getConnectorId();
if (leftConnectorId.isEmpty() || rightConnectorId.isEmpty() || !leftConnectorId.equals(rightConnectorId)) {
return Optional.empty();
}
if (!left.getTransactionHandle().equals(right.getTransactionHandle())) {
return Optional.empty();
}
CatalogName catalogName = leftConnectorId.get();
CatalogMetadata catalogMetadata = getCatalogMetadata(session, catalogName);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogName);
Optional<ConnectorPartitioningHandle> commonHandle = metadata.getCommonPartitioningHandle(session.toConnectorSession(catalogName), left.getConnectorHandle(), right.getConnectorHandle());
return commonHandle.map(handle -> new PartitioningHandle(Optional.of(catalogName), left.getTransactionHandle(), handle));
}
use of io.trino.sql.planner.PartitioningHandle in project trino by trinodb.
the class TestLocalExchange method testPartitionCustomPartitioning.
@Test(dataProvider = "executionStrategy")
public void testPartitionCustomPartitioning(PipelineExecutionStrategy executionStrategy) {
ConnectorPartitioningHandle connectorPartitioningHandle = new ConnectorPartitioningHandle() {
};
ConnectorNodePartitioningProvider connectorNodePartitioningProvider = new ConnectorNodePartitioningProvider() {
@Override
public ConnectorBucketNodeMap getBucketNodeMap(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
return createBucketNodeMap(2);
}
@Override
public ToIntFunction<ConnectorSplit> getSplitBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle) {
throw new UnsupportedOperationException();
}
@Override
public BucketFunction getBucketFunction(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorPartitioningHandle partitioningHandle, List<Type> partitionChannelTypes, int bucketCount) {
return (page, position) -> {
long rowValue = BIGINT.getLong(page.getBlock(0), position);
if (rowValue == 42) {
return 0;
}
return 1;
};
}
};
List<Type> types = ImmutableList.of(VARCHAR, BIGINT);
nodePartitioningManager.addPartitioningProvider(new CatalogName("foo"), connectorNodePartitioningProvider);
PartitioningHandle partitioningHandle = new PartitioningHandle(Optional.of(new CatalogName("foo")), Optional.of(TestingTransactionHandle.create()), connectorPartitioningHandle);
LocalExchangeFactory localExchangeFactory = new LocalExchangeFactory(nodePartitioningManager, SESSION, partitioningHandle, 2, types, ImmutableList.of(1), Optional.empty(), executionStrategy, LOCAL_EXCHANGE_MAX_BUFFERED_BYTES, TYPE_OPERATOR_FACTORY);
LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
localExchangeFactory.noMoreSinkFactories();
run(localExchangeFactory, executionStrategy, exchange -> {
assertEquals(exchange.getBufferCount(), 2);
assertExchangeTotalBufferedBytes(exchange, 0);
LocalExchangeSinkFactory sinkFactory = exchange.getSinkFactory(localExchangeSinkFactoryId);
LocalExchangeSink sink = sinkFactory.createSink();
assertSinkCanWrite(sink);
sinkFactory.close();
sinkFactory.noMoreSinkFactories();
LocalExchangeSource sourceA = exchange.getSource(1);
assertSource(sourceA, 0);
LocalExchangeSource sourceB = exchange.getSource(0);
assertSource(sourceB, 0);
Page pageA = SequencePageBuilder.createSequencePage(types, 1, 100, 42);
sink.addPage(pageA);
assertSource(sourceA, 1);
assertSource(sourceB, 0);
assertRemovePage(types, sourceA, pageA);
assertSource(sourceA, 0);
Page pageB = SequencePageBuilder.createSequencePage(types, 100, 100, 43);
sink.addPage(pageB);
assertSource(sourceA, 0);
assertSource(sourceB, 1);
assertRemovePage(types, sourceB, pageB);
assertSource(sourceB, 0);
});
}
Aggregations