info
Make the dedupe rule explicit
Most KPI drift comes from missing dedupe rules or unstable ordering. Treat match keys, tie-breakers, and late-arrival policy as requirements—not implementation details.
Workload
Translate Spark SQL idioms—MERGE/upserts, window logic, array/map patterns, and time handling—into Snowflake SQL with validation gates that prevent semantic drift and KPI surprises.
Quick answer
Translate Spark SQL idioms—MERGE/upserts, window logic, array/map patterns, and time handling—into Snowflake SQL with validation gates that prevent semantic drift and KPI surprises.
Back to pair pageContext
Databricks SQL estates are usually a mix of Spark SQL, Delta-specific patterns, and BI-generated queries. Many will translate syntactically—but drift happens when implicit semantics differ: NULL behavior, type coercion in CASE/COALESCE, timestamp/timezone assumptions, and array/map handling. Common symptoms after cutover:
Approach
Coverage
Representative Databricks/Spark SQL constructs we commonly convert to Snowflake SQL (exact coverage depends on your estate).
| Source | Target | Notes |
|---|---|---|
| Spark SQL window filters (ROW_NUMBER/RANK) | Snowflake window functions + QUALIFY | Deterministic ordering and tie-breakers enforced. |
| Delta MERGE and upsert patterns | Snowflake MERGE with staged apply | Match keys, casts, and update predicates made explicit and testable. |
| explode/arrays/maps/structs | FLATTEN/VARIANT + lateral joins (or normalized staging) | Empty-array semantics preserved intentionally. |
| DATE/TIMESTAMP arithmetic | Snowflake date/time functions | Timezone intent (NTZ/LTZ/TZ) normalized explicitly. |
| NULL-safe comparisons | Explicit null-safe equality patterns | Prevents join drift and duplicate inserts. |
| String/regex functions | Snowflake string/regex equivalents | Edge-case behavior validated via golden cohorts. |
Compare
| Topic | Databricks / Spark SQL | Snowflake | Notes |
|---|---|---|---|
| Execution assumptions | Shuffle-heavy plans and partition overwrite patterns common | Pruning + clustering alignment and bounded apply scopes | Snowflake rewards pruning discipline and explicit apply windows. |
| Semi-structured handling | Struct/array/map types and explode patterns | VARIANT + FLATTEN or normalized staging | Choose between VARIANT-centric or fully typed modeling. |
| Time semantics | Timezone assumptions often implicit | Explicit NTZ/LTZ/TZ and conversion rules | Time intent must be declared to prevent boundary-day drift. |
Examples
Representative Databricks → Snowflake rewrites for windowed dedupe, explode/flatten, and MERGE patterns. Adjust keys, paths, and casts to your model.
-- Databricks: latest row per key
SELECT *
FROM events
QUALIFY ROW_NUMBER() OVER (
PARTITION BY business_key
ORDER BY event_ts DESC
) = 1; -- Snowflake: enforce deterministic tie-breakers
SELECT *
FROM EVENTS
QUALIFY ROW_NUMBER() OVER (
PARTITION BY BUSINESS_KEY
ORDER BY EVENT_TS DESC, SRC_OFFSET DESC NULLS LAST, INGESTED_AT DESC
) = 1; -- Databricks: explode array
SELECT o.id, i.item_id
FROM orders o
LATERAL VIEW explode(o.items) e AS i; -- Snowflake: FLATTEN (items stored as VARIANT array)
SELECT o.id, f.value:item_id::STRING AS item_id
FROM ORDERS o, LATERAL FLATTEN(input => o.items) f; -- Snowflake MERGE (staged apply)
MERGE INTO MART.FACT_ORDERS t
USING STG_DEDUP s
ON t.ID = s.ID
WHEN MATCHED THEN UPDATE SET
t.STATUS = s.STATUS,
t.AMOUNT = s.AMOUNT,
t.UPDATED_AT = s.EVENT_TS
WHEN NOT MATCHED THEN
INSERT (ID, STATUS, AMOUNT, UPDATED_AT)
VALUES (s.ID, s.STATUS, s.AMOUNT, s.EVENT_TS); info
Most KPI drift comes from missing dedupe rules or unstable ordering. Treat match keys, tie-breakers, and late-arrival policy as requirements—not implementation details.
info
Design staging boundaries and pruning-aware apply strategies so credit burn stays predictable as volume grows.
Workload Assessment
We inventory your SQL estate, convert a representative slice, and deliver parity evidence on golden queries—plus a risk register for constructs that carry business meaning.
Book assessmentAvoid
explode, map, and nested structs need explicit Snowflake VARIANT/FLATTEN rewrites when semi-structured.Proof
Execution
A sequence that keeps correctness measurable and prevents semantic drift.
01
Export dbt models, notebooks, job SQL, view definitions, and BI SQL. Rank by business impact, frequency, and risk patterns (MERGE, windows, arrays/maps, time).
02
Make tie-breakers, NULL handling, casting strategy, timezone intent, and array/map handling explicit—especially for top-N, dedupe, and MERGE logic.
03
Apply deterministic rewrites for common constructs and flag ambiguous intent with review markers (implicit casts, ordering ambiguity, timezone assumptions).
04
Compile and run in Snowflake, compare KPI aggregates, and run targeted diffs on edge cohorts (ties, null-heavy segments, boundary dates).
05
Align clustering to access paths, bound MERGEs and applies, and recommend materializations where BI patterns repeatedly scan large facts.
FAQ
No. Databricks uses Spark SQL with Delta-centric patterns; Snowflake has different function sets, typing behavior, and semi-structured handling. We convert syntax and make semantic intent explicit where drift is common.
Implicit casts, NULL semantics in joins/CASE branches, timezone assumptions, and window/top-N ordering. These areas get explicit contracts and golden-query validation.
Yes. We migrate MERGE logic with explicit match keys, deterministic dedupe, and staged apply patterns, then validate idempotency and KPI parity under reruns and late data.
Not automatically. Spark-era query shapes often need pruning/clustering-aware adjustments in Snowflake. We baseline and tune the top queries as part of this workload.
Migration Acceleration
Get a conversion plan, review markers, and validation artifacts so query cutover is gated by evidence and rollback-ready criteria.
Next reads
End-to-end approach: what breaks, validation gates, and cutover plan.
Migrate Delta pipelines and orchestration to Snowflake with idempotency and late-data parity.
Tune Snowflake workloads post-cutover: bounded MERGEs, clustering, warehouse posture, and regression gates.
How we define parity contracts, thresholds, and evidence for sign-off.