Search in sources :

Example 6 with SchemaTablePrefix

use of io.trino.spi.connector.SchemaTablePrefix in project trino by trinodb.

the class AbstractTestHive method testIllegalStorageFormatDuringTableScan.

/**
 * During table scan, the illegal storage format for some specific table should not fail the whole table scan
 */
@Test
public void testIllegalStorageFormatDuringTableScan() {
    SchemaTableName schemaTableName = temporaryTable("test_illegal_storage_format");
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        List<Column> columns = ImmutableList.of(new Column("pk", HIVE_STRING, Optional.empty()));
        String tableOwner = session.getUser();
        String schemaName = schemaTableName.getSchemaName();
        String tableName = schemaTableName.getTableName();
        LocationHandle locationHandle = locationService.forNewTable(transaction.getMetastore(), session, schemaName, tableName, Optional.empty());
        Path targetPath = locationService.getQueryWriteInfo(locationHandle).getTargetPath();
        // create table whose storage format is null
        Table.Builder tableBuilder = Table.builder().setDatabaseName(schemaName).setTableName(tableName).setOwner(Optional.of(tableOwner)).setTableType(TableType.MANAGED_TABLE.name()).setParameters(ImmutableMap.of(PRESTO_VERSION_NAME, TEST_SERVER_VERSION, PRESTO_QUERY_ID_NAME, session.getQueryId())).setDataColumns(columns).withStorage(storage -> storage.setLocation(targetPath.toString()).setStorageFormat(StorageFormat.createNullable(null, null, null)).setSerdeParameters(ImmutableMap.of()));
        PrincipalPrivileges principalPrivileges = testingPrincipalPrivilege(tableOwner, session.getUser());
        transaction.getMetastore().createTable(session, tableBuilder.build(), principalPrivileges, Optional.empty(), Optional.empty(), true, EMPTY_TABLE_STATISTICS, false);
        transaction.commit();
    }
    // to make sure it can still be retrieved instead of throwing exception.
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Map<SchemaTableName, List<ColumnMetadata>> allColumns = listTableColumns(metadata, newSession(), new SchemaTablePrefix(schemaTableName.getSchemaName()));
        assertTrue(allColumns.containsKey(schemaTableName));
    } finally {
        dropTable(schemaTableName);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HiveSessionProperties.getTemporaryStagingDirectoryPath(io.trino.plugin.hive.HiveSessionProperties.getTemporaryStagingDirectoryPath) Table(io.trino.plugin.hive.metastore.Table) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) HiveColumnHandle.createBaseColumn(io.trino.plugin.hive.HiveColumnHandle.createBaseColumn) Column(io.trino.plugin.hive.metastore.Column) ViewColumn(io.trino.spi.connector.ConnectorViewDefinition.ViewColumn) SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) Test(org.testng.annotations.Test)

Example 7 with SchemaTablePrefix

use of io.trino.spi.connector.SchemaTablePrefix in project trino by trinodb.

the class AbstractTestHive method testHiveViewsHaveNoColumns.

@Test
public void testHiveViewsHaveNoColumns() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        assertEquals(listTableColumns(metadata, newSession(), new SchemaTablePrefix(view.getSchemaName(), view.getTableName())), ImmutableMap.of());
    }
}
Also used : SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) Test(org.testng.annotations.Test)

Example 8 with SchemaTablePrefix

use of io.trino.spi.connector.SchemaTablePrefix in project trino by trinodb.

the class AbstractTestHive method testGetAllTableColumnsInSchema.

@Test
public void testGetAllTableColumnsInSchema() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        Map<SchemaTableName, List<ColumnMetadata>> allColumns = listTableColumns(metadata, newSession(), new SchemaTablePrefix(database));
        assertTrue(allColumns.containsKey(tablePartitionFormat));
        assertTrue(allColumns.containsKey(tableUnpartitioned));
    }
}
Also used : SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 9 with SchemaTablePrefix

use of io.trino.spi.connector.SchemaTablePrefix in project trino by trinodb.

the class TestDeltaLakeGlueMetastore method testHideNonDeltaLakeTable.

@Test
public void testHideNonDeltaLakeTable() throws Exception {
    SchemaTableName deltaLakeTable = new SchemaTableName(databaseName, "delta_lake_table_" + randomName());
    SchemaTableName nonDeltaLakeTable1 = new SchemaTableName(databaseName, "hive_table_" + randomName());
    SchemaTableName nonDeltaLakeTable2 = new SchemaTableName(databaseName, "hive_table_" + randomName());
    String deltaLakeTableLocation = tableLocation(deltaLakeTable);
    createTable(deltaLakeTable, deltaLakeTableLocation, tableBuilder -> {
        tableBuilder.setParameter(TABLE_PROVIDER_PROPERTY, TABLE_PROVIDER_VALUE);
        tableBuilder.setParameter(LOCATION_PROPERTY, deltaLakeTableLocation);
        tableBuilder.getStorageBuilder().setStorageFormat(DELTA_STORAGE_FORMAT).setSerdeParameters(ImmutableMap.of(DeltaLakeMetadata.PATH_PROPERTY, deltaLakeTableLocation)).setLocation(deltaLakeTableLocation);
    });
    createTransactionLog(deltaLakeTableLocation);
    createTable(nonDeltaLakeTable1, tableLocation(nonDeltaLakeTable1), tableBuilder -> {
    });
    createTable(nonDeltaLakeTable2, tableLocation(nonDeltaLakeTable2), tableBuilder -> tableBuilder.setParameter(TABLE_PROVIDER_PROPERTY, "foo"));
    DeltaLakeMetadata metadata = metadataFactory.create(SESSION.getIdentity());
    // Verify the tables were created as non Delta Lake tables
    assertThatThrownBy(() -> metadata.getTableHandle(session, nonDeltaLakeTable1)).isInstanceOf(TrinoException.class).hasMessage(format("%s is not a Delta Lake table", nonDeltaLakeTable1));
    assertThatThrownBy(() -> metadata.getTableHandle(session, nonDeltaLakeTable2)).isInstanceOf(TrinoException.class).hasMessage(format("%s is not a Delta Lake table", nonDeltaLakeTable2));
    // TODO (https://github.com/trinodb/trino/issues/5426)
    // these assertions should use information_schema instead of metadata directly,
    // as information_schema or MetadataManager may apply additional logic
    // list all tables
    assertThat(metadata.listTables(session, Optional.empty())).contains(deltaLakeTable).doesNotContain(nonDeltaLakeTable1).doesNotContain(nonDeltaLakeTable2);
    // list all tables in a schema
    assertThat(metadata.listTables(session, Optional.of(databaseName))).contains(deltaLakeTable).doesNotContain(nonDeltaLakeTable1).doesNotContain(nonDeltaLakeTable2);
    // list all columns in a schema
    assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName))).contains(deltaLakeTable).doesNotContain(nonDeltaLakeTable1).doesNotContain(nonDeltaLakeTable2);
    // list all columns in a table
    assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName, deltaLakeTable.getTableName()))).contains(deltaLakeTable).doesNotContain(nonDeltaLakeTable1).doesNotContain(nonDeltaLakeTable2);
    assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName, nonDeltaLakeTable1.getTableName()))).isEmpty();
    assertThat(listTableColumns(metadata, new SchemaTablePrefix(databaseName, nonDeltaLakeTable2.getTableName()))).isEmpty();
}
Also used : SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) DeltaLakeMetadata(io.trino.plugin.deltalake.DeltaLakeMetadata) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 10 with SchemaTablePrefix

use of io.trino.spi.connector.SchemaTablePrefix in project trino by trinodb.

the class TestRaptorMetadata method testListTableColumnsFiltering.

@Test
public void testListTableColumnsFiltering() {
    metadata.createTable(SESSION, getOrdersTable(), false);
    Map<SchemaTableName, List<ColumnMetadata>> filterCatalog = metadata.listTableColumns(SESSION, new SchemaTablePrefix());
    Map<SchemaTableName, List<ColumnMetadata>> filterSchema = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test"));
    Map<SchemaTableName, List<ColumnMetadata>> filterTable = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test", "orders"));
    assertEquals(filterCatalog, filterSchema);
    assertEquals(filterCatalog, filterTable);
}
Also used : SchemaTablePrefix(io.trino.spi.connector.SchemaTablePrefix) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Aggregations

SchemaTablePrefix (io.trino.spi.connector.SchemaTablePrefix)15 SchemaTableName (io.trino.spi.connector.SchemaTableName)14 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)11 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)10 ConnectorSession (io.trino.spi.connector.ConnectorSession)9 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 Test (org.testng.annotations.Test)7 TrinoException (io.trino.spi.TrinoException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ColumnHandle (io.trino.spi.connector.ColumnHandle)4 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)4 ConnectorMaterializedViewDefinition (io.trino.spi.connector.ConnectorMaterializedViewDefinition)4 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)4 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)4 ConnectorViewDefinition (io.trino.spi.connector.ConnectorViewDefinition)4 Constraint (io.trino.spi.connector.Constraint)4 ConstraintApplicationResult (io.trino.spi.connector.ConstraintApplicationResult)4 SystemTable (io.trino.spi.connector.SystemTable)4