From 08a7d092b5a1c7b6eab299566053ab393ad670c7 Mon Sep 17 00:00:00 2001 From: Alex Jo Date: Mon, 7 Aug 2023 15:23:47 -0400 Subject: [PATCH] Test Iceberg statistics when a data file is fully deleted --- .../plugin/iceberg/TestIcebergStatistics.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java index e8c03b0fdae0..e6ebe9c6fe08 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java @@ -979,6 +979,33 @@ public void testShowStatsAfterExpiration() assertUpdate("DROP TABLE show_stats_after_expiration"); } + @Test + public void testStatsAfterDeletingAllRows() + { + String tableName = "test_stats_after_deleting_all_rows_"; + assertUpdate("CREATE TABLE " + tableName + " AS SELECT * FROM tpch.sf1.nation", 25); + + assertThat(query("SHOW STATS FOR " + tableName)) + .projected("column_name", "distinct_values_count", "row_count") + .skippingTypesCheck() + .containsAll("VALUES " + + "('nationkey', DOUBLE '25', null), " + + "('name', DOUBLE '25', null), " + + "('regionkey', DOUBLE '5', null), " + + "('comment', DOUBLE '25', null), " + + "(null, null, DOUBLE '25')"); + assertUpdate("DELETE FROM " + tableName + " WHERE nationkey < 50", 25); + assertThat(query("SHOW STATS FOR " + tableName)) + .projected("column_name", "distinct_values_count", "row_count") + .skippingTypesCheck() + .containsAll("VALUES " + + "('nationkey', DOUBLE '0.0', null), " + + "('name', DOUBLE '0.0', null), " + + "('regionkey', DOUBLE '0.0', null), " + + "('comment', DOUBLE '0.0', null), " + + "(null, null, DOUBLE '0.0')"); + } + private long getCurrentSnapshotId(String tableName) { return (long) computeActual(format("SELECT snapshot_id FROM \"%s$snapshots\" ORDER BY committed_at DESC FETCH FIRST 1 ROW WITH TIES", tableName))