Correct typo for the two last points:
The way an engine can handle unknown foreign expressions:
1. do not write to columns with unknown check constraint expression, or
unknown generated column expressions, or unknown write default value
expression, and do not generate unknown expression stats
2. do not use unknown expressions on those columns for read optimizations
(but you can always read the value directly).

On Fri, Nov 20, 2026 at 3:51 PM Szehon Ho <[email protected]> wrote:

> Sorry I missed the discussion, but thanks for summarizing.  I kind of
> agree with Andrei, I think the Expression spec does have a clause for
> engine specific functions:
>
> Engines may document and use a catalog name to identify their built-in
>> functions that are not part of the SQL spec, like
>> spark_builtin_functions.to_utc_timestamp.
>
> Ref:
> https://github.com/apache/iceberg/blob/main/format/expressions-spec.md#apply-function
>
> That allows the engine to move faster as Andrei mentioned.
>
> The idea of the sync, to have a set of well defined function semantics for
> common things like Hilbert index does make sense.  But I agree with Andrei,
> we might not want to limit user of Spark/Trino/etc from defining other
> generated column, constraint, stats expression in Iceberg that are
> 'engine-specific'.  Even sharing across Spark or Trino instance is a huge
> first step.
>
> So I think the namespace, ie, sql_functions, spark_builtin_functions,
> iceberg_functions (for those aforementioned well-defined ones), it can be a
> starting point for the engine to know whether it understands the semantics
> and can evaluate this expression?  The way an engine can handle it is
> 1. do not write to those columns with unknown check constraint, or
> generated column expressions, and do not generate expression stats
> 2. do not use those expressions for optimizations on read (but you can
> always the value directly).
>
> Thanks
> Szehon
>
> On Fri, Nov 20, 2026 at 3:35 PM Marco Kroll <[email protected]>
> wrote:
>
>> Hi everyone,
>>
>> Let me pull out my list again:
>> 1. `Default Values` - Not impacted
>> 2. `Constraints` - Critical, possibility of data corruption during write.
>> Introduce an 'allow-list', aka only iceberg functions. Reason: Iceberg
>> needs to ensure that ALL engines produce the SAME result.
>> 3. `Derived Columns` - Critical, possibility of data corruption during
>> read. Solution identical to `Constraints`
>> 4. `Stats-only` - Not-Critical. Engines can ignore it. Proposal: Store an
>> identifier that specifies how to reproduce the SAME result.
>>
>> So basically we 'split' it into 2 classes:
>> 1. Features with expressions that can be either ignored (stats-only) or
>> that get materialized (default values)
>> 2. Features where reproducibility across engines matters (constraints +
>> derived)
>>
>> Regarding `Constraints` and `Derived Columns` as already stated by the
>> others we need an allow-list of functions with semantics defined by
>> Iceberg, not just names.
>> Today that is only `iceberg_functions` (if_else + partition transforms)
>> [1]
>>
>> One problem that I'm currently seeing is that the expressions spec lets
>> us write `ColA + ColB < ColC` or `amount * (1 + tax)` via `apply` with
>> `sql_functions` or a UDF [2].
>> But it doesn't define what they mean. So we are back to the problem of
>> rounding, overflow and error handling implemented differently in engines.
>> Which means we now need to define them as well, raising the question
>> should we?
>>
>>
>> Best
>> Marco
>>
>>
>> [1]:
>> https://github.com/apache/iceberg/blob/main/format/expressions-spec.md
>> [2]: https://github.com/apache/iceberg/blob/main/format/udf-spec.md
>>
>> On Fri, Nov 20, 2026 at 1:08 PM Péter Váry <[email protected]>
>> wrote:
>>
>>> I don't have a solution yet and need more time to think about this, but
>>> I wanted to jot down two concerns.
>>> How would we store the "implementation that produced" the stats for a
>>> table written by Trino and Flink and later maintained by Spark? It seems we
>>> would need to track which engine computed the stats for every file and
>>> metadata file.
>>> Also, this is not specific to stats. We need similar guarantees for
>>> constraints, index values, derived columns, etc.
>>> Thanks, Peter
>>>
>>> Andrei Tserakhau via dev <[email protected]> ezt írta (időpont:
>>> 2026. nov. 20., P, 12:03):
>>>
>>>> Agree with Matt here on silent disagreement.
>>>>
>>>> This is the real problem, but i don't think that means that we shall
>>>> restrict ourselves into spec-only functions everywhere. Stats-only fields
>>>> are meant as optimization, so it's fine for an engine to just skip them.
>>>> What it can't do now is notice the disagreement itself, array_contains here
>>>> is a good example.
>>>>
>>>> One option here is to codify this doubt: store stats computed with a
>>>> non-spec function along with the name of the implementation that produced
>>>> them (engine or versioned shared library). A reader uses them only if it
>>>> can truly understand them; otherwise, it ignores them and scans. Spec
>>>> functions need no tag, since they are clearly specified. Engines that share
>>>> code (like Trino-based ones) still get the pruning, and nobody gets wrong
>>>> results. The good example of such behavior is collation bounds, they
>>>> already work this way by embedding collator version.
>>>>
>>>> This also leaves room for an engine to move faster than the spec. An
>>>> engine (or group of engines that can share code) can define functions on
>>>> its own and use each other's stats. Everyon else ignores them and scans
>>>> which is no worse than today. When a function proves useful, it can be
>>>> moved into a specified function with exact semantics and test vectors.
>>>> Puffin blob types work the same way: open names, readers skip what they
>>>> don't know.
>>>>
>>>> Best,
>>>> Andrei
>>>>
>>>> On Fri, Nov 20, 2026 at 4:56 AM huaxin gao <[email protected]>
>>>> wrote:
>>>>
>>>>> I agree with Matt's proposal.
>>>>>
>>>>> In my first email I said allowing only Iceberg functions was too
>>>>> limiting, because things like a Hilbert curve need functions Iceberg
>>>>> doesn't have. Matt's proposal answers that: those become Iceberg functions
>>>>> with exact semantics and test vectors. The cost is a longer function list,
>>>>> but I now think that's the right trade. Nobody can really promise that
>>>>> every dialect's body returns the same result. As Matt said, even with 
>>>>> Spark
>>>>> as a reference to test against, matching Spark's results for a fixed set 
>>>>> of
>>>>> functions in Comet took years, and differences still turn up. I saw this
>>>>> firsthand when I worked on Comet. A UDF author has much less to work with.
>>>>>
>>>>> For check constraints, I prefer allowing only exactly specified
>>>>> functions, and I'd apply it to all check constraints, not only the ones
>>>>> planners rely on. Every engine must get the same result for the same row,
>>>>> both when writing and when planning. Otherwise a row that passes in one
>>>>> engine can fail in another, and the constraint status can't be trusted. So
>>>>> check constraints should follow the same rule as index keys and stats-only
>>>>> fields.
>>>>>
>>>>> I think derived columns that are computed again on read should follow
>>>>> the same rule.
>>>>>
>>>>> I'm happy to update the constraint spec once we agree.
>>>>>
>>>>> Thanks,
>>>>> Huaxin
>>>>>
>>>>> On Thu, Nov 19, 2026 at 10:11 AM Matt Butrovich via dev <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Thanks everyone for the discussion in today's sync. Since my last
>>>>>> message I've looked at how often engines actually agree, and I'd like to
>>>>>> narrow what I proposed.
>>>>>>
>>>>>> Both the current `deterministic` rule and an IMMUTABLE level in the
>>>>>> enum rest on the UDF author promising that every dialect's body returns 
>>>>>> the
>>>>>> same result. I don't think anyone can keep that promise. Engines disagree
>>>>>> on details the SQL spec leaves open, and nobody knows all of them.
>>>>>>
>>>>>> For example, `array_contains(array(1, NULL), 2)` is NULL in Spark and
>>>>>> false in DataFusion and DuckDB. The SQL spec doesn't define
>>>>>> `array_contains`, both answers are defensible, and Spark kept its 
>>>>>> behavior
>>>>>> on purpose [1][2]. Under Iceberg's null-safe comparisons [3], a check 
>>>>>> like
>>>>>> `array_contains(tags, 'pii') = false` rejects that row in Spark and 
>>>>>> accepts
>>>>>> it in DataFusion. An author who writes that call in both bodies has no
>>>>>> reason to suspect a difference. `ln(0)` is NULL in Spark and -Infinity in
>>>>>> DataFusion, and their `ln` results differ in the last bit on about 2% of
>>>>>> inputs [4][5][6]. Regex engines differ too [7]. Engines also sort floats
>>>>>> differently around NaN and -0.0, and I filed #19040 [8] for the spec side
>>>>>> of that.
>>>>>>
>>>>>> This matches what we've seen on Comet. We've spent over two years
>>>>>> making Rust match Spark for a fixed set of functions, and we still keep a
>>>>>> list of known differences [7]. That's with a reference engine to test
>>>>>> against and fall back to. A UDF author has neither.
>>>>>>
>>>>>> Here's what I'd propose now:
>>>>>>
>>>>>> 1. Stats-only fields and index ordering keys use only functions
>>>>>> defined in the Iceberg spec, each with exact semantics and test vectors,
>>>>>> the way `bucket` works today [13]. A Hilbert curve would become one of
>>>>>> these functions.
>>>>>> 2. UDFs stay allowed for values that are computed once and stored,
>>>>>> like write defaults.
>>>>>> 3. I still like Peter's volatility enum for UDFs, as long as unknown
>>>>>> values read as VOLATILE and the old `deterministic` flag never maps to
>>>>>> IMMUTABLE.
>>>>>>
>>>>>> That's close to Huaxin's option 2 for index keys and stats-only
>>>>>> fields. It means a longer list of Iceberg functions. But each one gets
>>>>>> specified once, instead of every pair of engines finding their 
>>>>>> differences
>>>>>> through wrong results.
>>>>>>
>>>>>> Check constraints are the hard part, because the point is to let
>>>>>> planners trust them. The v4 rule already allows UDFs that declare
>>>>>> `deterministic` [9], and each engine runs the body for its own dialect. 
>>>>>> So
>>>>>> a Spark writer and a Trino writer can both mark a check as valid while
>>>>>> running different code [10]. SQL bodies make this hard to spot, because 
>>>>>> the
>>>>>> differences hide in built-ins like `array_contains`. Even one dialect 
>>>>>> isn't
>>>>>> stable. Spark 4 turned ANSI mode on by default [11], so the same Spark 
>>>>>> body
>>>>>> can fail on one version and pass on another. And an engine with no body 
>>>>>> for
>>>>>> its dialect can't write to the table while the check is enforced [12].
>>>>>>
>>>>>> If planners trust check statuses, every engine has to evaluate the
>>>>>> check the same way the writer did. That's the same requirement as index
>>>>>> keys. So I think we have to choose: allow only exactly-specified 
>>>>>> functions
>>>>>> in checks that planners trust, or say in the spec that planning on a UDF
>>>>>> check can return wrong results when bodies disagree. Today's rule does 
>>>>>> the
>>>>>> second without saying so. Which do people want?
>>>>>>
>>>>>> Thanks,
>>>>>> Matt
>>>>>>
>>>>>> [1] https://issues.apache.org/jira/browse/SPARK-55749
>>>>>> [2]
>>>>>> https://github.com/apache/datafusion/blob/13efc9c27d59b7fbc6503025042f14064c5fa0f7/datafusion/sqllogictest/test_files/array/array_has.slt#L22-L27
>>>>>> [3]
>>>>>> https://github.com/apache/iceberg/blob/2bd60a093a889a44a9e67033dba3abf4c36895f5/format/expressions-spec.md?plain=1#L140-L145
>>>>>> [4]
>>>>>> https://github.com/apache/spark/blob/cecbd5d846a2cdd891a4d9f0bda302b58b02092a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala#L783
>>>>>> [5]
>>>>>> https://github.com/apache/datafusion/blob/13efc9c27d59b7fbc6503025042f14064c5fa0f7/datafusion/functions/src/macros.rs#L293-L311
>>>>>> [6] https://github.com/apache/datafusion-spark/pull/334
>>>>>> [7]
>>>>>> https://github.com/apache/datafusion-comet/blob/d187e6823f9052e7331e8a810b08a1202debb91c/docs/source/user-guide/latest/compatibility/index.md?plain=1#L29-L30
>>>>>> [8] https://github.com/apache/iceberg/issues/19040
>>>>>> [9]
>>>>>> https://github.com/apache/iceberg/blob/2bd60a093a889a44a9e67033dba3abf4c36895f5/format/spec.md?plain=1#L787
>>>>>> [10]
>>>>>> https://github.com/apache/iceberg/blob/2bd60a093a889a44a9e67033dba3abf4c36895f5/format/spec.md?plain=1#L801-L802
>>>>>> [11]
>>>>>> https://github.com/apache/spark/blob/cecbd5d846a2cdd891a4d9f0bda302b58b02092a/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L6314-L6323
>>>>>> [12]
>>>>>> https://github.com/apache/iceberg/blob/2bd60a093a889a44a9e67033dba3abf4c36895f5/format/spec.md?plain=1#L773
>>>>>> [13]
>>>>>> https://github.com/apache/iceberg/blob/2bd60a093a889a44a9e67033dba3abf4c36895f5/format/spec.md?plain=1#L2018-L2019
>>>>>>
>>>>>>>

Reply via email to