diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergStatistics.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergStatistics.java index 6aa452506fec..b06d7437e535 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergStatistics.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergStatistics.java @@ -195,7 +195,7 @@ public void acceptDataFile(DataFile dataFile, PartitionSpec partitionSpec) Conversions.fromByteBuffer(column.type(), Optional.ofNullable(dataFile.lowerBounds()).map(a -> a.get(id)).orElse(null))); Object upperBound = convertIcebergValueToTrino(column.type(), Conversions.fromByteBuffer(column.type(), Optional.ofNullable(dataFile.upperBounds()).map(a -> a.get(id)).orElse(null))); - Optional nullCount = Optional.ofNullable(dataFile.nullValueCounts().get(id)); + Optional nullCount = Optional.ofNullable(dataFile.nullValueCounts()).map(nullCounts -> nullCounts.get(id)); updateMinMaxStats( id, trinoType, diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergSparkCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergSparkCompatibility.java index 1d313cdffcf4..88a76824d8ca 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergSparkCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/iceberg/TestIcebergSparkCompatibility.java @@ -1455,6 +1455,20 @@ public void testTrinoReadsSparkRowLevelDeletesWithRowTypes(StorageFormat tableSt onSpark().executeQuery("DROP TABLE " + sparkTableName); } + @Test(groups = {ICEBERG, PROFILE_SPECIFIC_TESTS}) + public void testMissingMetrics() + { + String tableName = "test_missing_metrics_" + randomTableSuffix(); + String sparkTableName = sparkTableName(tableName); + onSpark().executeQuery("CREATE TABLE " + sparkTableName + " (name STRING, country STRING) USING ICEBERG " + + "PARTITIONED BY (country) TBLPROPERTIES ('write.metadata.metrics.default'='none')"); + onSpark().executeQuery("INSERT INTO " + sparkTableName + " VALUES ('Christoph', 'AT'), (NULL, 'RO')"); + assertThat(onTrino().executeQuery(format("SELECT count(*) FROM %s.%s.\"%s$partitions\" WHERE data IS NOT NULL", TRINO_CATALOG, TEST_SCHEMA_NAME, tableName))) + .containsOnly(row(0)); + + onSpark().executeQuery("DROP TABLE " + sparkTableName); + } + private static String escapeSparkString(String value) { return value.replace("\\", "\\\\").replace("'", "\\'");