Iceberg: a renamed field inside a struct is read as NULL (ORC always, Parquet with dereference pushdown)
Your Environment
- Presto version used: master at 9d4e69dce4 ("refactor: Declare a signature when registering a test RPC function (#28496)")
- Storage (HDFS/S3/GCS..): local file system
- Data source and connector used: Iceberg connector (Java reader), Hive and Hadoop catalogs
- Deployment (Cloud or On-prem): local
DistributedQueryRunnerin tests
Expected Behavior
After a field inside a struct column is renamed, reading that field by its new name returns the values already written, just like a renamed top-level column does.
Current Behavior
The renamed field comes back as NULL for data files written before the rename. The data is still in the files. It is read by the old name and not found.
How bad it is depends on the file format:
Query (after renaming s.a to s.a_renamed) |
Parquet | Parquet, parquet_dereference_pushdown_enabled = false |
ORC |
|---|---|---|---|
SELECT s |
{a_renamed=10, b=20} ✅ |
{a_renamed=10, b=20} ✅ |
{a_renamed=NULL, b=20} ❌ |
SELECT s.a_renamed |
NULL ❌ |
10 ✅ |
NULL ❌ |
SELECT count(*) WHERE s.a_renamed = 10 |
1 ✅ |
1 ✅ |
0 ❌ |
The field b, which was not renamed, is always read correctly. The result is the same with pushdown_subfields_enabled on or off.
Possible Solution
Iceberg matches columns by field id, not by name, so that a rename does not need to rewrite any data. The Presto Iceberg reader does this for top-level columns, but not always for fields inside a struct:
- Parquet: a top-level column is found by field id (
IcebergPageSourceProvider.java:466). A dereference pushed down into the Parquet reader, such ass.a_renamed, is found by its name path instead (IcebergPageSourceProvider.java:459). The file only has a field nameda, so nothing is found and NULL is returned. - ORC: even a full read of the struct loses the renamed field, so fields inside a struct seem to be matched by name in the ORC path as well. I haven't looked into where yet.
Workaround for Parquet: SET SESSION iceberg.parquet_dereference_pushdown_enabled = false. I found no workaround for ORC.
Steps to Reproduce
Presto can't rename a nested field (ALTER TABLE ... RENAME COLUMN only works on top-level columns), so the rename has to be done through the Iceberg API, Spark, or another engine.
- In Presto:
CREATE TABLE t (id INTEGER, s ROW(a INTEGER, b INTEGER)) WITH (format = 'ORC'); -- or 'PARQUET' INSERT INTO t VALUES (1, ROW(10, 20)); - Rename the nested field through Iceberg, for example in a Java test:or in Spark:
table.updateSchema().renameColumn("s.a", "a_renamed").commit();ALTER TABLE t RENAME COLUMN s.a TO a_renamed. - In Presto:Expected:
SELECT s FROM t; -- ORC: a_renamed is NULL SELECT s.a_renamed, s.b FROM t; -- NULL, 20 (both formats) SELECT count(*) FROM t WHERE s.a_renamed = 10; -- ORC: 010fors.a_renamedeverywhere, and a count of1.
Context
I found this while adding a test for time travel reads over nested schema changes in #28503. That PR doesn't touch this code path, and the results above are from master without it. Tables whose nested fields are renamed by Spark or another engine will return NULLs in Presto for rows written before the rename, with no error.
Source: prestodb/presto