Search in sources :

Example 56 with SchemaTableName

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

the class AbstractTestHive method testUpdatePartitionColumnStatisticsEmptyOptionalFields.

@Test
public void testUpdatePartitionColumnStatisticsEmptyOptionalFields() throws Exception {
    SchemaTableName tableName = temporaryTable("update_partition_column_statistics");
    try {
        createDummyPartitionedTable(tableName, STATISTICS_PARTITIONED_TABLE_COLUMNS);
        testUpdatePartitionStatistics(tableName, EMPTY_TABLE_STATISTICS, ImmutableList.of(STATISTICS_EMPTY_OPTIONAL_FIELDS), ImmutableList.of(STATISTICS_EMPTY_OPTIONAL_FIELDS));
    } finally {
        dropTable(tableName);
    }
}
Also used : CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 57 with SchemaTableName

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

the class AbstractTestHive method testMaterializedViewMetadata.

@Test
public void testMaterializedViewMetadata() throws Exception {
    SchemaTableName sourceTableName = temporaryTable("materialized_view_tester");
    doCreateEmptyTable(sourceTableName, ORC, CREATE_TABLE_COLUMNS);
    SchemaTableName tableName = temporaryTable("mock_table");
    doCreateEmptyTable(tableName, ORC, CREATE_TABLE_COLUMNS);
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        ConnectorMetadata metadata = transaction.getMetadata();
        assertThat(metadata.getMaterializedView(session, tableName)).isEmpty();
        Optional<ConnectorMaterializedViewDefinition> result = metadata.getMaterializedView(session, sourceTableName);
        assertThat(result).isPresent();
        assertThat(result.get().getOriginalSql()).isEqualTo("dummy_view_sql");
    } finally {
        dropTable(sourceTableName);
        dropTable(tableName);
    }
}
Also used : ConnectorMaterializedViewDefinition(io.trino.spi.connector.ConnectorMaterializedViewDefinition) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 58 with SchemaTableName

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

the class AbstractTestHive method assertEmptyFile.

private void assertEmptyFile(HiveStorageFormat format) throws Exception {
    SchemaTableName tableName = temporaryTable("empty_file");
    try {
        List<Column> columns = ImmutableList.of(new Column("test", HIVE_STRING, Optional.empty()));
        createEmptyTable(tableName, format, columns, ImmutableList.of());
        try (Transaction transaction = newTransaction()) {
            ConnectorSession session = newSession();
            ConnectorMetadata metadata = transaction.getMetadata();
            metadata.beginQuery(session);
            ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName);
            List<ColumnHandle> columnHandles = filterNonHiddenColumnHandles(metadata.getColumnHandles(session, tableHandle).values());
            Table table = transaction.getMetastore().getTable(tableName.getSchemaName(), tableName.getTableName()).orElseThrow(AssertionError::new);
            // verify directory is empty
            HdfsContext context = new HdfsContext(session);
            Path location = new Path(table.getStorage().getLocation());
            assertTrue(listDirectory(context, location).isEmpty());
            // read table with empty directory
            readTable(transaction, tableHandle, columnHandles, session, TupleDomain.all(), OptionalInt.of(0), Optional.of(ORC));
            // create empty file
            FileSystem fileSystem = hdfsEnvironment.getFileSystem(context, location);
            assertTrue(fileSystem.createNewFile(new Path(location, "empty-file")));
            assertEquals(listDirectory(context, location), ImmutableList.of("empty-file"));
            // read table with empty file
            MaterializedResult result = readTable(transaction, tableHandle, columnHandles, session, TupleDomain.all(), OptionalInt.of(0), Optional.empty());
            assertEquals(result.getRowCount(), 0);
        }
    } finally {
        dropTable(tableName);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HiveSessionProperties.getTemporaryStagingDirectoryPath(io.trino.plugin.hive.HiveSessionProperties.getTemporaryStagingDirectoryPath) HiveColumnHandle.bucketColumnHandle(io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) Table(io.trino.plugin.hive.metastore.Table) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) 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) FileSystem(org.apache.hadoop.fs.FileSystem) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) MaterializedResult(io.trino.testing.MaterializedResult)

Example 59 with SchemaTableName

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

the class AbstractTestHive method testUpdateTableColumnStatistics.

@Test
public void testUpdateTableColumnStatistics() throws Exception {
    SchemaTableName tableName = temporaryTable("update_table_column_statistics");
    try {
        doCreateEmptyTable(tableName, ORC, STATISTICS_TABLE_COLUMNS);
        testUpdateTableStatistics(tableName, EMPTY_TABLE_STATISTICS, STATISTICS_1_1, STATISTICS_1_2, STATISTICS_2);
    } finally {
        dropTable(tableName);
    }
}
Also used : CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 60 with SchemaTableName

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

the class AbstractTestHive method testApplyRedirection.

@Test
public void testApplyRedirection() throws Exception {
    SchemaTableName sourceTableName = temporaryTable("apply_redirection_tester");
    doCreateEmptyTable(sourceTableName, ORC, CREATE_TABLE_COLUMNS);
    SchemaTableName tableName = temporaryTable("apply_no_redirection_tester");
    doCreateEmptyTable(tableName, ORC, CREATE_TABLE_COLUMNS);
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        ConnectorMetadata metadata = transaction.getMetadata();
        assertThat(metadata.applyTableScanRedirect(session, getTableHandle(metadata, tableName))).isEmpty();
        Optional<TableScanRedirectApplicationResult> result = metadata.applyTableScanRedirect(session, getTableHandle(metadata, sourceTableName));
        assertThat(result).isPresent();
        assertThat(result.get().getDestinationTable()).isEqualTo(new CatalogSchemaTableName("hive", database, "mock_redirection_target"));
    } finally {
        dropTable(sourceTableName);
        dropTable(tableName);
    }
}
Also used : TableScanRedirectApplicationResult(io.trino.spi.connector.TableScanRedirectApplicationResult) ConnectorSession(io.trino.spi.connector.ConnectorSession) TestingConnectorSession(io.trino.testing.TestingConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) SchemaTableName(io.trino.spi.connector.SchemaTableName) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) Test(org.testng.annotations.Test)

Aggregations

SchemaTableName (io.trino.spi.connector.SchemaTableName)446 Test (org.testng.annotations.Test)212 ImmutableList (com.google.common.collect.ImmutableList)131 ImmutableMap (com.google.common.collect.ImmutableMap)106 List (java.util.List)102 TrinoException (io.trino.spi.TrinoException)100 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)98 ConnectorSession (io.trino.spi.connector.ConnectorSession)98 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)92 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)89 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)86 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)86 Optional (java.util.Optional)78 Map (java.util.Map)67 ColumnHandle (io.trino.spi.connector.ColumnHandle)66 TupleDomain (io.trino.spi.predicate.TupleDomain)59 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)58 Path (org.apache.hadoop.fs.Path)55 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)53 ImmutableSet (com.google.common.collect.ImmutableSet)52