Skip to content

Commit

Permalink
Simplify MetadataManager::getMaterializedView
Browse files Browse the repository at this point in the history
Mixing handling of absence of object and catalog security in one 'if'
block was misleading. These two things are separate and unrelated so
the best if they handled in separately.
  • Loading branch information
kokosing committed Nov 21, 2023
1 parent ccf6b62 commit b4d1517
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1605,11 +1605,13 @@ public boolean isMaterializedView(Session session, QualifiedObjectName viewName)
public Optional<MaterializedViewDefinition> getMaterializedView(Session session, QualifiedObjectName viewName)
{
Optional<ConnectorMaterializedViewDefinition> connectorView = getMaterializedViewInternal(session, viewName);
if (connectorView.isEmpty() || isCatalogManagedSecurity(session, viewName.getCatalogName())) {
return connectorView.map(view -> {
String runAsUser = view.getOwner().orElseThrow(() -> new TrinoException(INVALID_VIEW, "Owner not set for a run-as invoker view: " + viewName));
return createMaterializedViewDefinition(view, Identity.ofUser(runAsUser));
});
if (connectorView.isEmpty()) {
return Optional.empty();
}

if (isCatalogManagedSecurity(session, viewName.getCatalogName())) {
String runAsUser = connectorView.get().getOwner().orElseThrow(() -> new TrinoException(INVALID_VIEW, "Owner not set for a run-as invoker view: " + viewName));
return Optional.of(createMaterializedViewDefinition(connectorView.get(), Identity.ofUser(runAsUser)));
}

Identity runAsIdentity = systemSecurityMetadata.getViewRunAsIdentity(session, viewName.asCatalogSchemaTableName())
Expand Down

0 comments on commit b4d1517

Please sign in to comment.