use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRenameMaterializedViewTask method testRenameMaterializedViewTargetViewExists.
@Test
public void testRenameMaterializedViewTargetViewExists() {
QualifiedObjectName materializedViewName = qualifiedObjectName("existing_materialized_view");
metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
QualifiedName viewName = qualifiedName("existing_view");
metadata.createView(testSession, QualifiedObjectName.valueOf(viewName.toString()), someView(), false);
assertTrinoExceptionThrownBy(() -> getFutureValue(executeRenameMaterializedView(asQualifiedName(materializedViewName), viewName))).hasErrorCode(TABLE_ALREADY_EXISTS).hasMessage("Target materialized view '%s' does not exist, but a view with that name exists.", viewName);
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRenameTableTask method testRenameExistingTable.
@Test
public void testRenameExistingTable() {
QualifiedObjectName tableName = qualifiedObjectName("existing_table");
QualifiedObjectName newTableName = qualifiedObjectName("existing_view_new");
metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
getFutureValue(executeRenameTable(asQualifiedName(tableName), asQualifiedName(newTableName), false));
assertThat(metadata.getTableHandle(testSession, tableName)).isEmpty();
assertThat(metadata.getTableHandle(testSession, newTableName)).isPresent();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class TestRenameViewTask method testRenameExistingView.
@Test
public void testRenameExistingView() {
QualifiedObjectName viewName = qualifiedObjectName("existing_view");
QualifiedObjectName newViewName = qualifiedObjectName("existing_view_new");
metadata.createView(testSession, viewName, someView(), false);
getFutureValue(executeRenameView(asQualifiedName(viewName), asQualifiedName(newViewName)));
assertThat(metadata.isView(testSession, viewName)).isFalse();
assertThat(metadata.isView(testSession, newViewName)).isTrue();
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class InformationSchemaMetadata method calculatePrefixesWithTableName.
private Set<QualifiedTablePrefix> calculatePrefixesWithTableName(InformationSchemaTable informationSchemaTable, ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
Session session = ((FullConnectorSession) connectorSession).getSession();
Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE);
if (tables.isPresent()) {
return prefixes.stream().peek(prefix -> verify(prefix.asQualifiedObjectName().isEmpty())).flatMap(prefix -> prefix.getSchemaName().map(schemaName -> Stream.of(prefix)).orElseGet(() -> listSchemaNames(session))).flatMap(prefix -> tables.get().stream().filter(this::isLowerCase).map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))).filter(objectName -> {
if (!isColumnsEnumeratingTable(informationSchemaTable) || metadata.isMaterializedView(session, objectName) || metadata.isView(session, objectName)) {
return true;
}
// This is a columns enumerating table and the object is not a view
try {
// filtering in case the source table does not exist or there is a problem with redirection.
return metadata.getRedirectionAwareTableHandle(session, objectName).getTableHandle().isPresent();
} catch (TrinoException e) {
if (e.getErrorCode().equals(TABLE_REDIRECTION_ERROR.toErrorCode())) {
// Ignore redirection errors for listing, treat as if the table does not exist
return false;
}
throw e;
}
}).filter(objectName -> predicate.isEmpty() || predicate.get().test(asFixedValues(objectName))).map(QualifiedObjectName::asQualifiedTablePrefix).collect(toImmutableSet());
}
if (predicate.isEmpty() || !isColumnsEnumeratingTable(informationSchemaTable)) {
return prefixes;
}
return prefixes.stream().flatMap(prefix -> Stream.concat(metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())).filter(objectName -> predicate.get().test(asFixedValues(objectName))).map(QualifiedObjectName::asQualifiedTablePrefix).collect(toImmutableSet());
}
use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.
the class CoordinatorSystemTablesProvider method getSystemTable.
@Override
public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTableName tableName) {
Optional<SystemTable> staticSystemTable = staticProvider.getSystemTable(session, tableName);
if (staticSystemTable.isPresent()) {
return staticSystemTable;
}
if (!isCoordinatorTransaction(session)) {
// this is a session from another coordinator, so there are no dynamic tables here for that session
return Optional.empty();
}
Optional<SystemTable> systemTable = metadata.getSystemTable(((FullConnectorSession) session).getSession(), new QualifiedObjectName(catalogName, tableName.getSchemaName(), tableName.getTableName()));
// dynamic tables require access to the transaction and thus can only run on the current coordinator
if (systemTable.isPresent() && systemTable.get().getDistribution() != SINGLE_COORDINATOR) {
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Distribution for dynamic system table must be " + SINGLE_COORDINATOR);
}
return systemTable;
}
Aggregations