Skip to content

Spark: Make the view stored-schema coercion configurable - #17499

Open
bmorck wants to merge 1 commit into
apache:mainfrom
bmorck:spark41-view-schema-binding-mode
Open

Spark: Make the view stored-schema coercion configurable#17499
bmorck wants to merge 1 commit into
apache:mainfrom
bmorck:spark41-view-schema-binding-mode

Conversation

@bmorck

@bmorck bmorck commented Aug 3, 2026

Copy link
Copy Markdown

This change adds a new spark.sql.iceberg.view.schema-binding-mode property, used in ResolveViews in Spark 4.1. Prior to this property, ResolveViews always wraps each output column in an UpCast that only does widening type coercion. So if the stored schema of the view has a narrower type than what the SQL actually produces, we get an error like the following:

[CANNOT_UP_CAST_DATATYPE] Cannot up cast id from "DOUBLE" to "BIGINT"

The new spark.sql.iceberg.view.schema-binding-mode introduces 3 modes to relax this behavior, taking its mode names from Spark's ViewSchemaMode:

value coercion
BINDING UpCast(col, storedType) — the current behaviour, and the default
COMPENSATION Cast(col, storedType, ansiEnabled = true) — narrowing allowed
TYPE_EVOLUTION no cast, so the view reports the types its SQL produces

Spark's has thespark.sql.legacy.viewSchemaBindingMode and spark.sql.legacy.viewSchemaCompensation confs to relax this behavior on the v1 SessionCatalog view path, but this doesn't apply to v2 views.

This change was adapted from: #17453

ResolveViews rebuilds a view's output from the stored schema, by position,
wrapping each column in an UpCast. UpCast only widens, so a view whose
stored type is narrower than what its SQL produces cannot be read at all,
and there is no way to relax it.

Add spark.sql.iceberg.view.schema-binding-mode, taking its mode names and
coercions from Spark's ViewSchemaMode: BINDING (UpCast, the default and
current behaviour), COMPENSATION (an ANSI cast, allowing narrowing) and
TYPE_EVOLUTION (no cast, so the view reports the types its SQL produces).
All three keep the stored column name and metadata.

When the conf is unset, Spark's spark.sql.legacy.viewSchemaBindingMode and
viewSchemaCompensation are honored instead, reproducing how
SessionCatalog.castColToType treats SchemaUnsupported.
@github-actions github-actions Bot added the spark label Aug 3, 2026
@bmorck
bmorck marked this pull request as ready for review August 3, 2026 18:51
@bmorck bmorck changed the title Spark 4.1: Make the view stored-schema coercion configurable Spark: Make the view stored-schema coercion configurable Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant