@@ -665,7 +665,7 @@ public List<TableColumnsMetadata> listTableColumns(Session session, QualifiedTab
665
665
666
666
try {
667
667
return Optional .<RelationColumnsMetadata >empty ()
668
- .or (() -> getMaterializedViewInternal (session , objectName )
668
+ .or (() -> getMaterializedViewInternal (session , getRedirectedTableName ( session , objectName , Optional . empty (), Optional . empty ()) )
669
669
.map (materializedView -> RelationColumnsMetadata .forMaterializedView (schemaTableName , materializedView .getColumns ())))
670
670
.or (() -> getViewInternal (session , objectName )
671
671
.map (view -> RelationColumnsMetadata .forView (schemaTableName , view .getColumns ())))
@@ -1649,13 +1649,14 @@ public void createMaterializedView(
1649
1649
@ Override
1650
1650
public void dropMaterializedView (Session session , QualifiedObjectName viewName )
1651
1651
{
1652
- CatalogMetadata catalogMetadata = getCatalogMetadataForWrite (session , viewName .catalogName ());
1652
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1653
+ CatalogMetadata catalogMetadata = getCatalogMetadataForWrite (session , targetViewName .catalogName ());
1653
1654
CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle ();
1654
1655
ConnectorMetadata metadata = catalogMetadata .getMetadata (session );
1655
1656
1656
- metadata .dropMaterializedView (session .toConnectorSession (catalogHandle ), viewName .asSchemaTableName ());
1657
+ metadata .dropMaterializedView (session .toConnectorSession (catalogHandle ), targetViewName .asSchemaTableName ());
1657
1658
if (catalogMetadata .getSecurityManagement () == SYSTEM ) {
1658
- systemSecurityMetadata .tableDropped (session , viewName .asCatalogSchemaTableName ());
1659
+ systemSecurityMetadata .tableDropped (session , targetViewName .asCatalogSchemaTableName ());
1659
1660
}
1660
1661
}
1661
1662
@@ -1737,31 +1738,34 @@ public Map<QualifiedObjectName, ViewInfo> getMaterializedViews(Session session,
1737
1738
@ Override
1738
1739
public boolean isMaterializedView (Session session , QualifiedObjectName viewName )
1739
1740
{
1740
- return getMaterializedViewInternal (session , viewName ).isPresent ();
1741
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1742
+ return getMaterializedViewInternal (session , targetViewName ).isPresent ();
1741
1743
}
1742
1744
1743
1745
@ Override
1744
1746
public Optional <MaterializedViewDefinition > getMaterializedView (Session session , QualifiedObjectName viewName )
1745
1747
{
1746
- Optional <ConnectorMaterializedViewDefinition > connectorView = getMaterializedViewInternal (session , viewName );
1748
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1749
+ Optional <ConnectorMaterializedViewDefinition > connectorView = getMaterializedViewInternal (session , targetViewName );
1747
1750
if (connectorView .isEmpty ()) {
1748
1751
return Optional .empty ();
1749
1752
}
1750
1753
1751
- if (isCatalogManagedSecurity (session , viewName .catalogName ())) {
1754
+ if (isCatalogManagedSecurity (session , targetViewName .catalogName ())) {
1752
1755
String runAsUser = connectorView .get ().getOwner ().orElseThrow (() -> new TrinoException (INVALID_VIEW , "Owner not set for a run-as invoker view: " + viewName ));
1753
- return Optional .of (createMaterializedViewDefinition (connectorView .get (), Identity .ofUser (runAsUser )));
1756
+ return Optional .of (createMaterializedViewDefinition (targetViewName , connectorView .get (), Identity .ofUser (runAsUser )));
1754
1757
}
1755
1758
1756
- Identity runAsIdentity = systemSecurityMetadata .getViewRunAsIdentity (session , viewName .asCatalogSchemaTableName ())
1759
+ Identity runAsIdentity = systemSecurityMetadata .getViewRunAsIdentity (session , targetViewName .asCatalogSchemaTableName ())
1757
1760
.or (() -> connectorView .get ().getOwner ().map (Identity ::ofUser ))
1758
1761
.orElseThrow (() -> new TrinoException (NOT_SUPPORTED , "Materialized view does not have an owner: " + viewName ));
1759
- return Optional .of (createMaterializedViewDefinition (connectorView .get (), runAsIdentity ));
1762
+ return Optional .of (createMaterializedViewDefinition (targetViewName , connectorView .get (), runAsIdentity ));
1760
1763
}
1761
1764
1762
- private static MaterializedViewDefinition createMaterializedViewDefinition (ConnectorMaterializedViewDefinition view , Identity runAsIdentity )
1765
+ private static MaterializedViewDefinition createMaterializedViewDefinition (QualifiedObjectName name , ConnectorMaterializedViewDefinition view , Identity runAsIdentity )
1763
1766
{
1764
1767
return new MaterializedViewDefinition (
1768
+ name ,
1765
1769
view .getOriginalSql (),
1766
1770
view .getCatalog (),
1767
1771
view .getSchema (),
@@ -1814,14 +1818,15 @@ public Map<String, Object> getMaterializedViewProperties(Session session, Qualif
1814
1818
@ Override
1815
1819
public MaterializedViewFreshness getMaterializedViewFreshness (Session session , QualifiedObjectName viewName )
1816
1820
{
1817
- Optional <CatalogMetadata > catalog = getOptionalCatalogMetadata (session , viewName .catalogName ());
1821
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1822
+ Optional <CatalogMetadata > catalog = getOptionalCatalogMetadata (session , targetViewName .catalogName ());
1818
1823
if (catalog .isPresent ()) {
1819
1824
CatalogMetadata catalogMetadata = catalog .get ();
1820
- CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle (session , viewName , Optional .empty (), Optional .empty ());
1825
+ CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle (session , targetViewName , Optional .empty (), Optional .empty ());
1821
1826
ConnectorMetadata metadata = catalogMetadata .getMetadataFor (session , catalogHandle );
1822
1827
1823
1828
ConnectorSession connectorSession = session .toConnectorSession (catalogHandle );
1824
- return metadata .getMaterializedViewFreshness (connectorSession , viewName .asSchemaTableName ());
1829
+ return metadata .getMaterializedViewFreshness (connectorSession , targetViewName .asSchemaTableName ());
1825
1830
}
1826
1831
return new MaterializedViewFreshness (STALE , Optional .empty ());
1827
1832
}
0 commit comments