Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small MV improvements #13574

Merged
merged 4 commits into from
Aug 12, 2022
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 @@ -1584,7 +1584,8 @@ private Optional<TableFunctionMetadata> resolveTableFunction(TableFunctionInvoca
name.getSchemaFunctionName().getFunctionName()));
return Optional.of(new TableFunctionMetadata(catalogHandle, resolved.get()));
}
} return Optional.empty();
}
return Optional.empty();
}

private Map<String, Argument> analyzeArguments(Node node, List<ArgumentSpecification> argumentSpecifications, List<TableFunctionArgument> arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.io.MoreFiles.deleteRecursively;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void testPageSinkStats()
}
}
Page page = pageBuilder.build();
pageSink.appendPage(page);
pageSink.appendPage(page).get(10, TimeUnit.SECONDS);

JsonCodec<DataFileInfo> dataFileInfoCodec = new JsonCodecFactory().jsonCodec(DataFileInfo.class);
Collection<Slice> fragments = getFutureValue(pageSink.finish());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2078,8 +2078,7 @@ public Optional<ConnectorOutputMetadata> finishRefreshMaterializedView(

String dependencies = sourceTableHandles.stream()
.map(handle -> (IcebergTableHandle) handle)
.filter(handle -> handle.getSnapshotId().isPresent())
.map(handle -> handle.getSchemaTableName() + "=" + handle.getSnapshotId().get())
.map(handle -> handle.getSchemaTableName() + "=" + handle.getSnapshotId().map(Object.class::cast).orElse(""))
.distinct()
.collect(joining(","));

Expand Down Expand Up @@ -2168,12 +2167,24 @@ public boolean isTableCurrent(ConnectorSession session, ConnectorTableHandle tab
@Override
public MaterializedViewFreshness getMaterializedViewFreshness(ConnectorSession session, SchemaTableName materializedViewName)
{
Map<String, Optional<TableToken>> refreshStateMap = getMaterializedViewToken(session, materializedViewName);
if (refreshStateMap.isEmpty()) {
Optional<ConnectorMaterializedViewDefinition> materializedViewDefinition = getMaterializedView(session, materializedViewName);
if (materializedViewDefinition.isEmpty()) {
// View not found, might have been concurrently deleted
return new MaterializedViewFreshness(false);
}

for (Map.Entry<String, Optional<TableToken>> entry : refreshStateMap.entrySet()) {
SchemaTableName storageTableName = materializedViewDefinition.get().getStorageTable()
.map(CatalogSchemaTableName::getSchemaTableName)
.orElseThrow(() -> new IllegalStateException("Storage table missing in definition of materialized view " + materializedViewName));

Table icebergTable = catalog.loadTable(session, storageTableName);
String dependsOnTables = icebergTable.currentSnapshot().summary().getOrDefault(DEPENDS_ON_TABLES, "");
if (dependsOnTables.isEmpty()) {
// Information missing
return new MaterializedViewFreshness(false);
}
Map<String, String> tableToSnapshotIdMap = Splitter.on(',').withKeyValueSeparator('=').split(dependsOnTables);
for (Map.Entry<String, String> entry : tableToSnapshotIdMap.entrySet()) {
List<String> strings = Splitter.on(".").splitToList(entry.getKey());
if (strings.size() == 3) {
strings = strings.subList(1, 3);
Expand All @@ -2189,7 +2200,14 @@ else if (strings.size() != 2) {
if (tableHandle == null) {
throw new MaterializedViewNotFoundException(materializedViewName);
}
if (!isTableCurrent(session, tableHandle, entry.getValue())) {
Optional<TableToken> tableToken;
if (entry.getValue().isEmpty()) {
tableToken = Optional.empty();
}
else {
tableToken = Optional.of(new TableToken(Long.parseLong(entry.getValue())));
}
if (!isTableCurrent(session, tableHandle, tableToken)) {
return new MaterializedViewFreshness(false);
}
}
Expand All @@ -2214,29 +2232,6 @@ public void setColumnComment(ConnectorSession session, ConnectorTableHandle tabl
catalog.updateColumnComment(session, ((IcebergTableHandle) tableHandle).getSchemaTableName(), ((IcebergColumnHandle) column).getColumnIdentity(), comment);
}

private Map<String, Optional<TableToken>> getMaterializedViewToken(ConnectorSession session, SchemaTableName name)
{
Map<String, Optional<TableToken>> viewToken = new HashMap<>();
Optional<ConnectorMaterializedViewDefinition> materializedViewDefinition = getMaterializedView(session, name);
if (materializedViewDefinition.isEmpty()) {
return viewToken;
}

SchemaTableName storageTableName = materializedViewDefinition.get().getStorageTable()
.map(CatalogSchemaTableName::getSchemaTableName)
.orElseThrow(() -> new IllegalStateException("Storage table missing in definition of materialized view " + name));

Table icebergTable = catalog.loadTable(session, storageTableName);
String dependsOnTables = icebergTable.currentSnapshot().summary().getOrDefault(DEPENDS_ON_TABLES, "");
if (!dependsOnTables.isEmpty()) {
Map<String, String> tableToSnapshotIdMap = Splitter.on(',').withKeyValueSeparator('=').split(dependsOnTables);
for (Map.Entry<String, String> entry : tableToSnapshotIdMap.entrySet()) {
viewToken.put(entry.getKey(), Optional.of(new TableToken(Long.parseLong(entry.getValue()))));
}
}
return viewToken;
}

@Override
public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session, SchemaTableName tableName)
{
Expand Down