Search in sources :

Example 11 with PartitionWithStatistics

use of com.facebook.presto.hive.metastore.PartitionWithStatistics in project presto by prestodb.

the class TestHiveLogicalPlanner method testMetadataAggregationFoldingWithTwoPartitionColumns.

@Test
public void testMetadataAggregationFoldingWithTwoPartitionColumns() {
    QueryRunner queryRunner = getQueryRunner();
    Session optimizeMetadataQueries = Session.builder(this.getQueryRunner().getDefaultSession()).setSystemProperty(OPTIMIZE_METADATA_QUERIES, Boolean.toString(true)).build();
    Session shufflePartitionColumns = Session.builder(this.getQueryRunner().getDefaultSession()).setCatalogSessionProperty(HIVE_CATALOG, SHUFFLE_PARTITIONED_COLUMNS_FOR_TABLE_WRITE, Boolean.toString(true)).build();
    // Create a table with partitions: ds=2020-07-01/status=A, ds=2020-07-01/status=B, ds=2020-07-02/status=A, ds=2020-07-02/status=B
    queryRunner.execute(shufflePartitionColumns, "CREATE TABLE test_metadata_aggregation_folding_with_two_partitions_columns WITH (partitioned_by = ARRAY['ds', 'status']) AS " + "SELECT orderkey, CAST(to_iso8601(date_add('DAY', orderkey % 2, date('2020-07-01'))) AS VARCHAR) AS ds, IF(orderkey % 2 = 1, 'A', 'B') status " + "FROM orders WHERE orderkey < 1000");
    ExtendedHiveMetastore metastore = replicateHiveMetastore((DistributedQueryRunner) queryRunner);
    MetastoreContext metastoreContext = new MetastoreContext(getSession().getUser(), getSession().getQueryId().getId(), Optional.empty(), Optional.empty(), Optional.empty(), false, HiveColumnConverterProvider.DEFAULT_COLUMN_CONVERTER_PROVIDER);
    Table table = metastore.getTable(metastoreContext, getSession().getSchema().get(), "test_metadata_aggregation_folding_with_two_partitions_columns").get();
    // Add one partition with no statistics.
    String partitionNameNoStats = "ds=2020-07-03/status=C";
    Partition partitionNoStats = createDummyPartition(table, partitionNameNoStats);
    metastore.addPartitions(metastoreContext, table.getDatabaseName(), table.getTableName(), ImmutableList.of(new PartitionWithStatistics(partitionNoStats, partitionNameNoStats, PartitionStatistics.empty())));
    try {
        // All matching partitions have stats. Enable rewrite.
        assertPlan(optimizeMetadataQueries, "SELECT MIN(ds), MAX(ds) FROM test_metadata_aggregation_folding_with_two_partitions_columns WHERE ds BETWEEN '2020-07-01' AND '2020-07-02'", anyTree(project(ImmutableMap.of("min", expression("'2020-07-01'"), "max", expression("'2020-07-02'")), anyTree(values()))));
        // All matching partitions have stats. Enable rewrite.
        assertPlan(optimizeMetadataQueries, "SELECT MIN(status), MAX(ds) FROM test_metadata_aggregation_folding_with_two_partitions_columns WHERE ds BETWEEN '2020-07-01' AND '2020-07-02'", anyTree(project(ImmutableMap.of("min", expression("'A'"), "max", expression("'2020-07-02'")), anyTree(values()))));
        // All matching partitions have stats. Enable rewrite.
        assertPlan(optimizeMetadataQueries, "SELECT MIN(ds) ds, MIN(status) status FROM test_metadata_aggregation_folding_with_two_partitions_columns", anyTree(project(ImmutableMap.of("ds", expression("'2020-07-01'"), "status", expression("'A'")), anyTree(values()))));
        // Resulting partition doesn't have stats. Disable rewrite.
        assertPlan(optimizeMetadataQueries, "SELECT MAX(status) status FROM test_metadata_aggregation_folding_with_two_partitions_columns", anyTree(tableScanWithConstraint("test_metadata_aggregation_folding_with_two_partitions_columns", ImmutableMap.of("status", multipleValues(VarcharType.createVarcharType(1), utf8Slices("A", "B", "C")), "ds", multipleValues(VARCHAR, utf8Slices("2020-07-01", "2020-07-02", "2020-07-03"))))));
    } finally {
        queryRunner.execute("DROP TABLE IF EXISTS test_metadata_aggregation_folding_with_two_partitions_columns");
    }
}
Also used : Partition(com.facebook.presto.hive.metastore.Partition) Table(com.facebook.presto.hive.metastore.Table) PartitionWithStatistics(com.facebook.presto.hive.metastore.PartitionWithStatistics) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) QueryRunner(com.facebook.presto.testing.QueryRunner) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

PartitionWithStatistics (com.facebook.presto.hive.metastore.PartitionWithStatistics)11 Partition (com.facebook.presto.hive.metastore.Partition)8 Table (com.facebook.presto.hive.metastore.Table)7 ExtendedHiveMetastore (com.facebook.presto.hive.metastore.ExtendedHiveMetastore)6 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)6 Test (org.testng.annotations.Test)6 PrestoException (com.facebook.presto.spi.PrestoException)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 NoHdfsAuthentication (com.facebook.presto.hive.authentication.NoHdfsAuthentication)4 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)4 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 FileUtils.makePartName (org.apache.hadoop.hive.common.FileUtils.makePartName)4 Domain (com.facebook.presto.common.predicate.Domain)3