Iceberg: decimal stored as FIXED_LEN_BYTE_ARRAY fails with "Parquet argument error: EOF: Not enough bytes to decode"
Summary
An Iceberg table whose parquet stores a decimal(15,2) column as FIXED_LEN_BYTE_ARRAY(7) fails to read in Databend. That is pyarrow's default layout, and the Iceberg spec allows it. The same file reads fine as plain parquet through a stage, and the same rows stored as INT64 read fine through the Iceberg catalog.
SELECT k, d FROM ice.demo.dec_flba
-- Parquet argument error: EOF: Not enough bytes to decode.Version: v1.2.949-nightly (8.0.90-v1.2.949-nightly-2f5710f863), datafuselabs/databend:v1.2.949-nightly.
Reproduce
The only moving parts are an Iceberg REST catalog on a local warehouse and three rows.
mkdir -p /tmp/wh && chmod 777 /tmp/wh
docker run -d --name rest -p 8181:8181 -v /tmp/wh:/tmp/wh \
-e CATALOG_WAREHOUSE=file:///tmp/wh \
-e CATALOG_IO__IMPL=org.apache.iceberg.hadoop.HadoopFileIO \
apache/iceberg-rest-fixture:1.9.2
pip install "pyiceberg[pyarrow]" pymysqlimport pyarrow as pa, pyarrow.parquet as pq
from pyiceberg.catalog import load_catalog
from pyiceberg.schema import Schema
from pyiceberg.types import DecimalType, LongType, NestedField
catalog = load_catalog("rest", uri="http://localhost:8181")
catalog.create_namespace("demo")
schema = Schema(NestedField(1, "k", LongType()), NestedField(2, "d", DecimalType(15, 2)))
rows = pa.table({"k": pa.array([1, 2, 3], pa.int64()),
"d": pa.array([123.45, -7.01, 99999.99]).cast(pa.decimal128(15, 2))})
# pyarrow's default: d is FIXED_LEN_BYTE_ARRAY(7)
pq.write_table(rows, "/tmp/wh/dec_flba.parquet")
catalog.create_table("demo.dec_flba", schema=schema).add_files(["file:///tmp/wh/dec_flba.parquet"])
# pyiceberg's own write: d is INT64
catalog.create_table("demo.dec_int64", schema=schema).append(rows)docker run -d --name db --network host -v /tmp/wh:/tmp/wh datafuselabs/databend:v1.2.949-nightlyCREATE CATALOG ice TYPE=ICEBERG CONNECTION=(TYPE='rest' ADDRESS='http://localhost:8181'
WAREHOUSE='file:///tmp/wh' "root"='/');
SELECT k, d FROM ice.demo.dec_int64 ORDER BY k; -- OK: (1, 123.45), (2, -7.01), (3, 99999.99)
SELECT k FROM ice.demo.dec_flba ORDER BY k; -- OK: 1, 2, 3
SELECT k, d FROM ice.demo.dec_flba ORDER BY k; -- ERROR: Parquet argument error: EOF: Not enough bytes to decode.
-- the same FLBA file as plain parquet
CREATE STAGE s URL='fs:///tmp/wh/';
SELECT k, d FROM @s/dec_flba.parquet (FILE_FORMAT => 'parquet') ORDER BY k; -- OKpyiceberg reads both tables correctly.
Likely cause
IcebergTable::do_read_data builds its reader with ParquetReaderBuilder::create(ctx, op, table_schema, arrow_schema) (src/query/storages/iceberg/src/table.rs). create derives the parquet schema from the Arrow schema with ArrowSchemaConverter. That converter maps Decimal128 with precision ≤ 18 to INT64 (≤ 9 to INT32), which is the arrow-rs writer's choice. The read plan is built once from that descriptor, so a data file that stores the column as FIXED_LEN_BYTE_ARRAY gets its pages decoded as INT64, and the plain decoder runs out of bytes.
The stage reader takes its descriptor from the file, which is why it works. Files written by Spark (INT64) never hit this. Files written by pyarrow do, including pyiceberg add_files and any pipeline that rewrites parquet with pyarrow.
Impact: on TPC-H tables whose parquet was written by pyarrow, every query that reads a decimal column fails (17 of 22). The other 5 pass.
Side note: with a file:// warehouse the catalog needs "root"='/'; without it every read fails with ConfigInvalid ... root is not specified.
Source: databendlabs/databend