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");
}
}
Aggregations