Skip to content

Support non-string dimension link default values - #2572

Open
shangyian wants to merge 2 commits into
DataJunction:mainfrom
shangyian:feat/typed-default-value
Open

shangyian wants to merge 2 commits into
DataJunction:mainfrom
shangyian:feat/typed-default-value

Conversation

@shangyian

@shangyian shangyian commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A dimension link's default_value has only ever worked for string columns.

The stored value is now JSON and accepts a string, number, or boolean. How it renders is decided by the type of the column it's referring to. That means links with a default value of "0" for a numeric column will emit COALESCE(col, 0).

Pulled the relevant changes from #2406.

Test Plan

@netlify

netlify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit 902d9b3
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6ab4d5141b92c70008bb90bc

@shangyian
shangyian force-pushed the feat/typed-default-value branch from 1b4cd3a to 1838573 Compare September 24, 2026 05:24
shangyian and others added 2 commits September 24, 2026 00:45
A dimension link's `default_value` could only ever be a string. The field
was typed `str` at every layer, so `default_value: 0` failed validation,
and the emitted literal was always single-quoted, so the workaround of
authoring `"0"` produced COALESCE(int_col, '0'). The feature was unusable
on any non-string dimension column.

The stored value is now JSON (jsonb on postgres) and accepts a string,
number, or boolean. How it renders is decided by the type of the column
it wraps, not by how it was authored, so links already carrying "0"
against a numeric column start emitting COALESCE(col, 0) with no
migration of anyone's YAML.

A link's default applies to every dimension column reached through it, so
one link can serve columns of different types and there is no coherent
write-time check to make. Resolution happens per column at build time
instead, and it never raises: a value the column's type cannot hold falls
back to the quoted string it produces today. Spark implicitly casts
COALESCE(int_col, 'Unknown') to string, so raising there would break
setups that currently work.

Supersedes DataJunction#2406, whose JSON-storage and column-type-wins approach this
carries forward.

Fixes DataJunction#2377

Co-Authored-By: Beto Dealmeida <bdealmeida@netflix.com>
Python counts 1, 1.0 and True as equal, so widening default_value to
accept numbers and booleans meant a swap between them read as no change
at three points: the deploy spec comparison key, the orchestrator's
exact-match check, and -- one layer down -- SQLAlchemy's own attribute
history, which decides whether to include the column in an UPDATE at
all. The first two left the deploy reporting a noop; the third let the
deploy report an update while the old value stayed in the database.

Both link write paths now flag the column modified explicitly, and the
two value comparisons go through a shared key that carries the type.
@shangyian
shangyian force-pushed the feat/typed-default-value branch from 308e3b8 to 902d9b3 Compare September 24, 2026 07:45
@shangyian
shangyian marked this pull request as ready for review September 24, 2026 07:45

@betodealmeida betodealmeida left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants