Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1207,10 +1207,17 @@ public InsertTableHandle beginRefreshMaterializedView(Session session, TableHand
ConnectorTransactionHandle transactionHandle = catalogMetadata.getTransactionHandleFor(catalogHandle);

List<ConnectorTableHandle> sourceConnectorHandles = sourceTableHandles.stream()
.filter(handle -> handle.catalogHandle().equals(catalogHandle))
.map(TableHandle::connectorHandle)
.collect(Collectors.toList());

ConnectorInsertTableHandle handle = metadata.beginRefreshMaterializedView(session.toConnectorSession(catalogHandle), tableHandle.connectorHandle(), sourceConnectorHandles, getRetryPolicy(session).getRetryMode(), refreshType);
ConnectorInsertTableHandle handle = metadata.beginRefreshMaterializedView(
session.toConnectorSession(catalogHandle),
tableHandle.connectorHandle(),
sourceConnectorHandles,
sourceConnectorHandles.size() < sourceTableHandles.size(),
getRetryPolicy(session).getRetryMode(),
refreshType);

return new InsertTableHandle(tableHandle.catalogHandle(), transactionHandle, handle);
}
Expand All @@ -1229,16 +1236,19 @@ public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(
ConnectorMetadata metadata = getMetadata(session, catalogHandle);

List<ConnectorTableHandle> sourceConnectorHandles = sourceTableHandles.stream()
.filter(handle -> handle.catalogHandle().equals(catalogHandle))
.map(TableHandle::connectorHandle)
.collect(toImmutableList());

return metadata.finishRefreshMaterializedView(
session.toConnectorSession(catalogHandle),
tableHandle.connectorHandle(),
insertHandle.connectorHandle(),
fragments,
computedStatistics,
sourceConnectorHandles,
sourceTableFunctions);
sourceConnectorHandles.size() < sourceTableHandles.size(),
!sourceTableFunctions.isEmpty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public boolean delegateMaterializedViewRefreshToConnector(ConnectorSession sessi
}

@Override
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, RetryMode retryMode, RefreshType refreshType)
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, RetryMode retryMode, RefreshType refreshType)
{
queryIdToRefreshType.put(session.getQueryId(), refreshType);
return TestingHandle.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,27 +702,20 @@ public CompletableFuture<?> refreshMaterializedView(ConnectorSession session, Sc
}

@Override
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, RetryMode retryMode, RefreshType refreshType)
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, RetryMode retryMode, RefreshType refreshType)
{
Span span = startSpan("beginRefreshMaterializedView", tableHandle);
try (var _ = scopedSpan(span)) {
return delegate.beginRefreshMaterializedView(session, tableHandle, sourceTableHandles, retryMode, refreshType);
return delegate.beginRefreshMaterializedView(session, tableHandle, sourceTableHandles, hasForeignSourceTables, retryMode, refreshType);
}
}

@Override
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(
ConnectorSession session,
ConnectorTableHandle tableHandle,
ConnectorInsertTableHandle insertHandle,
Collection<Slice> fragments,
Collection<ComputedStatistics> computedStatistics,
List<ConnectorTableHandle> sourceTableHandles,
List<String> sourceTableFunctions)
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, boolean hasSourceTableFunctions)
{
Span span = startSpan("finishRefreshMaterializedView", tableHandle);
try (var _ = scopedSpan(span)) {
return delegate.finishRefreshMaterializedView(session, tableHandle, insertHandle, fragments, computedStatistics, sourceTableHandles, sourceTableFunctions);
return delegate.finishRefreshMaterializedView(session, tableHandle, insertHandle, fragments, computedStatistics, sourceTableHandles, hasForeignSourceTables, hasSourceTableFunctions);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,20 +748,13 @@ public CompletableFuture<?> refreshMaterializedView(ConnectorSession session, Sc
}

@Override
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, RetryMode retryMode, RefreshType refreshType)
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, RetryMode retryMode, RefreshType refreshType)
{
return new MockConnectorInsertTableHandle(((MockConnectorTableHandle) tableHandle).getTableName());
}

@Override
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(
ConnectorSession session,
ConnectorTableHandle tableHandle,
ConnectorInsertTableHandle insertHandle,
Collection<Slice> fragments,
Collection<ComputedStatistics> computedStatistics,
List<ConnectorTableHandle> sourceTableHandles,
List<String> sourceTableFunctions)
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, boolean hasSourceTableFunctions)
{
return Optional.empty();
}
Expand Down
12 changes: 12 additions & 0 deletions core/trino-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,18 @@
<oldVisibility>private</oldVisibility>
<newVisibility>public</newVisibility>
</item>
<item>
<ignore>true</ignore>
<code>java.method.numberOfParametersChanged</code>
<old>method io.trino.spi.connector.ConnectorInsertTableHandle io.trino.spi.connector.ConnectorMetadata::beginRefreshMaterializedView(io.trino.spi.connector.ConnectorSession, io.trino.spi.connector.ConnectorTableHandle, java.util.List&lt;io.trino.spi.connector.ConnectorTableHandle&gt;, io.trino.spi.connector.RetryMode, io.trino.spi.RefreshType)</old>
<new>method io.trino.spi.connector.ConnectorInsertTableHandle io.trino.spi.connector.ConnectorMetadata::beginRefreshMaterializedView(io.trino.spi.connector.ConnectorSession, io.trino.spi.connector.ConnectorTableHandle, java.util.List&lt;io.trino.spi.connector.ConnectorTableHandle&gt;, boolean, io.trino.spi.connector.RetryMode, io.trino.spi.RefreshType)</new>
</item>
<item>
<ignore>true</ignore>
<code>java.method.numberOfParametersChanged</code>
<old>method java.util.Optional&lt;io.trino.spi.connector.ConnectorOutputMetadata&gt; io.trino.spi.connector.ConnectorMetadata::finishRefreshMaterializedView(io.trino.spi.connector.ConnectorSession, io.trino.spi.connector.ConnectorTableHandle, io.trino.spi.connector.ConnectorInsertTableHandle, java.util.Collection&lt;io.airlift.slice.Slice&gt;, java.util.Collection&lt;io.trino.spi.statistics.ComputedStatistics&gt;, java.util.List&lt;io.trino.spi.connector.ConnectorTableHandle&gt;, java.util.List&lt;java.lang.String&gt;)</old>
<new>method java.util.Optional&lt;io.trino.spi.connector.ConnectorOutputMetadata&gt; io.trino.spi.connector.ConnectorMetadata::finishRefreshMaterializedView(io.trino.spi.connector.ConnectorSession, io.trino.spi.connector.ConnectorTableHandle, io.trino.spi.connector.ConnectorInsertTableHandle, java.util.Collection&lt;io.airlift.slice.Slice&gt;, java.util.Collection&lt;io.trino.spi.statistics.ComputedStatistics&gt;, java.util.List&lt;io.trino.spi.connector.ConnectorTableHandle&gt;, boolean, boolean)</new>
</item>
</differences>
</revapi.differences>
</analysisConfiguration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,13 @@ default CompletableFuture<?> refreshMaterializedView(ConnectorSession session, S
* {@code refreshType} is a signal from the engine to the connector whether the MV refresh could be done incrementally or only fully, based on the plan.
* The connector is not obligated to perform the refresh in the fashion prescribed by {@code refreshType}, this is merely a hint from the engine that the refresh could be append-only.
*/
default ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, RetryMode retryMode, RefreshType refreshType)
default ConnectorInsertTableHandle beginRefreshMaterializedView(
ConnectorSession session,
ConnectorTableHandle tableHandle,
List<ConnectorTableHandle> sourceTableHandles,
boolean hasForeignSourceTables,
RetryMode retryMode,
RefreshType refreshType)
Comment on lines +819 to +821
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider combining hasForeighSourceTable and RefreshType.

{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support materialized views");
}
Expand All @@ -827,7 +833,8 @@ default Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(
Collection<Slice> fragments,
Collection<ComputedStatistics> computedStatistics,
List<ConnectorTableHandle> sourceTableHandles,
List<String> sourceTableFunctions)
boolean hasForeignSourceTables,
boolean hasSourceTableFunctions)
{
throw new TrinoException(GENERIC_INTERNAL_ERROR, "ConnectorMetadata beginRefreshMaterializedView() is implemented without finishRefreshMaterializedView()");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,32 +622,18 @@ public CompletableFuture<?> refreshMaterializedView(ConnectorSession session, Sc
}

@Override
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, RetryMode retryMode, RefreshType refreshType)
public ConnectorInsertTableHandle beginRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, RetryMode retryMode, RefreshType refreshType)
{
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(classLoader)) {
return delegate.beginRefreshMaterializedView(session, tableHandle, sourceTableHandles, retryMode, refreshType);
return delegate.beginRefreshMaterializedView(session, tableHandle, sourceTableHandles, hasForeignSourceTables, retryMode, refreshType);
}
}

@Override
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(
ConnectorSession session,
ConnectorTableHandle tableHandle,
ConnectorInsertTableHandle insertHandle,
Collection<Slice> fragments,
Collection<ComputedStatistics> computedStatistics,
List<ConnectorTableHandle> sourceTableHandles,
List<String> sourceTableFunctions)
{
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(classLoader)) {
return delegate.finishRefreshMaterializedView(
session,
tableHandle,
insertHandle,
fragments,
computedStatistics,
sourceTableHandles,
sourceTableFunctions);
public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(ConnectorSession session, ConnectorTableHandle tableHandle, ConnectorInsertTableHandle insertHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics, List<ConnectorTableHandle> sourceTableHandles, boolean hasForeignSourceTables, boolean hasSourceTableFunctions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this chopped down as there are so many args.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do that in any of these forwarding classes since the parameter names aren't important to read

{
try (ThreadContextClassLoader _ = new ThreadContextClassLoader(classLoader)) {
return delegate.finishRefreshMaterializedView(session, tableHandle, insertHandle, fragments, computedStatistics, sourceTableHandles, hasForeignSourceTables, hasSourceTableFunctions);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.trino.spi.PageSorter;
import io.trino.spi.catalog.CatalogName;
import io.trino.spi.classloader.ThreadContextClassLoader;
import io.trino.spi.connector.CatalogHandle;
import io.trino.spi.connector.Connector;
import io.trino.spi.connector.ConnectorContext;
import io.trino.spi.connector.ConnectorFactory;
Expand Down Expand Up @@ -92,7 +91,6 @@ public static Connector createConnector(
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
binder.bind(CatalogHandle.class).toInstance(context.getCatalogHandle());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
binder.bind(PageSorter.class).toInstance(context.getPageSorter());
},
Expand Down
Loading
Loading