Search in sources :

Example 6 with ConnectorOutputTableHandle

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

the class TestHiveGlueMetastore method testUpdatePartitionedStatisticsOnCreate.

@Test
public void testUpdatePartitionedStatisticsOnCreate() {
    SchemaTableName tableName = temporaryTable("update_partitioned_statistics_create");
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        ConnectorMetadata metadata = transaction.getMetadata();
        List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("a_column", BigintType.BIGINT), new ColumnMetadata("part_column", BigintType.BIGINT));
        ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, columns, createTableProperties(TEXTFILE, ImmutableList.of("part_column")));
        ConnectorOutputTableHandle createTableHandle = metadata.beginCreateTable(session, tableMetadata, Optional.empty(), NO_RETRIES);
        // write data
        ConnectorPageSink sink = pageSinkProvider.createPageSink(transaction.getTransactionHandle(), session, createTableHandle);
        MaterializedResult data = MaterializedResult.resultBuilder(session, BigintType.BIGINT, BigintType.BIGINT).row(1L, 1L).row(2L, 1L).row(3L, 1L).row(4L, 2L).row(5L, 2L).build();
        sink.appendPage(data.toPage());
        Collection<Slice> fragments = getFutureValue(sink.finish());
        // prepare statistics
        ComputedStatistics statistics1 = ComputedStatistics.builder(ImmutableList.of("part_column"), ImmutableList.of(singleValueBlock(1))).addTableStatistic(TableStatisticType.ROW_COUNT, singleValueBlock(3)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MIN_VALUE), singleValueBlock(1)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MAX_VALUE), singleValueBlock(3)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_DISTINCT_VALUES), singleValueBlock(3)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_NON_NULL_VALUES), singleValueBlock(3)).build();
        ComputedStatistics statistics2 = ComputedStatistics.builder(ImmutableList.of("part_column"), ImmutableList.of(singleValueBlock(2))).addTableStatistic(TableStatisticType.ROW_COUNT, singleValueBlock(2)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MIN_VALUE), singleValueBlock(4)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MAX_VALUE), singleValueBlock(5)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_DISTINCT_VALUES), singleValueBlock(2)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_NON_NULL_VALUES), singleValueBlock(2)).build();
        // finish CTAS
        metadata.finishCreateTable(session, createTableHandle, fragments, ImmutableList.of(statistics1, statistics2));
        transaction.commit();
    } finally {
        dropTable(tableName);
    }
}
Also used : ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) ComputedStatistics(io.trino.spi.statistics.ComputedStatistics) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ConnectorPageSink(io.trino.spi.connector.ConnectorPageSink) MaterializedResult(io.trino.testing.MaterializedResult) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 7 with ConnectorOutputTableHandle

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

the class TestHiveGlueMetastore method testUpdateStatisticsOnCreate.

@Test
public void testUpdateStatisticsOnCreate() {
    SchemaTableName tableName = temporaryTable("update_statistics_create");
    try (Transaction transaction = newTransaction()) {
        ConnectorSession session = newSession();
        ConnectorMetadata metadata = transaction.getMetadata();
        List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata("a_column", BigintType.BIGINT));
        ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName, columns, createTableProperties(TEXTFILE));
        ConnectorOutputTableHandle createTableHandle = metadata.beginCreateTable(session, tableMetadata, Optional.empty(), NO_RETRIES);
        // write data
        ConnectorPageSink sink = pageSinkProvider.createPageSink(transaction.getTransactionHandle(), session, createTableHandle);
        MaterializedResult data = MaterializedResult.resultBuilder(session, BigintType.BIGINT).row(1L).row(2L).row(3L).row(4L).row(5L).build();
        sink.appendPage(data.toPage());
        Collection<Slice> fragments = getFutureValue(sink.finish());
        // prepare statistics
        ComputedStatistics statistics = ComputedStatistics.builder(ImmutableList.of(), ImmutableList.of()).addTableStatistic(TableStatisticType.ROW_COUNT, singleValueBlock(5)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MIN_VALUE), singleValueBlock(1)).addColumnStatistic(new ColumnStatisticMetadata("a_column", MAX_VALUE), singleValueBlock(5)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_DISTINCT_VALUES), singleValueBlock(5)).addColumnStatistic(new ColumnStatisticMetadata("a_column", NUMBER_OF_NON_NULL_VALUES), singleValueBlock(5)).build();
        // finish CTAS
        metadata.finishCreateTable(session, createTableHandle, fragments, ImmutableList.of(statistics));
        transaction.commit();
    } finally {
        dropTable(tableName);
    }
}
Also used : ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) ComputedStatistics(io.trino.spi.statistics.ComputedStatistics) ConnectorSession(io.trino.spi.connector.ConnectorSession) ConnectorMetadata(io.trino.spi.connector.ConnectorMetadata) ConnectorPageSink(io.trino.spi.connector.ConnectorPageSink) MaterializedResult(io.trino.testing.MaterializedResult) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 8 with ConnectorOutputTableHandle

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

the class MemoryMetadata method createTable.

@Override
public synchronized void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, boolean ignoreExisting) {
    ConnectorOutputTableHandle outputTableHandle = beginCreateTable(session, tableMetadata, Optional.empty(), NO_RETRIES);
    finishCreateTable(session, outputTableHandle, ImmutableList.of(), ImmutableList.of());
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle)

Example 9 with ConnectorOutputTableHandle

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

the class TestMemoryMetadata method tableIsCreatedAfterCommits.

@Test
public void tableIsCreatedAfterCommits() {
    assertNoTables();
    SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty(), NO_RETRIES);
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    List<SchemaTableName> tables = metadata.listTables(SESSION, Optional.empty());
    assertEquals(tables.size(), 1, "Expected only one table");
    assertEquals(tables.get(0).getTableName(), "temp_table", "Expected table with name 'temp_table'");
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 10 with ConnectorOutputTableHandle

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

the class TestMemoryMetadata method testRenameTable.

@Test
public void testRenameTable() {
    SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
    metadata.createSchema(SESSION, "test_schema", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty(), NO_RETRIES);
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    // rename table to schema which does not exist
    SchemaTableName invalidSchemaTableName = new SchemaTableName("test_schema_not_exist", "test_table_renamed");
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
    Throwable throwable = expectThrows(SchemaNotFoundException.class, () -> metadata.renameTable(SESSION, tableHandle, invalidSchemaTableName));
    assertEquals(throwable.getMessage(), "Schema test_schema_not_exist not found");
    // rename table to same schema
    SchemaTableName sameSchemaTableName = new SchemaTableName("test_schema", "test_renamed");
    metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, tableName), sameSchemaTableName);
    assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of(sameSchemaTableName));
    // rename table to different schema
    metadata.createSchema(SESSION, "test_different_schema", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
    SchemaTableName differentSchemaTableName = new SchemaTableName("test_different_schema", "test_renamed");
    metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, sameSchemaTableName), differentSchemaTableName);
    assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of());
    assertEquals(metadata.listTables(SESSION, Optional.of("test_different_schema")), ImmutableList.of(differentSchemaTableName));
}
Also used : ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)19 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)13 Test (org.testng.annotations.Test)10 ConnectorSession (io.trino.spi.connector.ConnectorSession)9 SchemaTableName (io.trino.spi.connector.SchemaTableName)9 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)7 Slice (io.airlift.slice.Slice)6 ConnectorPageSink (io.trino.spi.connector.ConnectorPageSink)6 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)6 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)5 MaterializedResult (io.trino.testing.MaterializedResult)5 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)4 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)4 TestingConnectorSession (io.trino.testing.TestingConnectorSession)4 HiveSessionProperties.getTemporaryStagingDirectoryPath (io.trino.plugin.hive.HiveSessionProperties.getTemporaryStagingDirectoryPath)3 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)3 ColumnHandle (io.trino.spi.connector.ColumnHandle)3 Path (org.apache.hadoop.fs.Path)3 HiveColumnHandle.bucketColumnHandle (io.trino.plugin.hive.HiveColumnHandle.bucketColumnHandle)2 ConnectorPageSource (io.trino.spi.connector.ConnectorPageSource)2