Repository navigation
Description
Describe the bug
Currently, read_iceberg fills a column that a data file does not contain with NULL, even when the table schema gives that column an initial-default (Iceberg v3). The spec says readers must return the initial-default for such rows. PyIceberg's scan, Spark, DuckDB and polars do this. Daft returns NULL instead, and its filters see NULL too: c = 5 finds no rows and c IS NULL matches rows whose value is 5. Nothing is raised and nothing is logged.
IcebergDataSource builds its schema with convert_iceberg_schema and maps file columns through SchemaFieldIdMappingVisitor. Nothing on main reads NestedField.initial_default. The open PR #7356 rejects this case in read_iceberg_changes() because "silently returning None there would be a data-value correctness bug". read_iceberg still returns None.
To Reproduce
The table below is written with the Iceberg Java API through PySpark, which gives c an initial-default of 5 (pip install pyspark==4.0.4 daft pyiceberg):
import glob, os
from pyspark.sql import SparkSession
spark = (SparkSession.builder.master("local[1]")
.config("spark.jars.packages", "org.apache.iceberg:iceberg-spark-runtime-4.0_2.13:1.11.0")
.config("spark.sql.extensions", "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
.config("spark.sql.catalog.local", "org.apache.iceberg.spark.SparkCatalog")
.config("spark.sql.catalog.local.type", "hadoop")
.config("spark.sql.catalog.local.warehouse", os.path.abspath("wh"))
.getOrCreate())
spark.sql("CREATE TABLE local.db.t (id INT) USING iceberg TBLPROPERTIES ('format-version'='3')")
spark.sql("INSERT INTO local.db.t VALUES (1), (2)")
jvm = spark._jvm
table = jvm.org.apache.iceberg.spark.Spark3Util.loadIcebergTable(spark._jsparkSession, "local.db.t")
table.updateSchema().addColumn(
"c", jvm.org.apache.iceberg.types.Types.IntegerType.get(), "", jvm.org.apache.iceberg.expressions.Literal.of(5)
).commit()
spark.sql("REFRESH TABLE local.db.t")
spark.sql("INSERT INTO local.db.t VALUES (3, 7)")
spark.sql("SELECT * FROM local.db.t ORDER BY id").show()
# 1 5 / 2 5 / 3 7
import daft
from daft import col
from pyiceberg.table import StaticTable
metadata = max(glob.glob("wh/db/t/metadata/v*.metadata.json"), key=lambda p: int(os.path.basename(p)[1:].split(".")[0]))
t = StaticTable.from_metadata(os.path.abspath(metadata))
print(t.scan().to_arrow().sort_by("id").to_pylist())
# [{'id': 1, 'c': 5}, {'id': 2, 'c': 5}, {'id': 3, 'c': 7}]
print(daft.read_iceberg(t).sort("id").to_pylist())
# [{'id': 1, 'c': None}, {'id': 2, 'c': None}, {'id': 3, 'c': 7}]
print(daft.read_iceberg(t).where(col("c") == 5).to_pylist())
# []
print(daft.read_iceberg(t).where(col("c").is_null()).sort("id").to_pylist())
# [{'id': 1, 'c': None}, {'id': 2, 'c': None}]Expected behavior
[{'id': 1, 'c': 5}, {'id': 2, 'c': 5}, {'id': 3, 'c': 7}], the same rows Spark and PyIceberg return. c = 5 should return ids 1 and 2, and c IS NULL should return no rows. If defaults are not supported yet, read_iceberg should raise for a column with an initial-default rather than fill it with NULL. Nested fields behave the same way: a struct field added with a default reads as NULL in Daft.
Component(s)
Data Sources & Sinks
Additional context
daft 0.7.26, pyiceberg 0.12.0, pyspark 4.0.4 with iceberg-spark-runtime-4.0_2.13 1.11.0, Python 3.12.13, macOS 26.6.2, arm64 (Darwin 25.6.0). DuckDB 2.0.0 iceberg_scan and polars 2.1.0 scan_iceberg return 5 for the same table. Columns added without a default read as NULL in every reader, Daft included.
Activity
fix(iceberg): read Iceberg v3 initial-defaults instead of NULL