Indian-boult opened a new issue, #1015:
URL: https://github.com/apache/incubator-xtable/issues/1015

   ### 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 🐞
   
   Paimon stores each data file's value stats by position in the schema the 
file was written with (`DataFileMeta#schemaId()`). When 
`DataFileMeta#valueStatsCols()` is null, which is the default when every column 
has stats, `PaimonStatsExtractor` reads the stats by position in the snapshot 
schema instead. After a schema change, files written before it are read with 
the wrong layout:
   
   1. After `ADD COLUMN`, the sync fails for every target with `ReadException: 
Mismatch between column stats names and values arity: names=3, values=2`. This 
also happens after a rename followed by an add.
   2. After `DROP COLUMN b` and `ADD COLUMN c`, the arity matches, so `c` gets 
the stats of `b` in the old files, including a null count of 0. Iceberg then 
skips those files for `c IS NULL`, although `c` is null in all their rows.
   3. After a type change such as INT to BIGINT or FLOAT to DOUBLE, old values 
are read with the new type. The result is not defined. In one run `a` (values 
-5 and 7) got the range [4294967291, 7], and `f` (values -1.5 and 2.5) got 
[1.59E-314, 5.32E-315].
   
   This affects append tables and primary-key tables. A compacted file keeps 
its old schema until it is rewritten.
   
   Repro with Paimon 1.3.1, an append table, writes without compaction:
   
   1. Create `t (id INT, a INT, b INT)` and write `(1, 10, 100)`, `(2, 20, 
200)`.
   2. `ALTER TABLE t DROP COLUMN b`, then `ALTER TABLE t ADD COLUMN c INT`.
   3. Write `(3, 30, 3000)`.
   4. Sync `t` to Iceberg with XTable and run `SELECT * FROM <iceberg table> 
WHERE c IS NULL`.
   
   Expected 2 rows (`id` 1 and 2). Actual 0 rows. The old file has stats `c` 
[100, 200] with 0 nulls in XTable. If step 2 is only `ADD COLUMN c INT` on `t 
(id INT, a INT)`, the sync fails with the `ReadException` above.
   
   Expected behavior: stats are read by the file's own schema and matched to 
the current columns by field id. A column added after the file was written, or 
whose type changed, gets no stats from that file.
   
   ### 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]

Reply via email to