diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java index 439997b7885c..c2fd246ded1c 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java @@ -392,7 +392,8 @@ private static void populateMapping( fieldNameToIdMappingForTableColumns.put( identity.getId(), identity.getChildren().stream() - .collect(toImmutableMap(ColumnIdentity::getName, ColumnIdentity::getId))); + // Lower casing is required here because ORC StructColumnReader does the same before mapping + .collect(toImmutableMap(child -> child.getName().toLowerCase(ENGLISH), ColumnIdentity::getId))); for (ColumnIdentity child : identity.getChildren()) { populateMapping(child, fieldNameToIdMappingForTableColumns); @@ -415,7 +416,9 @@ public IdBasedFieldMapper(Map idToColumnMappingForFile, Map< @Override public OrcColumn get(String fieldName) { - int fieldId = nameToIdMappingForTableColumns.get(fieldName); + int fieldId = requireNonNull( + nameToIdMappingForTableColumns.get(fieldName), + () -> format("Id mapping for field %s not found", fieldName)); return idToColumnMappingForFile.get(fieldId); } } diff --git a/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/environment/singlenode-spark-iceberg/iceberg.properties b/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/environment/singlenode-spark-iceberg/iceberg.properties index 7ce5303954a3..c2cf659b1b1e 100644 --- a/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/environment/singlenode-spark-iceberg/iceberg.properties +++ b/testing/trino-product-tests-launcher/src/main/resources/docker/presto-product-tests/conf/environment/singlenode-spark-iceberg/iceberg.properties @@ -1,2 +1,4 @@ connector.name=iceberg hive.metastore.uri=thrift://hadoop-master:9083 +# TODO: Remove this config to test default read behavior once Spark writer version is fixed. See https://github.com/trinodb/trino/issues/6369 for details +iceberg.use-file-size-from-metadata=false diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/iceberg/TestSparkCompatibility.java b/testing/trino-product-tests/src/main/java/io/trino/tests/iceberg/TestSparkCompatibility.java index d5bd2f171212..a72056662515 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/iceberg/TestSparkCompatibility.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/iceberg/TestSparkCompatibility.java @@ -367,11 +367,18 @@ public void testIdBasedFieldMapping() String prestoTableName = prestoTableName(baseTableName); String sparkTableName = sparkTableName(baseTableName); - onPresto().executeQuery(format( - "CREATE TABLE %s (_struct ROW(rename BIGINT, keep BIGINT, drop_and_add BIGINT), _partition BIGINT) " - + "WITH (partitioning = ARRAY['_partition'])", - prestoTableName)); - onPresto().executeQuery(format("INSERT INTO %s VALUES (row(1, 2, 3), 1001)", prestoTableName)); + onSpark().executeQuery(format( + "CREATE TABLE %s (_struct STRUCT, _partition BIGINT)" + + " USING ICEBERG" + + " partitioned by (_partition)" + + " TBLPROPERTIES ('write.format.default' = 'orc')", + sparkTableName)); + + onSpark().executeQuery(format( + "INSERT INTO TABLE %s SELECT " + + "named_struct('rename', 1, 'keep', 2, 'drop_and_add', 3, 'CaseSensitive', 4), " + + "1001", + sparkTableName)); // Alter nested fields using Spark. Presto does not support this yet. onSpark().executeQuery(format("ALTER TABLE %s RENAME COLUMN _struct.rename TO renamed", sparkTableName)); @@ -383,6 +390,7 @@ public void testIdBasedFieldMapping() // Rename does not change id .addField("renamed", 1L) .addField("keep", 2L) + .addField("CaseSensitive", 4L) // Dropping and re-adding changes id .addField("drop_and_add", null) .build(),