use of io.trino.spi.connector.ConnectorTableSchema in project trino by trinodb.
the class InternalMetadataProvider method getRelationMetadata.
@Override
public Optional<ConnectorTableSchema> getRelationMetadata(ConnectorSession connectorSession, CatalogSchemaTableName tableName) {
Session session = ((FullConnectorSession) connectorSession).getSession();
QualifiedObjectName qualifiedName = new QualifiedObjectName(tableName.getCatalogName(), tableName.getSchemaTableName().getSchemaName(), tableName.getSchemaTableName().getTableName());
Optional<MaterializedViewDefinition> materializedView = metadataManager.getMaterializedView(session, qualifiedName);
if (materializedView.isPresent()) {
return Optional.of(new ConnectorTableSchema(tableName.getSchemaTableName(), toColumnSchema(materializedView.get().getColumns())));
}
Optional<ViewDefinition> view = metadataManager.getView(session, qualifiedName);
if (view.isPresent()) {
return Optional.of(new ConnectorTableSchema(tableName.getSchemaTableName(), toColumnSchema(view.get().getColumns())));
}
Optional<TableHandle> tableHandle = metadataManager.getTableHandle(session, qualifiedName);
if (tableHandle.isPresent()) {
return Optional.of(metadataManager.getTableSchema(session, tableHandle.get()).getTableSchema());
}
return Optional.empty();
}
use of io.trino.spi.connector.ConnectorTableSchema in project trino by trinodb.
the class MetadataManager method getTableSchema.
@Override
public TableSchema getTableSchema(Session session, TableHandle tableHandle) {
CatalogName catalogName = tableHandle.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
ConnectorTableSchema tableSchema = metadata.getTableSchema(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle());
return new TableSchema(catalogName, tableSchema);
}
use of io.trino.spi.connector.ConnectorTableSchema in project trino by trinodb.
the class ViewReaderUtil method coralTableRedirectionResolver.
private static CoralTableRedirectionResolver coralTableRedirectionResolver(ConnectorSession session, BiFunction<ConnectorSession, SchemaTableName, Optional<CatalogSchemaTableName>> tableRedirectionResolver, MetadataProvider metadataProvider) {
return schemaTableName -> tableRedirectionResolver.apply(session, schemaTableName).map(target -> {
ConnectorTableSchema tableSchema = metadataProvider.getRelationMetadata(session, target).orElseThrow(() -> new TableNotFoundException(target.getSchemaTableName(), format("%s is redirected to %s, but that relation cannot be found", schemaTableName, target)));
List<Column> columns = tableSchema.getColumns().stream().filter(columnSchema -> !columnSchema.isHidden()).map(columnSchema -> new Column(columnSchema.getName(), toHiveType(columnSchema.getType()), Optional.empty())).collect(toImmutableList());
Table table = Table.builder().setDatabaseName(schemaTableName.getSchemaName()).setTableName(schemaTableName.getTableName()).setTableType(EXTERNAL_TABLE.name()).setDataColumns(columns).withStorage(storage -> storage.setStorageFormat(fromHiveStorageFormat(TEXTFILE))).setOwner(Optional.empty()).build();
return toMetastoreApiTable(table);
});
}
Aggregations