Hi Peter/Huaxin,

Thanks for starting this.

First in the current state, I think it's up to the engines to enforce
'deterministic' as Iceberg can do little.

About Spark's problem with its definition of 'deterministic, I indeed saw
this this while looking at support for derived column (aka generated
columnl).  I am thinking to fix this on the Spark side but haven't had the
chance to organize it yet.   As you note, Spark 'deterministic' is
unfortunately double-meaning and I find it somewhat a soft blocker for
clean Spark support for derived column.  As you stated, we can't rely on
the flag as it seems a combination of 'stable' and 'immutable', and
derived column should
only be the latter (like Postgres).  The other option was, to just
whitelist known deterministic catalyst Expression in Iceberg-Spark until we
have the proper 'immutable/stable' split.

Options

1. Add a new optional flag to the UDF spec for the strong requirement (name
> TBD, default false). When it's true, the function returns the same result
> for the same input in any engine, session, or environment, and all its SQL
> bodies return the same result. Check constraints, stats-only fields, and
> derived columns would require this new flag instead of `deterministic`.
> This is similar to PostgreSQL and Oracle: UDFs are allowed, and we trust
> the person who creates them.
> 2. Do what Delta does: only allow functions defined in the Iceberg spec,
> and no UDFs.


On option 2, I am not sure if Delta spec really prohibits UDF's,
Delta-Spark does but its implementation detail and can probably be
relaxed.  So I'd say it's not that relevant to Iceberg UDF spec (as Delta
never had UDF spec, only Delta-Spark knows about Spark UDF's).

On option 1 (taking Peter's proposal), I do support adding Immutable/
Stable/ Volatile to Iceberg. I think it is always to be clear. But two
thoughts:

1. The stable category has a bit narrow of a use case, and may not be
always applicable for derived column.  It's more for allowing the same
function call to be collapsed into one (see Redshift documentation:
https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_FUNCTION.html)
2. I don't think that the current determinist/non-deterministic split is a
blocker to the table function work (check constraint, derived column).  The
current Iceberg deterministic should be enough.

So while it is useful and I support it, I do hope it's useful to more
engines, as the deprecation will inevitably bring confusion.

Thanks
Szehon


On Tue, Nov 17, 2026 at 11:57 AM Andrei Tserakhau via dev <
[email protected]> wrote:

> Thanks Huaxin, I think this question is a bit overdue.
>
> There are multiple places where this matters: derived columns, check
> constraints and stats-only fields all hit the same question, so answering
> it here is important.
>
> I think determinism is a must wherever a value gets computed again later.
> But forbidding UDFs closes too much. It just pushes people back to
> engine-specific table properties.
>
> +1 to Peter's enum idea, with some more thoughts:
>
> 1/ The key rule is "computed again later", not the function itself. Check
> validation, virtual columns and stats-only expressions need to be
> IMMUTABLE. A value computed once and stored as the source of truth can be
> VOLATILE: defaults, materialized derived columns. They are very useful with
> AI functions like embed(body, 'my-awesome-model'). They can be
> non-deterministic, but they can't be virtual.
>
> 2/ IMMUTABLE means no hidden inputs. Session time zone, locale or
> collation version must be explicit arguments. That also covers built-ins:
> wrap them in a UDF declared IMMUTABLE.
>
> 3/ deterministic=true is IMO closer to STABLE, not IMMUTABLE. Readers
> should treat unknown values as VOLATILE.
>
> 4/ Allowing UDFs shouldn’t mean every engine has to support them. An
> engine that can’t evaluate a stored expression ignores it on read (falls
> back to a scan) and refuses to write, same as any unsupported feature.
>
> best,
> Andrei
>
> On Tue, Nov 17, 2026 at 9:26 AM Péter Váry <[email protected]>
> wrote:
>
>> Thanks Huaxin for putting this together.
>>
>> I would like to suggest another option: *add an optional **volatility**
>> enum* with three values: VOLATILE, STABLE, and IMMUTABLE, with semantics
>> based on PostgreSQL's volatility categories [1].
>> We could deprecate the existing *deterministic* flag and define its
>> relationship with volatility during a transition period.
>>
>> Pros:
>>
>>    - Covers both the existing weaker notion of determinism and the
>>    stronger guarantee needed here.
>>    - Provides a clear, established distinction without introducing
>>    another overlapping boolean.
>>    - Can be used for other cases where STABLE is sufficient.
>>
>> Cons:
>>
>>    - Slightly more complex than a boolean.
>>    - Adding enum values in the future may have forward-compatibility
>>    implications.
>>
>> I would prefer this option because it provides a clean distinction
>> between the different guarantees and is more expressive than adding another
>> boolean flag.
>>
>> Thanks,
>> Peter
>>
>> [1] PostgreSQL Function Volatility Categories:
>> https://www.postgresql.org/docs/current/xfunc-volatility.html
>>
>> huaxin gao <[email protected]> ezt írta (időpont: 2026. nov. 17.,
>> K, 6:11):
>>
>>> Hi everyone,
>>>
>>> I want to start a discussion about what "deterministic" means for
>>> functions in stored expressions, and what the UDF spec should say about it.
>>>
>>> Why this matters
>>>
>>> Some features compute a value when data is written, and compute it again
>>> later, maybe in a different engine:
>>>
>>>    - Check constraints (v4): a UDF used in a check must set
>>>    `deterministic` to true.
>>>    - Stats-only fields in the index spec (
>>>    https://github.com/apache/iceberg/pull/16961): the expression must
>>>    be deterministic. The writer uses the value to sort index entries. The
>>>    reader computes it again to find the right region file.
>>>    - Derived (generated) columns: the value is computed from other
>>>    columns when data is written. Different engines may write rows to the 
>>> same
>>>    table, so they must compute the same value for the same input.
>>>
>>> If two engines get different results for the same input, a check can
>>> pass in one engine and fail in another. An index lookup can also miss rows.
>>> For a primary key lookup, a missed row means a duplicate row is written.
>>>
>>> What the UDF spec says today
>>>
>>>    - `deterministic` is a boolean on each definition version. The spec
>>>    doesn't say what it means: the same result within one query, within one
>>>    session, or always.
>>>    - "Deterministic" can be a weak requirement or a strong requirement.
>>>    The weak one is a hint for the engine to optimize, for example to cache a
>>>    result. The strong one is "the same input always gives the same output".
>>>    The `deterministic` flag in the UDF spec is meant as the weak one.
>>>    - A UDF can have one SQL body per engine. Nothing says these bodies
>>>    must return the same result. This came up in the UDF spec PR, and the
>>>    decision was to follow the view spec and not add a rule:
>>>    https://github.com/apache/iceberg/pull/14117#discussion_r2771641415.
>>>
>>>
>>> What other systems do
>>>
>>>    - "Deterministic" has two meanings in practice. The SQL standard,
>>>    Oracle, Db2, MySQL, Snowflake (IMMUTABLE), BigQuery (JavaScript UDFs) and
>>>    PostgreSQL (IMMUTABLE) mean "always the same result for the same input".
>>>    Spark and Trino use a weaker meaning: both treat current_timestamp() as
>>>    deterministic, because its value is fixed within one query. This is close
>>>    to PostgreSQL's STABLE.
>>>    - Session settings can change results. PostgreSQL says a function
>>>    that depends on the time zone should be STABLE, not IMMUTABLE. Oracle 
>>> warns
>>>    that changing NLS settings in a session can give wrong results from a
>>>    function-based index. SQL Server requires fixed SET options for indexes 
>>> on
>>>    computed columns. Db2 doesn't allow functions that depend on special
>>>    registers in generated columns.
>>>    - In almost all systems, the flag is a promise from the person who
>>>    creates the function. The system doesn't check it. If the flag is wrong,
>>>    results can be wrong.
>>>    - For stored data, many systems don't allow UDFs at all, even ones
>>>    marked deterministic: Delta generated columns and CHECK constraints,
>>>    Snowflake virtual columns and materialized views, BigQuery materialized
>>>    views, MySQL generated columns and check constraints, Db2 
>>> expression-based
>>>    indexes, and Oracle check constraints. Some systems do allow UDFs:
>>>    PostgreSQL in indexes and stored generated columns, if the UDF is marked
>>>    IMMUTABLE; Oracle in function-based indexes and virtual columns, if it is
>>>    marked DETERMINISTIC; and SQL Server in indexed computed columns, if SQL
>>>    Server decides the function is deterministic.
>>>    - The databases above each run one engine, so they don't need
>>>    multiple engines to agree. Delta is also used by many engines. The Delta
>>>    Lake docs say generated column expressions can't use user-defined
>>>    functions, and the Databricks docs say the same for CHECK constraints.
>>>
>>>
>>> Options
>>> 1. Add a new optional flag to the UDF spec for the strong requirement
>>> (name TBD, default false). When it's true, the function returns the same
>>> result for the same input in any engine, session, or environment, and all
>>> its SQL bodies return the same result. Check constraints, stats-only
>>> fields, and derived columns would require this new flag instead of
>>> `deterministic`. This is similar to PostgreSQL and Oracle: UDFs are
>>> allowed, and we trust the person who creates them.
>>> 2. Do what Delta does: only allow functions defined in the Iceberg spec,
>>> and no UDFs.
>>>
>>> Option 2 is simpler and safer, but it's too limiting. For example,
>>> sorting an index by a Hilbert curve value needs a function that Iceberg
>>> doesn't have, and we want to keep the list of Iceberg functions small.
>>>
>>> Open questions
>>>
>>> 1. What should the new flag be called? `immutable` matches PostgreSQL
>>> and Snowflake, but people may confuse it with immutable view and UDF
>>> versions.
>>> 2. What about functions that are not UDFs? Stored expressions can also
>>> call SQL standard functions and engine built-in functions, and the new flag
>>> doesn't cover them. For example, lower() can depend on locale. Should we
>>> only allow Iceberg functions and UDFs with the new flag? Engines can wrap
>>> their own functions in UDFs.
>>> 3. Should the new flag also mean `deterministic` is true?
>>>
>>> If people agree with adding a new flag in UDF spec, I can open a PR for
>>> this.
>>>
>>> Thanks,
>>> Huaxin
>>>
>>

Reply via email to