# DuckDB Parquet 读取错误：schema 和数据页之间的列数不匹配

- **ID:** `data/duckdb-parquet-mismatch-column-count`
- **领域:** data
- **类别:** data_error
- **错误码:** `IOException`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Parquet 文件的元数据页脚损坏，schema 声明的列数多于实际数据页中的列数，通常由不完整的写入或文件截断引起。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| DuckDB 0.9.0+ | active | — | — |
| Apache Parquet 1.12.0+ | active | — | — |
| PyArrow 12.0.0+ | active | — | — |

## 解决方案

1. ```
   使用 PyArrow 读取并重写文件修复：`import pyarrow.parquet as pq; table = pq.read_table('corrupted.parquet'); pq.write_table(table, 'fixed.parquet')`
   ```
2. ```
   使用 DuckDB 的 `read_parquet` 并设置 `union_by_name=true` 尝试 schema 协调：`SELECT * FROM read_parquet('file.parquet', union_by_name=true)`
   ```
3. ```
   使用 `parquet-tools meta file.parquet` 手动检查 Parquet 元数据，并在可能的情况下截断页脚中的 schema。
   ```

## 无效尝试

- **** — The corruption is in the file itself; re-downloading the same source without verification repeats the issue. (60% 失败率)
- **** — DuckDB does not have an ignore_errors option for Parquet; it will fail on metadata parsing. (90% 失败率)
