diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index 2c9fbae6128d8..76d79fdaddf9b 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -1790,10 +1790,12 @@ public Optional> applyFilter(C else { Table icebergTable = catalog.loadTable(session, table.getSchemaTableName()); - Long snapshotId = table.getSnapshotId().orElseThrow(() -> new IllegalStateException("Snapshot id must be present")); - Set partitionSpecIds = icebergTable.snapshot(snapshotId).allManifests(icebergTable.io()).stream() - .map(ManifestFile::partitionSpecId) - .collect(toImmutableSet()); + Set partitionSpecIds = table.getSnapshotId().map( + snapshot -> icebergTable.snapshot(snapshot).allManifests(icebergTable.io()).stream() + .map(ManifestFile::partitionSpecId) + .collect(toImmutableSet())) + // No snapshot, so no data. This case doesn't matter. + .orElseGet(() -> ImmutableSet.copyOf(icebergTable.specs().keySet())); Map unsupported = new LinkedHashMap<>(); Map newEnforced = new LinkedHashMap<>(); 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 a429dc1dfb439..1a8cc0fd3422b 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 @@ -117,6 +117,7 @@ public void testTrinoReadingSparkData(StorageFormat storageFormat, int specVersi // Validate queries on an empty table created by Spark assertThat(onTrino().executeQuery(format("SELECT * FROM %s", trinoTableName("\"" + baseTableName + "$snapshots\"")))).hasNoRows(); assertThat(onTrino().executeQuery(format("SELECT * FROM %s", trinoTableName))).hasNoRows(); + assertThat(onTrino().executeQuery(format("SELECT * FROM %s WHERE _integer > 0", trinoTableName))).hasNoRows(); onSpark().executeQuery(format( "INSERT INTO %s VALUES (" +