Should Iceberg Define Function Semantics With Substrait? Stored Expressions and Cross-Engine Determinism

Iceberg increasingly stores expressions that every engine must evaluate the same way: UDFs, check constraints, statistics on partition expressions and generated.

13 Mins readAlex Merced
Should Iceberg Define Function Semantics With Substrait? Stored Expressions and Cross-Engine Determinism

Iceberg increasingly stores expressions that every engine must evaluate the same way: UDFs, check constraints, statistics on partition expressions and generated columns. Float ordering already differs between engines. On Nov 23, 2026, Matt Topol suggested Iceberg define function semantics with Substrait, the existing cross-engine expression standard, rather than writing its own.

Here’s a bug that hasn’t happened to you yet. A table has a check constraint, discount_rate <= 1.0. One engine writes a row where discount_rate is NaN, the floating-point “not a number” value. That engine treats NaN <= 1.0 as false and rejects the row. Another engine, with different NaN semantics, accepts it. Now the table holds data that violates its own constraint, depending on which engine wrote it. A third engine’s planner trusts the constraint to skip a filter, and returns wrong results.

Nothing in that story is exotic. Engines really do disagree on NaN, NULL, and overflow behavior. The difference is that until recently, Apache Iceberg tables mostly stored data and simple partition transforms. As Iceberg starts storing expressions that engines evaluate and trust, those disagreements stop being query quirks. They turn into table correctness problems.

That’s the debate running on the Iceberg dev list under the subject “Cross-engine determinism for functions in stored expressions.” This article explains the problem, the positions in the thread, and why Matt Topol’s November 23 suggestion to lean on Substrait deserves serious attention.

Where Iceberg Stores Expressions

Iceberg has always stored a few expressions. Partition transforms such as bucket(16, id) and day(event_ts) are the oldest. The spec defines them exactly, down to the hash function for buckets, because every engine must compute the same partition for the same row. That precision is why Iceberg partitioning works across engines.

The list of stored expressions is growing. The thread names several features in scope:

  • User-defined functions (UDFs). Functions stored in the catalog and callable from SQL in any engine.
  • Check constraints. Boolean expressions every row must satisfy.
  • Derived or generated columns. Columns computed from other columns by a stored expression.
  • Column statistics and index keys. Statistics computed over expressions, including multi-column orderings such as Hilbert curves, used for pruning.
  • Write default values, though one participant noted default values aren’t affected, since they’re literals.

Each of these asks two or more engines to evaluate the same expression and agree. Partition transforms got that guarantee because the spec defined each transform exactly. Arbitrary expressions have no such definition yet.

Why Engines Disagree

The thread lists the usual suspects: NULL handling, floating-point math, and regular expressions. Each one has real, documented divergence across engines.

NULL handling. SQL’s three-valued logic is standard, but functions differ. Does concat('a', NULL) return NULL or 'a'? It depends on the engine and sometimes on a configuration flag.

Floating-point math. IEEE 754 defines float arithmetic, but engines differ in how they compare NaNs, whether -0.0 equals 0.0 in all contexts, and how aggregates order operations, which changes rounding.

Regular expressions. Java regex, RE2, PCRE, and POSIX regex differ in syntax and semantics. The same pattern string matches different text in different engines.

Overflow. Integer overflow wraps silently in some engines, errors in others, and saturates in a few.

Casting. String to timestamp, decimal rounding, and timezone handling vary widely.

For ad hoc queries, these differences cause surprises. For stored expressions that engines trust, they cause corruption. That’s the distinction that makes this debate matter.

A Concrete Divergence: Float and NaN Ordering

The thread didn’t happen in a vacuum. On November 19, 2026, Matt Butrovich opened issue #19040, “Spec: Float sort order puts -NaN first but says it matches Java.” It’s a clean example of the whole problem.

The Iceberg spec’s float sort rule puts -NaN below negative infinity and NaN above positive infinity. The spec says this “aligns with the implementation of Java floating-point types comparisons.” The issue points out that it doesn’t. Java’s Double.compareTo treats every NaN as equal and greater than positive infinity, so Java has no low-end -NaN. The spec’s described order matches IEEE 754 totalOrder instead.

And the implementations split along that seam. Iceberg Java uses Comparator.naturalOrder(), which is Double.compareTo. iceberg-rust uses total_cmp, which puts negative NaNs first and orders NaNs by payload. Same spec, two behaviors.

It gets worse. IEEE 754 leaves the sign of a NaN produced by arithmetic unspecified. For 0.0 / 0.0, x86 SSE and AArch64 produce different bit patterns. So the same computation on two machines produces NaNs that sort at opposite ends under totalOrder. The issue notes this matters for ordering keys in the proposed secondary index spec, which cites this rule.

The proposed fix is to specify that all NaN representations compare equal and sort after infinity. That matches Java and the spec’s own wording. It constrains only comparison, so stored values keep their bits and writers don’t have to canonicalize NaNs. A fix PR, #19069, is open.

Notice the scale of effort for one comparison rule. One function, one type, two implementations, a spec ambiguity, and a hardware dependence. Now multiply by every function a UDF, constraint, or generated column calls.

The Positions in the Thread

The thread surfaced a spectrum of views. Here they are in order from most constrained to most open.

Restrict trusted expressions to exactly specified functions. Matt Butrovich proposed limiting statistics and index keys to functions the Iceberg spec defines exactly, keeping UDFs for stored values, and adding a volatility enum to classify functions. Under this view, anything an engine trusts for correctness uses a small, fully specified function set, like partition transforms today.

Let engines define their own functions. Andrei Tserakhau and Szehon Ho favored letting engines define functions in their own dialects, with readers skipping what they don’t understand. Under this view, an engine that can’t evaluate an expression with confidence ignores it, rather than trusting it.

Use an existing standard for function semantics. Matt Topol’s message on November 23 observed that the group was “basically re-implementing something like” Substrait. He asked whether others had looked at Substrait as a way to specify UDFs, expressions, and related behavior.

The thread also named where risk concentrates. Check constraints and derived columns are highest risk, because planners trust them and a mismatch corrupts data on write or read. Engine-specific UDF bodies can’t be verified by annotations alone, and engine dialects change between versions.

What Substrait Is

Substrait is an open specification for representing relational query plans and expressions in a cross-language, engine-neutral form. Engines produce Substrait plans, and other engines consume them. Apache Arrow’s Acero engine, DuckDB through an extension, Apache DataFusion, Velox, and others support it in varying degrees.

The part relevant to Iceberg is how Substrait defines functions. It doesn’t hard-code a function list into its core. Instead, functions live in YAML extension files.

  • Each file has a urn of the form extension:<owner>:<id>, with the owner in reverse-domain style.
  • Each function has signatures made of its name and short type names, such as add:i8_i8 or avg:fp32.
  • Plans reference functions by extension URN plus signature, with integer anchors inside the plan.
  • Functions carry options that pin down behavior engines usually disagree on.

That last point is the key. Substrait’s arithmetic functions document options like these:

  • overflow: SILENT, SATURATE, or ERROR
  • rounding: TIE_TO_EVEN, TIE_AWAY_FROM_ZERO, TRUNCATE, CEILING, or FLOOR
  • on_division_by_zero for divide: IEEE, LIMIT, NULL, or ERROR
  • on_domain_error: NAN, NULL, or ERROR

Those are precisely the dimensions on which engines diverge. A stored expression that references divide with on_division_by_zero = NULL says exactly what should happen. An engine either implements that behavior or knows it doesn’t.

What a Substrait Function Definition Looks Like

Here’s the shape of a Substrait simple extension file defining one scalar function. The function is invented for illustration. The structure follows Substrait’s simple extension format:

urn: extension:com.example:lakehouse_functions
scalar_functions:
  - name: safe_ratio
    description: >
      Ratio of two doubles. Division by zero returns NULL.
      Defined for use in generated columns and constraints.
    impls:
      - args:
          - name: numerator
            value: fp64
          - name: denominator
            value: fp64
        options:
          on_division_by_zero:
            values: [ NULL ]
          rounding:
            values: [ TIE_TO_EVEN ]
        nullability: MIRROR
        deterministic: true
        return: fp64

The urn names the extension so plans and catalogs reference it unambiguously. The scalar_functions list holds one function with a description humans can read. Each entry under impls is one signature. Here it’s safe_ratio:fp64_fp64. The options block narrows behavior to a single choice for division by zero and for rounding, so there’s nothing left for an engine to interpret. nullability: MIRROR says the result is NULL when any input is NULL. deterministic: true says the same inputs always produce the same output, which is exactly the property a planner needs before it trusts the function in a constraint or statistic.

Compare that with a SQL UDF body stored as a string in one engine’s dialect. The string says what to compute. It doesn’t say how overflow, NULLs, division by zero, or rounding behave, because the dialect assumes its own engine’s defaults. Another engine reading the same string fills in its own defaults, and gets a different answer.

How Partition Transforms Got It Right

It’s worth looking at why partition transforms never had this problem, because they’re the model any solution has to match.

Take the bucket transform. The Iceberg spec doesn’t just say “hash the value into N buckets.” It names the hash function: 32-bit Murmur3, x86 variant, with a seed of zero. It specifies the exact bytes to hash for each type. Integers and longs hash as 8-byte little-endian longs, so an int and a long with the same value land in the same bucket. Strings hash as their UTF-8 bytes. Decimals hash as the minimum number of bytes of their two’s-complement unscaled value. Then it specifies the arithmetic for turning the hash into a bucket number, including masking the sign bit before taking the modulus.

That level of detail is what makes it work. A Rust writer and a Java reader compute the same bucket for the same row, every time, on every machine. Without that detail, partition pruning silently drops rows.

The truncate, year, month, day, and hour transforms get the same treatment. Truncation of negative integers rounds toward negative infinity, not toward zero, and the spec says so. Timestamps convert with defined epoch arithmetic.

This is the bar every trusted expression has to meet. The question in the thread is how to reach that bar for many more functions without the Iceberg spec growing into a function library. Partition transforms show the bar is reachable. They also show it took careful definitions for a handful of functions, which is why nobody wants to write hundreds more by hand.

Volatility: The Classification Every Option Needs

Matt Butrovich’s proposal included a volatility enum. Whatever source of semantics Iceberg picks, it needs some version of this classification, so it’s worth understanding.

Databases have long classified functions by how their output depends on inputs. PostgreSQL’s three levels are the familiar example.

  • Immutable. Same inputs always give the same output, forever. abs(x) and lower(s) qualify, assuming fixed collation rules.
  • Stable. Same inputs give the same output within one query, but can change between queries. Anything reading the current timezone setting or a lookup table falls here.
  • Volatile. Output can change on every call. random() and now() qualify.

For stored expressions, the classification decides what’s safe. A planner can only trust immutable functions in statistics, index keys, constraints, and generated columns. A stable function in a generated column produces values that depend on when and where they were computed. A volatile function there is meaningless.

Substrait carries a related property directly. Each function implementation has a deterministic flag. That’s not a full volatility model, but it covers the most important line: whether repeated evaluation can give different answers.

The practical consequence is that Iceberg needs to know a function’s volatility before it lets the function into a trusted context. A dialect string doesn’t carry that. A Substrait reference does, at least for determinism. An Iceberg-defined function set declares it per function.

Where Substrait Fits in Iceberg Metadata

If the community goes the Substrait route, there are practical questions about storage. None of these are settled, and the thread hasn’t proposed answers. Here are the choices any design has to make.

Encoding. Substrait plans and expressions are defined in Protocol Buffers, and there’s a JSON form of the same messages. Iceberg metadata is JSON. Storing Substrait expressions as JSON keeps metadata human-readable. Storing them as base64-encoded binary keeps them compact. Readability usually wins in Iceberg’s design.

Version pinning. Substrait evolves on its own schedule. A stored expression must record which Substrait version it targets, so a reader knows whether it understands it.

Extension references. Expressions reference functions by extension URN and signature. Iceberg needs a rule for which extension URNs are allowed. One option is “Substrait’s standard extensions only, plus registered Iceberg extensions.” Another is “anything, with readers skipping what they don’t know.” The choice decides how much freedom engines get and how much safety readers get.

Fallback. Engines that don’t speak Substrait need a defined behavior. Refuse to write to tables with Substrait constraints they can’t evaluate? Skip and warn? For trusted expressions, refusing to write is the only safe default.

Coexistence with dialect strings. Views in Iceberg already store SQL in multiple dialects. A UDF can store a Substrait definition the same way, alongside dialect bodies for engines that prefer them, with the Substrait definition as the authority when they disagree.

These are the questions a design document has to answer. They’re answerable. The harder question is whether enough engines will implement Substrait consumption to make the investment pay off.

Option A: Iceberg-Defined Semantics

The alternative to Substrait is for Iceberg to define the semantics itself, the way it defined partition transforms.

Advantages. Iceberg controls the definitions completely. The function set stays small and fits table-format needs exactly. Implementers read one spec. There’s a strong precedent, since partition transforms work well.

Costs. Every function needs a definition precise enough to implement identically in Java, Rust, Go, Python, C++, and every engine. The NaN ordering issue shows how hard one comparison rule is. A useful function library is dozens or hundreds of functions. Iceberg ends up building a function specification project inside a table format project.

Fit. Strong for a small set of functions engines trust for correctness, such as statistics transforms and index keys. Weak for general UDFs.

Option B: Reference Substrait

Iceberg stores expressions as Substrait expressions, or references Substrait function definitions by URN and signature.

Advantages. The function semantics work already exists, with options for exactly the behaviors that diverge. Engines that already speak Substrait reuse their implementations. Iceberg stays focused on being a table format. Extension files let projects define new functions without changing Iceberg’s spec.

Costs. Every engine that reads Iceberg stored expressions must understand Substrait, at least the subset used. Substrait has its own versioning and release cadence, and Iceberg then depends on it. Engine support for Substrait varies widely, and some major engines don’t consume it at all. Substrait’s function library has gaps of its own. And “references Substrait” still needs Iceberg rules for which functions and options are allowed in which contexts.

Fit. Strong for a general UDF and expression system shared across engines. It depends on engine adoption that isn’t universal today.

Option C: Engine Dialects With Skip-If-Unknown

Engines store expressions in their own dialects, tagged with the dialect. Readers that don’t understand a dialect skip the expression.

Advantages. Zero new specification. Each engine uses what it already has.

Costs. Skipping is safe for optional hints and unsafe for anything that must hold. A check constraint that one engine skips isn’t a constraint for that engine’s writes. A generated column one engine can’t compute either blocks writes or produces wrong values.

Fit. Fine for UDFs used only in reads, where each engine runs its own version. Poor for anything trusted for correctness across engines.

Matching Options to Features

The options aren’t exclusive. The thread’s own analysis points to a split by feature risk:

FeatureTrusted by planners or writers?Reasonable semantics source
Partition transformsYesIceberg spec (today)
Statistics and index keysYesIceberg spec, small exact set
Check constraintsYesExact semantics required, Substrait a strong candidate
Generated columnsYesExact semantics required, Substrait a strong candidate
Read-time UDFsNo, each engine runs its ownDialects with skip-if-unknown, or Substrait for portability

The pattern is simple. Where an engine trusts an expression for correctness, semantics must be exact and shared. Where each engine only runs the expression for its own reads, dialects are tolerable. Substrait’s value is highest in the middle rows, where exactness matters and the function set is too big for Iceberg to define alone.

What This Means for Practitioners Today

None of this is in the spec yet. Here’s what to do now if you use stored expressions or plan to.

Avoid floating-point columns in constraints and partition-like expressions. Use DECIMAL where you can. The NaN ordering issue alone is a reason.

Keep trusted expressions engine-portable. If you define a constraint or generated column, write it with simple comparisons and arithmetic on integers, decimals, dates, and strings. Avoid regex, string functions with NULL-handling quirks, and casts.

Test across engines. If two engines write the same table, run a small test that inserts edge-case values through each: NULLs, NaN, infinities, -0.0, extreme integers, empty strings. Then read back with each engine and compare.

Know your engine’s NaN rules. Spark SQL documents that NaN equals NaN and sorts greater than any other value, for example. Other engines differ.

Here’s a quick cross-engine probe you can adapt. Run the same statement in each engine you use and compare:

SELECT
  CAST('NaN' AS DOUBLE) = CAST('NaN' AS DOUBLE)         AS nan_equals_nan,
  CAST('NaN' AS DOUBLE) > CAST('Infinity' AS DOUBLE)     AS nan_above_inf,
  CAST('-0.0' AS DOUBLE) = CAST('0.0' AS DOUBLE)         AS neg_zero_equals_zero,
  concat('a', CAST(NULL AS VARCHAR))                     AS concat_with_null,
  1.0 / 0.0                                              AS float_div_by_zero;

Each column probes one known divergence. NaN equality and NaN ordering versus infinity test the exact rule in issue #19040. Negative zero tests signed-zero handling. concat with NULL tests NULL propagation in string functions. Division by zero tests error, NULL, or infinity behavior. Some engines reject some of these expressions outright, which is itself a finding. Engines also differ in literal syntax and cast names, so adjust as needed. Record the results per engine and keep them next to any stored expression design.

Failure Modes and Warning Signs

Constraint violations that depend on the writer. Warning sign: rows that violate a constraint exist in a table with that constraint. Cause: an engine that evaluated the constraint differently, or skipped it. Fix: audit which engines write the table and which evaluate constraints.

Pruning that drops valid rows. Warning sign: a query with a filter returns fewer rows than a full scan with the same filter applied later. Cause: statistics computed with one ordering and compared with another. Fix: report it with the data types involved. Float columns are the usual suspect.

Generated column drift. Warning sign: a generated column’s value doesn’t match recomputing it from source columns. Cause: different engines computed it with different semantics. Fix: restrict generated columns to portable expressions, and recompute with one engine.

UDF result mismatches. Warning sign: the same UDF returns different results in two engines. Cause: dialect differences in NULLs, overflow, or casting. Fix: treat UDFs as engine-local until a shared semantics source exists.

What to Watch at the UDF Sync

The Iceberg community runs a biweekly UDF sync, and its next meeting was scheduled for December 3, 2026. Three outcomes from that conversation are worth watching.

  1. Whether the float ordering fix lands as specified in issue #19040’s proposal. It’s the smallest decision and a test of how the community resolves semantics questions.
  2. Whether trusted expressions get a restricted function set. That’s the Butrovich direction, and it’s likely the first thing to reach the spec in some form.
  3. Whether Substrait gets a design document. A serious proposal needs one. It has to answer which Substrait version, which subset of functions and options, and how engines that don’t speak Substrait participate.

Conclusion

Iceberg’s partition transforms work across engines because the spec defines them exactly. As Iceberg starts storing check constraints, generated columns, statistics over expressions, and UDFs, it needs the same exactness for a much larger function surface. The float ordering issue shows how much work exactness takes for a single comparison.

Matt Topol’s question cuts to the core. A cross-engine standard for function semantics already exists, with options for exactly the behaviors engines disagree on. Whether Iceberg references Substrait, defines a small exact set itself, or splits the difference by feature, the direction is clear. Expressions that engines trust for correctness need semantics that leave nothing to interpretation. Until the spec delivers that, keep trusted expressions simple, avoid floats in them, and test across every engine that writes your tables.

For related context, see the materialized view spec vote, table constraints in Iceberg v4, the proposal for AI functions in Iceberg’s Spark and Flink connectors, and the Iceberg and Parquet spec ambiguity ledger.

Sources: Matt Topol, Nov 23, 2026 · Issue #19040 · Substrait extensions · Substrait arithmetic functions

Keep Going

If this piece was useful, I have written a lot more on how the Iceberg specification works and evolves. Apache Iceberg: The Definitive Guide (O’Reilly) covers partition transforms, the spec’s design principles, and how engines implement them. You can find every book I have written, across lakehouse architecture, Apache Iceberg, Apache Polaris, and AI, at books.alexmerced.com.

Share :

Related Posts

ADBC 1.2 Planning: Metadata API, Credential Callbacks, Vendor Actions and What Driver Authors Should Expect

ADBC 1.2 Planning: Metadata API, Credential Callbacks, Vendor Actions and What Driver Authors Should Expect

ADBC 1.2 is the next revision of the Arrow Database Connectivity API, not a driver release. A Nov 24, 2026 planning session agreed on a credential callback limited to calling SetOption, on JSON struct...

Events and Skills Over MCP: What the Beta Extensions Change for Data Platform MCP Servers

Events and Skills Over MCP: What the Beta Extensions Change for Data Platform MCP Servers

Two MCP extensions reached beta in November 2026. Events lets an agent react when something happens, such as a commit to a table, without polling. Skills over MCP lets a server ship guidance on how to...

Compaction Against Concurrent Deletion Vectors in Iceberg: Re-Plan-and-Retry vs a Persisted Compaction Map

Compaction Against Concurrent Deletion Vectors in Iceberg: Re-Plan-and-Retry vs a Persisted Compaction Map

When deletion vectors land while Spark's RewriteDataFiles runs, compaction commits can fail, because every file group was planned from one starting snapshot. On Nov 24, 2026, Iceberg contributors lean...

Work with Alex