@@ -664,7 +664,7 @@ public List<TableColumnsMetadata> listTableColumns(Session session, QualifiedTab
664
664
665
665
try {
666
666
return Optional .<RelationColumnsMetadata >empty ()
667
- .or (() -> getMaterializedViewInternal (session , objectName )
667
+ .or (() -> getMaterializedViewInternal (session , getRedirectedTableName ( session , objectName , Optional . empty (), Optional . empty ()) )
668
668
.map (materializedView -> RelationColumnsMetadata .forMaterializedView (schemaTableName , materializedView .getColumns ())))
669
669
.or (() -> getViewInternal (session , objectName )
670
670
.map (view -> RelationColumnsMetadata .forView (schemaTableName , view .getColumns ())))
@@ -1690,13 +1690,14 @@ public void createMaterializedView(
1690
1690
@ Override
1691
1691
public void dropMaterializedView (Session session , QualifiedObjectName viewName )
1692
1692
{
1693
- CatalogMetadata catalogMetadata = getCatalogMetadataForWrite (session , viewName .catalogName ());
1693
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1694
+ CatalogMetadata catalogMetadata = getCatalogMetadataForWrite (session , targetViewName .catalogName ());
1694
1695
CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle ();
1695
1696
ConnectorMetadata metadata = catalogMetadata .getMetadata (session );
1696
1697
1697
- metadata .dropMaterializedView (session .toConnectorSession (catalogHandle ), viewName .asSchemaTableName ());
1698
+ metadata .dropMaterializedView (session .toConnectorSession (catalogHandle ), targetViewName .asSchemaTableName ());
1698
1699
if (catalogMetadata .getSecurityManagement () == SYSTEM ) {
1699
- systemSecurityMetadata .tableDropped (session , viewName .asCatalogSchemaTableName ());
1700
+ systemSecurityMetadata .tableDropped (session , targetViewName .asCatalogSchemaTableName ());
1700
1701
}
1701
1702
}
1702
1703
@@ -1778,31 +1779,34 @@ public Map<QualifiedObjectName, ViewInfo> getMaterializedViews(Session session,
1778
1779
@ Override
1779
1780
public boolean isMaterializedView (Session session , QualifiedObjectName viewName )
1780
1781
{
1781
- return getMaterializedViewInternal (session , viewName ).isPresent ();
1782
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1783
+ return getMaterializedViewInternal (session , targetViewName ).isPresent ();
1782
1784
}
1783
1785
1784
1786
@ Override
1785
1787
public Optional <MaterializedViewDefinition > getMaterializedView (Session session , QualifiedObjectName viewName )
1786
1788
{
1787
- Optional <ConnectorMaterializedViewDefinition > connectorView = getMaterializedViewInternal (session , viewName );
1789
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1790
+ Optional <ConnectorMaterializedViewDefinition > connectorView = getMaterializedViewInternal (session , targetViewName );
1788
1791
if (connectorView .isEmpty ()) {
1789
1792
return Optional .empty ();
1790
1793
}
1791
1794
1792
- if (isCatalogManagedSecurity (session , viewName .catalogName ())) {
1795
+ if (isCatalogManagedSecurity (session , targetViewName .catalogName ())) {
1793
1796
String runAsUser = connectorView .get ().getOwner ().orElseThrow (() -> new TrinoException (INVALID_VIEW , "Owner not set for a run-as invoker view: " + viewName ));
1794
- return Optional .of (createMaterializedViewDefinition (connectorView .get (), Identity .ofUser (runAsUser )));
1797
+ return Optional .of (createMaterializedViewDefinition (targetViewName , connectorView .get (), Identity .ofUser (runAsUser )));
1795
1798
}
1796
1799
1797
- Identity runAsIdentity = systemSecurityMetadata .getViewRunAsIdentity (session , viewName .asCatalogSchemaTableName ())
1800
+ Identity runAsIdentity = systemSecurityMetadata .getViewRunAsIdentity (session , targetViewName .asCatalogSchemaTableName ())
1798
1801
.or (() -> connectorView .get ().getOwner ().map (Identity ::ofUser ))
1799
1802
.orElseThrow (() -> new TrinoException (NOT_SUPPORTED , "Materialized view does not have an owner: " + viewName ));
1800
- return Optional .of (createMaterializedViewDefinition (connectorView .get (), runAsIdentity ));
1803
+ return Optional .of (createMaterializedViewDefinition (targetViewName , connectorView .get (), runAsIdentity ));
1801
1804
}
1802
1805
1803
- private static MaterializedViewDefinition createMaterializedViewDefinition (ConnectorMaterializedViewDefinition view , Identity runAsIdentity )
1806
+ private static MaterializedViewDefinition createMaterializedViewDefinition (QualifiedObjectName name , ConnectorMaterializedViewDefinition view , Identity runAsIdentity )
1804
1807
{
1805
1808
return new MaterializedViewDefinition (
1809
+ name ,
1806
1810
view .getOriginalSql (),
1807
1811
view .getCatalog (),
1808
1812
view .getSchema (),
@@ -1855,14 +1859,15 @@ public Map<String, Object> getMaterializedViewProperties(Session session, Qualif
1855
1859
@ Override
1856
1860
public MaterializedViewFreshness getMaterializedViewFreshness (Session session , QualifiedObjectName viewName )
1857
1861
{
1858
- Optional <CatalogMetadata > catalog = getOptionalCatalogMetadata (session , viewName .catalogName ());
1862
+ QualifiedObjectName targetViewName = getRedirectedTableName (session , viewName , Optional .empty (), Optional .empty ());
1863
+ Optional <CatalogMetadata > catalog = getOptionalCatalogMetadata (session , targetViewName .catalogName ());
1859
1864
if (catalog .isPresent ()) {
1860
1865
CatalogMetadata catalogMetadata = catalog .get ();
1861
- CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle (session , viewName , Optional .empty (), Optional .empty ());
1866
+ CatalogHandle catalogHandle = catalogMetadata .getCatalogHandle (session , targetViewName , Optional .empty (), Optional .empty ());
1862
1867
ConnectorMetadata metadata = catalogMetadata .getMetadataFor (session , catalogHandle );
1863
1868
1864
1869
ConnectorSession connectorSession = session .toConnectorSession (catalogHandle );
1865
- return metadata .getMaterializedViewFreshness (connectorSession , viewName .asSchemaTableName ());
1870
+ return metadata .getMaterializedViewFreshness (connectorSession , targetViewName .asSchemaTableName ());
1866
1871
}
1867
1872
return new MaterializedViewFreshness (STALE , Optional .empty ());
1868
1873
}
0 commit comments