use of io.trino.metadata.QualifiedObjectName 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.metadata.QualifiedObjectName in project trino by trinodb.
the class TableCommentSystemTable method getComment.
private Optional<String> getComment(Session session, QualifiedTablePrefix prefix, SchemaTableName name, Map<SchemaTableName, ViewInfo> views, Map<SchemaTableName, ViewInfo> materializedViews) {
ViewInfo materializedViewDefinition = materializedViews.get(name);
if (materializedViewDefinition != null) {
return materializedViewDefinition.getComment();
}
ViewInfo viewInfo = views.get(name);
if (viewInfo != null) {
return viewInfo.getComment();
}
QualifiedObjectName tableName = new QualifiedObjectName(prefix.getCatalogName(), name.getSchemaName(), name.getTableName());
return metadata.getRedirectionAwareTableHandle(session, tableName).getTableHandle().map(handle -> metadata.getTableMetadata(session, handle)).map(metadata -> metadata.getMetadata().getComment()).orElseGet(() -> {
// A previously listed table might have been dropped concurrently
LOG.warn("Failed to get metadata for table: %s", name);
return Optional.empty();
});
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class ExtractSpatialJoins method loadKdbTree.
private static KdbTree loadKdbTree(String tableName, Session session, Metadata metadata, SplitManager splitManager, PageSourceManager pageSourceManager) {
QualifiedObjectName name = toQualifiedObjectName(tableName, session.getCatalog().get(), session.getSchema().get());
TableHandle tableHandle = metadata.getTableHandle(session, name).orElseThrow(() -> new TrinoException(INVALID_SPATIAL_PARTITIONING, format("Table not found: %s", name)));
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
List<ColumnHandle> visibleColumnHandles = columnHandles.values().stream().filter(handle -> !metadata.getColumnMetadata(session, tableHandle, handle).isHidden()).collect(toImmutableList());
checkSpatialPartitioningTable(visibleColumnHandles.size() == 1, "Expected single column for table %s, but found %s columns", name, columnHandles.size());
ColumnHandle kdbTreeColumn = Iterables.getOnlyElement(visibleColumnHandles);
Optional<KdbTree> kdbTree = Optional.empty();
try (SplitSource splitSource = splitManager.getSplits(session, tableHandle, UNGROUPED_SCHEDULING, EMPTY, alwaysTrue())) {
while (!Thread.currentThread().isInterrupted()) {
SplitBatch splitBatch = getFutureValue(splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), 1000));
List<Split> splits = splitBatch.getSplits();
for (Split split : splits) {
try (ConnectorPageSource pageSource = pageSourceManager.createPageSource(session, split, tableHandle, ImmutableList.of(kdbTreeColumn), DynamicFilter.EMPTY)) {
do {
getFutureValue(pageSource.isBlocked());
Page page = pageSource.getNextPage();
if (page != null && page.getPositionCount() > 0) {
checkSpatialPartitioningTable(kdbTree.isEmpty(), "Expected exactly one row for table %s, but found more", name);
checkSpatialPartitioningTable(page.getPositionCount() == 1, "Expected exactly one row for table %s, but found %s rows", name, page.getPositionCount());
String kdbTreeJson = VARCHAR.getSlice(page.getBlock(0), 0).toStringUtf8();
try {
kdbTree = Optional.of(KdbTreeUtils.fromJson(kdbTreeJson));
} catch (IllegalArgumentException e) {
checkSpatialPartitioningTable(false, "Invalid JSON string for KDB tree: %s", e.getMessage());
}
}
} while (!pageSource.isFinished());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
if (splitBatch.isLastBatch()) {
break;
}
}
}
checkSpatialPartitioningTable(kdbTree.isPresent(), "Expected exactly one row for table %s, but got none", name);
return kdbTree.get();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class SetPropertiesTask method execute.
@Override
public ListenableFuture<Void> execute(SetProperties statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName objectName = createQualifiedObjectName(session, statement, statement.getName());
if (statement.getType() == TABLE) {
Map<String, Optional<Object>> properties = tablePropertyManager.getNullableProperties(getRequiredCatalogHandle(plannerContext.getMetadata(), session, statement, objectName.getCatalogName()), statement.getProperties(), session, plannerContext, accessControl, parameterExtractor(statement, parameters), false);
setTableProperties(statement, objectName, session, properties);
} else if (statement.getType() == MATERIALIZED_VIEW) {
Map<String, Optional<Object>> properties = materializedViewPropertyManager.getNullableProperties(getRequiredCatalogHandle(plannerContext.getMetadata(), session, statement, objectName.getCatalogName()), statement.getProperties(), session, plannerContext, accessControl, parameterExtractor(statement, parameters), false);
setMaterializedViewProperties(statement, objectName, session, properties);
} else {
throw semanticException(NOT_SUPPORTED, statement, "Unsupported target type: %s", statement.getType());
}
return immediateVoidFuture();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class SetTableAuthorizationTask method execute.
@Override
public ListenableFuture<Void> execute(SetTableAuthorization statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getSource());
getRequiredCatalogHandle(metadata, session, statement, tableName.getCatalogName());
if (metadata.getTableHandle(session, tableName).isEmpty()) {
throw semanticException(TABLE_NOT_FOUND, statement, "Table '%s' does not exist", tableName);
}
TrinoPrincipal principal = createPrincipal(statement.getPrincipal());
checkRoleExists(session, statement, metadata, principal, Optional.of(tableName.getCatalogName()).filter(catalog -> metadata.isCatalogManagedSecurity(session, catalog)));
accessControl.checkCanSetTableAuthorization(session.toSecurityContext(), tableName, principal);
metadata.setTableAuthorization(session, tableName.asCatalogSchemaTableName(), principal);
return immediateVoidFuture();
}
Aggregations