Search in sources :

Example 1 with TpchPartitioningHandle

use of io.trino.plugin.tpch.TpchPartitioningHandle in project trino by trinodb.

the class TestInsert method createLocalQueryRunner.

@Override
protected LocalQueryRunner createLocalQueryRunner() {
    Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog("mock").setSchema("schema");
    LocalQueryRunner queryRunner = LocalQueryRunner.create(sessionBuilder.build());
    queryRunner.createCatalog("mock", MockConnectorFactory.builder().withGetTableHandle((session, schemaTableName) -> {
        if (schemaTableName.getTableName().equals("test_table_preferred_partitioning")) {
            return new MockConnectorTableHandle(schemaTableName);
        }
        if (schemaTableName.getTableName().equals("test_table_required_partitioning")) {
            return new MockConnectorTableHandle(schemaTableName);
        }
        return null;
    }).withGetColumns(name -> ImmutableList.of(new ColumnMetadata("column1", INTEGER), new ColumnMetadata("column2", INTEGER))).withGetInsertLayout((session, tableName) -> {
        if (tableName.getTableName().equals("test_table_preferred_partitioning")) {
            return Optional.of(new ConnectorTableLayout(ImmutableList.of("column1")));
        }
        if (tableName.getTableName().equals("test_table_required_partitioning")) {
            return Optional.of(new ConnectorTableLayout(new TpchPartitioningHandle("orders", 10), ImmutableList.of("column1")));
        }
        return Optional.empty();
    }).withGetNewTableLayout((session, tableMetadata) -> {
        if (tableMetadata.getTable().getTableName().equals("new_test_table_preferred_partitioning")) {
            return Optional.of(new ConnectorTableLayout(ImmutableList.of("column1")));
        }
        if (tableMetadata.getTable().getTableName().equals("new_test_table_required_partitioning")) {
            return Optional.of(new ConnectorTableLayout(new TpchPartitioningHandle("orders", 10), ImmutableList.of("column1")));
        }
        if (tableMetadata.getTable().getTableName().equals("new_test_table_unpartitioned")) {
            return Optional.empty();
        }
        return Optional.empty();
    }).build(), ImmutableMap.of());
    return queryRunner;
}
Also used : ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS(io.trino.SystemSessionProperties.PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) LocalQueryRunner(io.trino.testing.LocalQueryRunner) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) INTEGER(io.trino.spi.type.IntegerType.INTEGER) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) StatsProvider(io.trino.cost.StatsProvider) TASK_WRITER_COUNT(io.trino.SystemSessionProperties.TASK_WRITER_COUNT) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TpchPartitioningHandle(io.trino.plugin.tpch.TpchPartitioningHandle) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) MatchResult(io.trino.sql.planner.assertions.MatchResult) USE_PREFERRED_WRITE_PARTITIONING(io.trino.SystemSessionProperties.USE_PREFERRED_WRITE_PARTITIONING) Metadata(io.trino.metadata.Metadata) Matcher(io.trino.sql.planner.assertions.Matcher) Optional(java.util.Optional) SymbolAliases(io.trino.sql.planner.assertions.SymbolAliases) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) Session(io.trino.Session) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) TpchPartitioningHandle(io.trino.plugin.tpch.TpchPartitioningHandle) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Session(io.trino.Session)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Session (io.trino.Session)1 PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS (io.trino.SystemSessionProperties.PREFERRED_WRITE_PARTITIONING_MIN_NUMBER_OF_PARTITIONS)1 TASK_WRITER_COUNT (io.trino.SystemSessionProperties.TASK_WRITER_COUNT)1 USE_PREFERRED_WRITE_PARTITIONING (io.trino.SystemSessionProperties.USE_PREFERRED_WRITE_PARTITIONING)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)1 StatsProvider (io.trino.cost.StatsProvider)1 Metadata (io.trino.metadata.Metadata)1 TpchPartitioningHandle (io.trino.plugin.tpch.TpchPartitioningHandle)1 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)1 ConnectorTableLayout (io.trino.spi.connector.ConnectorTableLayout)1 INTEGER (io.trino.spi.type.IntegerType.INTEGER)1 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)1 MatchResult (io.trino.sql.planner.assertions.MatchResult)1 Matcher (io.trino.sql.planner.assertions.Matcher)1 PlanMatchPattern.anyTree (io.trino.sql.planner.assertions.PlanMatchPattern.anyTree)1 PlanMatchPattern.exchange (io.trino.sql.planner.assertions.PlanMatchPattern.exchange)1