Search in sources :

Example 76 with QualifiedObjectName

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);
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 77 with QualifiedObjectName

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();
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 78 with QualifiedObjectName

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();
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 79 with QualifiedObjectName

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());
}
Also used : Arrays(java.util.Arrays) VIEWS(io.trino.connector.informationschema.InformationSchemaTable.VIEWS) TABLES(io.trino.connector.informationschema.InformationSchemaTable.TABLES) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ENGLISH(java.util.Locale.ENGLISH) MetadataUtil.findColumnMetadata(io.trino.metadata.MetadataUtil.findColumnMetadata) TABLE_REDIRECTION_ERROR(io.trino.spi.StandardErrorCode.TABLE_REDIRECTION_ERROR) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Range(io.trino.spi.predicate.Range) ROLE_AUTHORIZATION_DESCRIPTORS(io.trino.connector.informationschema.InformationSchemaTable.ROLE_AUTHORIZATION_DESCRIPTORS) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Domain(io.trino.spi.predicate.Domain) EquatableValueSet(io.trino.spi.predicate.EquatableValueSet) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) LimitApplicationResult(io.trino.spi.connector.LimitApplicationResult) SchemaTableName(io.trino.spi.connector.SchemaTableName) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) INFORMATION_SCHEMA(io.trino.connector.informationschema.InformationSchemaTable.INFORMATION_SCHEMA) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) Session(io.trino.Session) Constraint(io.trino.spi.connector.Constraint) Slice(io.airlift.slice.Slice) FullConnectorSession(io.trino.FullConnectorSession) NullableValue(io.trino.spi.predicate.NullableValue) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TABLE_PRIVILEGES(io.trino.connector.informationschema.InformationSchemaTable.TABLE_PRIVILEGES) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) COLUMNS(io.trino.connector.informationschema.InformationSchemaTable.COLUMNS) QualifiedTablePrefix(io.trino.metadata.QualifiedTablePrefix) ConstraintApplicationResult(io.trino.spi.connector.ConstraintApplicationResult) ConnectorSession(io.trino.spi.connector.ConnectorSession) TupleDomain(io.trino.spi.predicate.TupleDomain) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Metadata(io.trino.metadata.Metadata) SortedRangeSet(io.trino.spi.predicate.SortedRangeSet) ImmutableSet(com.google.common.collect.ImmutableSet) EquatableValueSet(io.trino.spi.predicate.EquatableValueSet) Set(java.util.Set) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) SortedRangeSet(io.trino.spi.predicate.SortedRangeSet) TrinoException(io.trino.spi.TrinoException) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Session(io.trino.Session) FullConnectorSession(io.trino.FullConnectorSession) ConnectorSession(io.trino.spi.connector.ConnectorSession) FullConnectorSession(io.trino.FullConnectorSession)

Example 80 with QualifiedObjectName

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;
}
Also used : TrinoException(io.trino.spi.TrinoException) SystemTable(io.trino.spi.connector.SystemTable) QualifiedObjectName(io.trino.metadata.QualifiedObjectName)

Aggregations

QualifiedObjectName (io.trino.metadata.QualifiedObjectName)142 ViewExpression (io.trino.spi.security.ViewExpression)51 Test (org.testng.annotations.Test)51 Test (org.junit.jupiter.api.Test)41 Session (io.trino.Session)40 TableHandle (io.trino.metadata.TableHandle)33 MetadataUtil.createQualifiedObjectName (io.trino.metadata.MetadataUtil.createQualifiedObjectName)24 Optional (java.util.Optional)20 Metadata (io.trino.metadata.Metadata)17 Map (java.util.Map)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 ImmutableList (com.google.common.collect.ImmutableList)15 List (java.util.List)15 ImmutableMap (com.google.common.collect.ImmutableMap)14 TrinoException (io.trino.spi.TrinoException)14 ImmutableSet (com.google.common.collect.ImmutableSet)13 ColumnHandle (io.trino.spi.connector.ColumnHandle)13 Type (io.trino.spi.type.Type)11 Set (java.util.Set)11 CatalogName (io.trino.connector.CatalogName)10