|
23 | 23 | import io.trino.plugin.iceberg.IcebergPageSourceProviderFactory; |
24 | 24 | import io.trino.plugin.iceberg.IcebergTableHandle; |
25 | 25 | import io.trino.plugin.iceberg.system.files.FilesTableSplit; |
| 26 | +import io.trino.spi.connector.ColumnHandle; |
| 27 | +import io.trino.spi.connector.ConnectorPageSource; |
26 | 28 | import io.trino.spi.connector.ConnectorPageSourceProvider; |
27 | 29 | import io.trino.spi.connector.ConnectorPageSourceProviderFactory; |
| 30 | +import io.trino.spi.connector.ConnectorSession; |
28 | 31 | import io.trino.spi.connector.ConnectorSplit; |
29 | 32 | import io.trino.spi.connector.ConnectorTableHandle; |
| 33 | +import io.trino.spi.connector.ConnectorTransactionHandle; |
| 34 | +import io.trino.spi.connector.DynamicFilter; |
| 35 | + |
| 36 | +import java.util.List; |
30 | 37 |
|
31 | 38 | import static java.util.Objects.requireNonNull; |
32 | 39 |
|
@@ -54,8 +61,36 @@ public LakehousePageSourceProviderFactory( |
54 | 61 | @Override |
55 | 62 | public ConnectorPageSourceProvider createPageSourceProvider() |
56 | 63 | { |
57 | | - return (transaction, session, split, table, columns, dynamicFilter) -> |
58 | | - forHandle(split, table).createPageSource(transaction, session, split, table, columns, dynamicFilter); |
| 64 | + // createPageSourceProvider is called for each scan within a query |
| 65 | + // we hold on to ConnectorPageSourceProvider instance to allow IcebergPageSourceProvider to reuse equality deletes between splits of the same scan |
| 66 | + return new ConnectorPageSourceProvider() |
| 67 | + { |
| 68 | + private volatile ConnectorPageSourceProvider delegate; |
| 69 | + |
| 70 | + @Override |
| 71 | + public ConnectorPageSource createPageSource(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<ColumnHandle> columns, DynamicFilter dynamicFilter) |
| 72 | + { |
| 73 | + if (delegate == null) { |
| 74 | + synchronized (this) { |
| 75 | + if (delegate == null) { |
| 76 | + delegate = forHandle(split, table); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + return delegate.createPageSource(transaction, session, split, table, columns, dynamicFilter); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public long getMemoryUsage() |
| 85 | + { |
| 86 | + ConnectorPageSourceProvider provider = delegate; |
| 87 | + if (provider == null) { |
| 88 | + // No page source was created, so no memory is used |
| 89 | + return 0; |
| 90 | + } |
| 91 | + return provider.getMemoryUsage(); |
| 92 | + } |
| 93 | + }; |
59 | 94 | } |
60 | 95 |
|
61 | 96 | private ConnectorPageSourceProvider forHandle(ConnectorSplit split, ConnectorTableHandle handle) |
|
0 commit comments