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 @@ -162,6 +162,7 @@ public synchronized TrinoCatalog create(ConnectorIdentity identity)
uniqueTableLocation,
caseInsensitiveNameMatching,
remoteNamespaceMappingCache,
remoteTableMappingCache);
remoteTableMappingCache,
viewEndpointsEnabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class TrinoRestCatalog
private final boolean caseInsensitiveNameMatching;
private final Cache<Namespace, Namespace> remoteNamespaceMappingCache;
private final Cache<TableIdentifier, TableIdentifier> remoteTableMappingCache;
private final boolean viewEndpointsEnabled;

private final Cache<SchemaTableName, BaseTable> tableCache = EvictableCacheBuilder.newBuilder()
.maximumSize(PER_QUERY_CACHE_SIZE)
Expand All @@ -134,7 +135,8 @@ public TrinoRestCatalog(
boolean useUniqueTableLocation,
boolean caseInsensitiveNameMatching,
Cache<Namespace, Namespace> remoteNamespaceMappingCache,
Cache<TableIdentifier, TableIdentifier> remoteTableMappingCache)
Cache<TableIdentifier, TableIdentifier> remoteTableMappingCache,
boolean viewEndpointsEnabled)
{
this.restSessionCatalog = requireNonNull(restSessionCatalog, "restSessionCatalog is null");
this.catalogName = requireNonNull(catalogName, "catalogName is null");
Expand All @@ -147,6 +149,7 @@ public TrinoRestCatalog(
this.caseInsensitiveNameMatching = caseInsensitiveNameMatching;
this.remoteNamespaceMappingCache = requireNonNull(remoteNamespaceMappingCache, "remoteNamespaceMappingCache is null");
this.remoteTableMappingCache = requireNonNull(remoteTableMappingCache, "remoteTableMappingCache is null");
this.viewEndpointsEnabled = viewEndpointsEnabled;
}

@Override
Expand Down Expand Up @@ -284,16 +287,18 @@ public List<TableInfo> listTables(ConnectorSession session, Optional<String> nam
}).stream()
.map(id -> new TableInfo(SchemaTableName.schemaTableName(toSchemaName(id.namespace()), id.name()), TableInfo.ExtendedRelationType.TABLE))
.forEach(tables::add);
listTableIdentifiers(restNamespace, () -> {
try {
return restSessionCatalog.listViews(sessionContext, toRemoteNamespace(session, restNamespace));
}
catch (RESTException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, "Failed to list views", e);
}
}).stream()
.map(id -> new TableInfo(SchemaTableName.schemaTableName(toSchemaName(id.namespace()), id.name()), TableInfo.ExtendedRelationType.OTHER_VIEW))
.forEach(tables::add);
if (viewEndpointsEnabled) {
listTableIdentifiers(restNamespace, () -> {
try {
return restSessionCatalog.listViews(sessionContext, toRemoteNamespace(session, restNamespace));
}
catch (RESTException e) {
throw new TrinoException(ICEBERG_CATALOG_ERROR, "Failed to list views", e);
}
}).stream()
.map(id -> new TableInfo(SchemaTableName.schemaTableName(toSchemaName(id.namespace()), id.name()), TableInfo.ExtendedRelationType.OTHER_VIEW))
.forEach(tables::add);
}
}
return tables.build();
}
Expand Down Expand Up @@ -323,6 +328,10 @@ public List<SchemaTableName> listIcebergTables(ConnectorSession session, Optiona
@Override
public List<SchemaTableName> listViews(ConnectorSession session, Optional<String> namespace)
{
if (!viewEndpointsEnabled) {
return ImmutableList.of();
}

SessionContext sessionContext = convert(session);
List<Namespace> namespaces = listNamespaces(session, namespace);

Expand Down Expand Up @@ -705,6 +714,10 @@ public Optional<ConnectorViewDefinition> getView(ConnectorSession session, Schem

private Optional<View> getIcebergView(ConnectorSession session, SchemaTableName viewName, boolean getCached)
{
if (!viewEndpointsEnabled) {
return Optional.empty();
}

try {
return Optional.of(restSessionCatalog.loadView(convert(session), toRemoteView(session, viewName, getCached)));
}
Expand Down Expand Up @@ -926,6 +939,10 @@ private TableIdentifier toRemoteView(ConnectorSession session, SchemaTableName s

private TableIdentifier findRemoteView(ConnectorSession session, TableIdentifier tableIdentifier)
{
if (!viewEndpointsEnabled) {
return tableIdentifier;
}

Namespace remoteNamespace = toRemoteNamespace(session, tableIdentifier.namespace());
List<TableIdentifier> tableIdentifiers;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ private static TrinoRestCatalog createTrinoRestCatalog(boolean useUniqueTableLoc
useUniqueTableLocations,
false,
EvictableCacheBuilder.newBuilder().expireAfterWrite(1000, MILLISECONDS).shareNothingWhenDisabled().build(),
EvictableCacheBuilder.newBuilder().expireAfterWrite(1000, MILLISECONDS).shareNothingWhenDisabled().build());
EvictableCacheBuilder.newBuilder().expireAfterWrite(1000, MILLISECONDS).shareNothingWhenDisabled().build(),
true);
}

@Test
Expand Down