Search in sources :

Example 11 with QualifiedObjectName

use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.

the class BaseHiveConnectorTest method getTableMetadata.

private TableMetadata getTableMetadata(String catalog, String schema, String tableName) {
    Session session = getSession();
    Metadata metadata = getDistributedQueryRunner().getCoordinator().getMetadata();
    return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
        Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, schema, tableName));
        assertTrue(tableHandle.isPresent());
        return metadata.getTableMetadata(transactionSession, tableHandle.get());
    });
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TableMetadata(io.trino.metadata.TableMetadata) Metadata(io.trino.metadata.Metadata) InsertTableHandle(io.trino.metadata.InsertTableHandle) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) HiveQueryRunner.createBucketedSession(io.trino.plugin.hive.HiveQueryRunner.createBucketedSession) Session(io.trino.Session)

Example 12 with QualifiedObjectName

use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.

the class TestSetPropertiesTask method testSetMaterializedViewProperties.

@Test
public void testSetMaterializedViewProperties() {
    QualifiedObjectName materializedViewName = qualifiedObjectName("test_materialized_view");
    metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
    // set all properties to non-DEFAULT values and check the results
    executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME), new LongLiteral("111")), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME), new StringLiteral("abc")))));
    assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_1_NAME, 111L, MATERIALIZED_VIEW_PROPERTY_2_NAME, "abc"));
    // set all properties to DEFAULT and check the results
    executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME)), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME)))));
    // since the default value of property 1 is null, property 1 should not appear in the result, whereas property 2 should appear in
    // the result with its (non-null) default value
    assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_2_NAME, MATERIALIZED_VIEW_PROPERTY_2_DEFAULT_VALUE));
}
Also used : Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) Property(io.trino.sql.tree.Property) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 13 with QualifiedObjectName

use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.

the class TestRenameMaterializedViewTask method testRenameMaterializedViewOnTableIfExists.

@Test
public void testRenameMaterializedViewOnTableIfExists() {
    QualifiedObjectName tableName = qualifiedObjectName("existing_table");
    metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
    assertTrinoExceptionThrownBy(() -> getFutureValue(executeRenameMaterializedView(asQualifiedName(tableName), qualifiedName("existing_table_new"), true))).hasErrorCode(TABLE_NOT_FOUND).hasMessage("Materialized View '%s' does not exist, but a table with that name exists. Did you mean ALTER TABLE %s RENAME ...?", tableName, tableName);
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 14 with QualifiedObjectName

use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.

the class TestRenameMaterializedViewTask method testRenameMaterializedViewOnTable.

@Test
public void testRenameMaterializedViewOnTable() {
    QualifiedObjectName tableName = qualifiedObjectName("existing_table");
    metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
    assertTrinoExceptionThrownBy(() -> getFutureValue(executeRenameMaterializedView(asQualifiedName(tableName), qualifiedName("existing_table_new")))).hasErrorCode(TABLE_NOT_FOUND).hasMessage("Materialized View '%s' does not exist, but a table with that name exists. Did you mean ALTER TABLE %s RENAME ...?", tableName, tableName);
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 15 with QualifiedObjectName

use of io.trino.metadata.QualifiedObjectName in project trino by trinodb.

the class TestRenameMaterializedViewTask method testRenameExistingMaterializedView.

@Test
public void testRenameExistingMaterializedView() {
    QualifiedObjectName materializedViewName = qualifiedObjectName("existing_materialized_view");
    QualifiedObjectName newMaterializedViewName = qualifiedObjectName("existing_materialized_view_new");
    metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
    getFutureValue(executeRenameMaterializedView(asQualifiedName(materializedViewName), asQualifiedName(newMaterializedViewName)));
    assertThat(metadata.isMaterializedView(testSession, materializedViewName)).isFalse();
    assertThat(metadata.isMaterializedView(testSession, newMaterializedViewName)).isTrue();
}
Also used : QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

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