Repository navigation
Description
Basic Information
- Branch Name: main (task worktree)
- Commit ID: ac55588
- Other Environment Information:
- Hardware parameters: Apple silicon (darwin arm64), single local node
- OS type: macOS
- Others: standalone single-process
mo-service(offset launch config, mysql port 26601); local MinIO S3 (127.0.0.1:29600, bucketmo-iceberg, credentials minio/minio123); Nessie 0.108.1 Iceberg REST catalog athttp://127.0.0.1:39720/iceberg(IN_MEMORY store, default-branchmain, warehouses3://mo-iceberg/warehouse);MO_ICEBERG_ALLOW_PLAIN_HTTP=1; mysql client with--default-character-set=utf8mb4.
Actual Behavior
On a mapped Iceberg external table whose current snapshot contains one Parquet data file with multiple row groups, every SELECT whose predicate row-group-prunes at least one row group (but not all) fails deterministically:
mysql> SELECT id, amount FROM qa_db.rgr1 WHERE id = 1;
ERROR 20101 (HY000) at line 1: internal error: convert go error to mo error invalid magic footer of parquet file: "\x00\x00Z "
The same error is returned for WHERE id = 2, for COUNT(*) ... WHERE id = 1, etc. - three consecutive runs produce the identical message. The data file itself is valid: pyarrow reads it, the row (1, 2) exists in row-group 0, and its declared manifest size (161158 bytes) matches the real object size. Full-scan and non-pruning queries return correct results, so only predicate-selective reads are broken.
Expected Behavior
SELECT id, amount FROM qa_db.rgr1 WHERE id = 1 should return the single matching row 1, 2 (row-group pruning is an internal physical optimization and must not affect correctness).
Steps to Reproduce
Preconditions: MinIO at 127.0.0.1:29600 (bucket mo-iceberg), Nessie REST at http://127.0.0.1:39720/iceberg, mo-service at 127.0.0.1:26601 (root/111), MO_ICEBERG_ALLOW_PLAIN_HTTP=1.
- Create the remote Iceberg table (2 nullable-long columns, unpartitioned) and the namespace:
curl -s -X POST "http://127.0.0.1:39720/iceberg/v1/main/namespaces" -H "Content-Type: application/json" -d '{"namespace":["qa"]}'
curl -s -X POST "http://127.0.0.1:39720/iceberg/v1/main/namespaces/qa/tables" -H "Content-Type: application/json" -d '{
"name": "rgr1",
"schema": {"type": "struct", "schema-id": 0, "fields": [
{"id": 1, "name": "id", "required": true, "type": "long"},
{"id": 2, "name": "amount", "required": false, "type": "long"}]},
"partition-spec": {"spec-id": 0, "fields": []},
"stage-create": false}'- Map it in MatrixOne and load 10000 rows (one INSERT -> one data file -> 3 row groups of 4096/4096/1808 rows):
CREATE ICEBERG CATALOG nessie WITH ('type'='rest','uri'='http://127.0.0.1:39720/iceberg','warehouse'='s3://mo-iceberg/warehouse','auth_mode'='none');
CALL iceberg_register_access('nessie','scope=cluster,account_id=0,external_principal=qa-principal,endpoint=localhost,region=us-east-1,bucket=mo-iceberg');
CREATE DATABASE qa_db;
CREATE EXTERNAL TABLE qa_db.rgr1 (id BIGINT, amount BIGINT) ENGINE=ICEBERG WITH ('catalog'='nessie','namespace'='qa','table'='rgr1','ref'='main','read_mode'='merge_on_read','write_mode'='merge_on_read');
CREATE TABLE qa_db.ten (i INT);
INSERT INTO qa_db.ten VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
INSERT INTO qa_db.rgr1 SELECT t.i, t.i*2 FROM (SELECT a.i + 10*b.i + 100*c.i + 1000*d.i AS i FROM qa_db.ten a, qa_db.ten b, qa_db.ten c, qa_db.ten d) t;
SELECT COUNT(*) FROM qa_db.rgr1; -- 10000, OK- Trigger (fails every time):
SELECT id, amount FROM qa_db.rgr1 WHERE id = 1; -- ERROR 20101 invalid magic footer
SELECT COUNT(*) FROM qa_db.rgr1 WHERE id = 1; -- same error
SELECT id FROM qa_db.rgr1 WHERE id = 2 LIMIT 3; -- same error- Controls (all succeed):
SELECT COUNT(*) FROM qa_db.rgr1; -- 10000 (no predicate)
SELECT COUNT(*) FROM qa_db.rgr1 WHERE id >= 0 AND id < 10000; -- 10000 (predicate prunes no row group)
SELECT id, amount FROM qa_db.rgr1 WHERE id BETWEEN 0 AND 5; -- rows 0..5 (BETWEEN not used for row-group pruning)Additional information
Root cause chain (all on this commit):
pkg/sql/compile/compile_iceberg_scan.go:74-req.EnableRowGroupPlanning = len(req.PrunePredicates) > 0: any query with predicates enters row-group planning.pkg/iceberg/metadata/row_group_parquet.go-applyRowGroupPlanning: after reading real per-row-group footers it callsPruneRowGroupSplits(line 76). If nothing is pruned the ORIGINAL whole-file task is kept (lines 81-87) - that is why the control queries work. If at least one row group is pruned, each surviving row group becomes its own task withRowGroups=[split](lines 91-97).pkg/iceberg/metadata/row_group_parquet.go:190- each split'sBytesis set toestimateIcebergParquetRowGroupBytes(...), which at lines 450-455 isint64(float64(fileSize) * float64(rowGroupRows) / float64(totalRows))- an ESTIMATE, not the real file size.pkg/sql/compile/iceberg_runtime.go- the runtime task is initialized with the true size at line 103 (FileSize: file.FileSizeInBytes), but lines 114-123 overwrite it when the task points at a single row group: line 122runtimeTask.FileSize = rg.Bytes. For rg0:int64(161158 * 4096 / 10000) = 66010replaces the real 161158.pkg/sql/colexec/external/parquet.go- line 213 takesfileSizefromparam.FileSize[...]and line 252 callsparquet.OpenFile(r, fileSize). The parquet reader locates the footer via the file-size trailer (magic + footer length atfileSize-8), so it reads mid-file data as the footer and fails:invalid magic footer of parquet file: "\x00\x00Z ".
In short: row-group pruning shrinks the DATA slice a task should read, but the task's FileSize field is consumed by the parquet reader as the physical file length for footer discovery. Any pruning therefore corrupts file opening instead of narrowing it.
Impact: the MO Iceberg writer produces files with ~4096 rows per row group, so ANY Iceberg external table with more than 4096 rows in a data file cannot be queried with selective predicates (equality, point lookups, typical dashboard/lookup queries). Only full scans, predicates matching every row group, or predicate shapes that skip pruning still work. Deterministic across 3/3 fresh runs on this table and also reproduced earlier the same day on another table generated the same way (10010 rows, error variant "\x00\x886\x00"), on an independent mo-service instance - not flaky, purely a deterministic read-path defect.
Possible fixes: keep the true DataFile.FileSizeInBytes on row-group tasks and carry the estimated row-group byte size in a separate field for memory/parallelism accounting, or have the reader stat the object before parquet.OpenFile (as the delete-apply path already does with a real fs.StatFile).
No existing issue mentions invalid magic footer (GitHub search for "invalid magic footer" in this repo returns 0 results); checked #27196, #27209, #27237, #27200, #30431, #23359, #27894 - all different root causes (Spark-written manifest/schema handling, DATE file pruning, equality deletes, position-delete overflow).
Found by Loom bug hunt (module: custom-e69df17185; tests: unit, white-box, end-to-end)
Activity