Indian-boult opened a new issue, #1013: URL: https://github.com/apache/incubator-xtable/issues/1013
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/incubator-xtable/issues?q=is%3Aissue) and found no similar issues. ### Please describe the bug 🐞 With `delta.columnMapping.mode` set to `name` or `id`, Delta keys the per-file stats (`minValues`, `maxValues`, `nullCount`) by the physical column name. The Delta source looks them up by the logical name in `DeltaStatsUtils.parseColumnStatsFromJson`, which both `DeltaStatsExtractor` and `DeltaKernelStatsExtractor` use. This has three effects: 1. On a table created with column mapping, physical names are `col-<uuid>`, so no column gets stats. Iceberg and Hudi targets get no min, max or null counts. 2. When column mapping is enabled on a table that already has data, the existing names become the physical names. After renaming `a` to `a_old` and adding a new `a`, the new `a` gets the stats of `a_old`, and `a_old` gets none. In files written before the new `a` existed, the new `a` reports 0 nulls, although all its values are null. Iceberg then skips those files for `a IS NULL` and returns wrong results. 3. If the re-added column has a different type, parsing the old column's stats can throw. For a DATE column it throws `DateTimeParseException`. Repro with Spark 3.4 and Delta 2.4.0, the versions XTable tests with: ```sql CREATE TABLE delta.`/tmp/cm_stats` (id INT, a INT) USING DELTA; INSERT INTO delta.`/tmp/cm_stats` VALUES (1, 10), (2, 20); ALTER TABLE delta.`/tmp/cm_stats` SET TBLPROPERTIES ( 'delta.minReaderVersion' = '2', 'delta.minWriterVersion' = '5', 'delta.columnMapping.mode' = 'name'); ALTER TABLE delta.`/tmp/cm_stats` RENAME COLUMN a TO a_old; ALTER TABLE delta.`/tmp/cm_stats` ADD COLUMNS (a INT); INSERT INTO delta.`/tmp/cm_stats` VALUES (3, 30, 300); ``` Stats in the Delta log. Here `a` is the physical name of `a_old`, and `col-80879e3e-...` is the physical name of the new `a`. ```text file 1: {"numRecords":2,"minValues":{"id":1,"a":10},"maxValues":{"id":2,"a":20},"nullCount":{"id":0,"a":0}} file 2: {"numRecords":1,"minValues":{"id":3,"a":30,"col-80879e3e-08a4-45b0-9976-0d45549da65f":300},"maxValues":{"id":3,"a":30,"col-80879e3e-08a4-45b0-9976-0d45549da65f":300},"nullCount":{"id":0,"a":0,"col-80879e3e-08a4-45b0-9976-0d45549da65f":0}} ``` Column stats from `getCurrentSnapshot()`, the same for `DeltaConversionSource` and `DeltaKernelConversionSource`: | File | Expected | Actual | | --- | --- | --- | | file 1 | `id` [1, 2], `a_old` [10, 20] | `id` [1, 2], `a` [10, 20] with 0 nulls | | file 2 | `id` [3, 3], `a_old` [30, 30], `a` [300, 300] | `id` [3, 3], `a` [30, 30] | After a sync to Iceberg, `SELECT * FROM <iceberg table> WHERE a IS NULL` returns 0 rows. A full scan shows rows 1 and 2 with `a` = NULL, so 2 rows are expected. In this setup Delta 2.4.0 also returns 0 rows for that filter, even with data skipping off, so compare against a full scan. If column mapping is set in `CREATE TABLE ... TBLPROPERTIES (...)` instead, the same steps give no stats for any column. Expected behavior: stats are read by physical name. Each column gets its own stats, and a column with no stats in a file gets no column stat. ### Are you willing to submit PR? - [X] I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
