|
50 | 50 | import java.util.List; |
51 | 51 | import java.util.Map; |
52 | 52 | import java.util.Optional; |
| 53 | +import java.util.OptionalLong; |
53 | 54 | import java.util.TimeZone; |
54 | 55 | import java.util.stream.Collectors; |
55 | 56 |
|
@@ -281,6 +282,80 @@ public void testSyncPartitionOnBucketRoot() |
281 | 282 | assertUpdate("DROP TABLE " + fullyQualifiedTestTableName); |
282 | 283 | } |
283 | 284 |
|
| 285 | + @Test |
| 286 | + public void testUpdateStatisticInsertOverwritePartitionedTable() |
| 287 | + { |
| 288 | + String partitionValue = "0"; |
| 289 | + Session session = Session.builder(getQueryRunner().getDefaultSession()) |
| 290 | + .setCatalogSessionProperty("hive", "insert_existing_partitions_behavior", "OVERWRITE") |
| 291 | + .setCatalogSessionProperty("hive", "collect_column_statistics_on_write", "true") |
| 292 | + .build(); |
| 293 | + String tableName = "test_statistic" + randomNameSuffix(); |
| 294 | + String testTable = getFullyQualifiedTestTableName(tableName); |
| 295 | + computeActual(getCreateTableStatement( |
| 296 | + testTable, |
| 297 | + "partitioned_by=ARRAY['regionkey']")); |
| 298 | + copyTpchNationToTable(session, testTable); |
| 299 | + Table hiveTable = metastoreClient.getTable(HIVE_TEST_SCHEMA, tableName).orElseThrow(); |
| 300 | + Partition partition = metastoreClient.getPartition(hiveTable, List.of(partitionValue)).orElseThrow(); |
| 301 | + Map<String, Map<String, HiveColumnStatistics>> partitionStatistics = metastoreClient.getPartitionColumnStatistics( |
| 302 | + HIVE_TEST_SCHEMA, |
| 303 | + tableName, |
| 304 | + ImmutableSet.of("regionkey=0"), |
| 305 | + partition.getColumns().stream().map(Column::getName).collect(toSet())); |
| 306 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().isPresent()).isTrue(); |
| 307 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMin()).isEqualTo(OptionalLong.of(0)); |
| 308 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMax()).isEqualTo(OptionalLong.of(16)); |
| 309 | + |
| 310 | + assertUpdate(session, "INSERT INTO " + testTable + "(name, comment, nationkey, regionkey) values ('name1', 'comment1', 20, 0)", 1); |
| 311 | + |
| 312 | + partitionStatistics = metastoreClient.getPartitionColumnStatistics( |
| 313 | + HIVE_TEST_SCHEMA, |
| 314 | + tableName, |
| 315 | + ImmutableSet.of("regionkey=0"), |
| 316 | + partition.getColumns().stream().map(Column::getName).collect(toSet())); |
| 317 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().isPresent()).isTrue(); |
| 318 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMin()).isEqualTo(OptionalLong.of(20)); |
| 319 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMax()).isEqualTo(OptionalLong.of(20)); |
| 320 | + } |
| 321 | + |
| 322 | + @Test |
| 323 | + public void testUpdateStatisticInsertAppendPartitionedTable() |
| 324 | + { |
| 325 | + String partitionValue = "0"; |
| 326 | + Session session = Session.builder(getQueryRunner().getDefaultSession()) |
| 327 | + .setCatalogSessionProperty("hive", "insert_existing_partitions_behavior", "APPEND") |
| 328 | + .setCatalogSessionProperty("hive", "collect_column_statistics_on_write", "true") |
| 329 | + .build(); |
| 330 | + String tableName = "test_statistic" + randomNameSuffix(); |
| 331 | + String testTable = getFullyQualifiedTestTableName(tableName); |
| 332 | + computeActual(session, getCreateTableStatement( |
| 333 | + testTable, |
| 334 | + "partitioned_by=ARRAY['regionkey']")); |
| 335 | + copyTpchNationToTable(session, testTable); |
| 336 | + Table hiveTable = metastoreClient.getTable(HIVE_TEST_SCHEMA, tableName).orElseThrow(); |
| 337 | + Partition partition = metastoreClient.getPartition(hiveTable, List.of(partitionValue)).orElseThrow(); |
| 338 | + Map<String, Map<String, HiveColumnStatistics>> partitionStatistics = metastoreClient.getPartitionColumnStatistics( |
| 339 | + HIVE_TEST_SCHEMA, |
| 340 | + tableName, |
| 341 | + ImmutableSet.of("regionkey=0"), |
| 342 | + partition.getColumns().stream().map(Column::getName).collect(toSet())); |
| 343 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().isPresent()).isTrue(); |
| 344 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMin()).isEqualTo(OptionalLong.of(0)); |
| 345 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMax()).isEqualTo(OptionalLong.of(16)); |
| 346 | + |
| 347 | + computeActual(session, "INSERT INTO " + testTable + "(name, comment, nationkey, regionkey) values ('name1', 'comment1', 20, 0)"); |
| 348 | + |
| 349 | + partitionStatistics = metastoreClient.getPartitionColumnStatistics( |
| 350 | + HIVE_TEST_SCHEMA, |
| 351 | + tableName, |
| 352 | + ImmutableSet.of("regionkey=0"), |
| 353 | + partition.getColumns().stream().map(Column::getName).collect(toSet())); |
| 354 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().isPresent()).isTrue(); |
| 355 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMin()).isEqualTo(OptionalLong.of(0)); |
| 356 | + assertThat(partitionStatistics.get("regionkey=0").get("nationkey").getIntegerStatistics().get().getMax()).isEqualTo(OptionalLong.of(20)); |
| 357 | + } |
| 358 | + |
284 | 359 | @Test |
285 | 360 | public void testSyncPartitionCaseSensitivePathVariation() |
286 | 361 | { |
@@ -2470,9 +2545,13 @@ protected String getCreateTableStatement(String tableName, List<String> properti |
2470 | 2545 | tableName); |
2471 | 2546 | } |
2472 | 2547 |
|
2473 | | - protected void copyTpchNationToTable(String testTable) |
| 2548 | + protected void copyTpchNationToTable(String testTable) { |
| 2549 | + copyTpchNationToTable(getSession(), testTable); |
| 2550 | + } |
| 2551 | + |
| 2552 | + protected void copyTpchNationToTable(Session session, String testTable) |
2474 | 2553 | { |
2475 | | - computeActual(format("INSERT INTO " + testTable + " SELECT name, comment, nationkey, regionkey FROM tpch.tiny.nation")); |
| 2554 | + computeActual(session, format("INSERT INTO " + testTable + " SELECT name, comment, nationkey, regionkey FROM tpch.tiny.nation")); |
2476 | 2555 | } |
2477 | 2556 |
|
2478 | 2557 | private void testWriteWithFileSize(String testTable, int scaleFactorInThousands, long fileSizeRangeStart, long fileSizeRangeEnd) |
|
0 commit comments