Skip to content

Spark: Add scd_type2 option to create_changelog_view procedure #15593

Closed as not planned

Description

@moomindani

Feature Request / Improvement

The create_changelog_view procedure lets users query changelog rows from an Iceberg table, but producing a Slowly Changing Dimensions Type-2 (SCD Type-2) history view still requires users to write non-trivial SQL manually: joining with snapshot metadata, applying LEAD window functions, and filtering intermediate rows. This is a recurring pattern across many analytical workloads.

This issue proposes adding a scd_type2 parameter to create_changelog_view so Iceberg can produce an SCD Type-2 view natively.

Proposed API

CALL catalog.system.create_changelog_view(
    table              => 'db.products',
    changelog_view     => 'products_history',
    identifier_columns => array('product_id'),
    scd_type2          => true
)

New columns added to the view

Column Type Nullable Description
_valid_from TIMESTAMP no Commit timestamp when this version became active
_valid_to TIMESTAMP yes Commit timestamp when superseded; NULL if still active
_is_current BOOLEAN no true when _valid_to IS NULL AND _change_type != 'DELETE'

Design choices

  • NULL for open-ended rows — aligns with dbt (dbt_valid_from/dbt_valid_to) and Databricks DLT (__START_AT/__END_AT)
  • _valid_from/_valid_to naming — closest to dbt and Kimball semantics; prefixed with _ to match Iceberg metadata column conventions
  • _is_current retained — DELETE rows have _valid_to IS NULL but are NOT current; the convenience flag avoids the two-condition footgun
  • DELETE rows kept — marks hard deletes with _is_current = false, aligns with dbt hard_deletes='new_record'
  • UPDATE_BEFORE rows filtered — they are intermediate computation artifacts

Constraints

  • scd_type2 = true requires identifier_columns (explicit or from table schema identifier fields)
  • scd_type2 = true and net_changes = true are mutually exclusive
  • scd_type2 = true implicitly forces compute_updates = true

Query engine

Spark

Willingness to contribute

  • I can contribute this improvement/feature independently
  • I would be willing to contribute this improvement/feature with guidance from the Iceberg community
  • I cannot contribute this improvement/feature at this time

Activity

  1. github-actions commented on Sep 9, 2026

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  2. github-actions commented on Sep 24, 2026

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

  3. moomindani commented on Sep 24, 2026

    @moomindani
    ContributorAuthor

    Could a committer reopen this? It was closed by the stale bot, and it is being worked on in #17765.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions