LakeLogic
Loading…
Back to Blog
Engineering

Testing a Data Quality Rule Shouldn't Need a Cluster. Proving It on Spark Still Does.

Jul 11, 2026
LakeLogic Team
Testing a Data Quality Rule Shouldn't Need a Cluster. Proving It on Spark Still Does.

Picture changing one quality rule: an email pattern that was too strict. To see whether it works you push the notebook, start a cluster, wait for it, run the job against a sample and read the output. The fix took a minute. Finding out whether it was right took far longer, and you will do it all again after the next edit.

This is the Spark tax: the cost, in time and compute, of validation logic that can only run where production runs. It comes from writing rules inside Spark code, so the only way to execute a rule is to start Spark. The rule itself, "email looks like an email", has nothing to do with distributed compute.

This article covers the ways teams cut that loop, the catch they all share (a local pass does not prove a Spark pass), and how LakeLogic runs one contract on Polars, DuckDB and Spark and checks the engines against each other. It contains no speed benchmarks. Startup and run times depend too much on hardware, data and cluster settings for a general number to mean anything; measure your own.

Why the loop is slow

The rule and the engine are the same code. A df.filter(...) in PySpark is both the business rule and its execution. To test the rule, you need the engine.

Production is the only place the engine is configured. Paths, catalogs and secrets exist in the workspace, so even a local Spark session cannot read the same inputs without extra setup.

Separating the two is straightforward in principle. The hard part is making sure the rule means the same thing wherever it runs.

The ways teams shorten the loop

ApproachHow it worksGood fitWatch out for
Local SparkLocal PySpark session on small fixture filesTeams wanting the exact production APIJVM startup; not your platform's runtime or catalog
Databricks ConnectCode in your IDE, executed on remote Databricks computeIDE debugging against real dataStill needs running compute and a workspace
Smaller or serverless computeSingle-node or serverless compute for developmentCutting cost without changing codeEach iteration still goes through the platform
Rewrite checks in pandas or PolarsLocal frame library in tests; Spark in productionSmall rule sets, one teamTwo implementations of every rule drift apart
Multi-backend libraries (Pandera, Ibis)One API targeting several backendsPython teams defining checks in codeBackend support differs per feature

Local Spark also differs from your platform in Delta settings and runtime version. With a multi-backend library, check that each rule you use is supported on each backend you run.

All of these work, and many teams use two: a fast local check while editing and a platform run before merging.

They share one weakness. A rule that passes locally can behave differently on Spark, because the engines read files, cast types and evaluate expressions in their own ways. Shortening the loop is the easy half. Knowing when the fast engine and the production engine disagree is the gap LakeLogic is built around.

How LakeLogic approaches it

In LakeLogic the rule lives in a data contract, not in engine code. The runtime has adapters for Polars, DuckDB and Spark (plus warehouse adapters for Snowflake and BigQuery, outside this article's scope), and you choose the engine when you run:

import lakelogic as ll

# while editing: no cluster
good, bad = ll.DataProcessor("contracts/customers.yaml", engine="polars").run(sample_df)

# in the platform job: same contract
good, bad = ll.DataProcessor("contracts/customers.yaml", engine="spark").run(spark_df)

good holds rows that passed every row rule; bad holds quarantined rows with the rule each one failed. The contract is the same file in both calls.

Checking that the engines agree

"Same contract" is only useful if it produces the same answer. Two mechanisms check that.

A cross-engine conformance suite. The Open Lakehouse Contract repository holds more than a hundred behavioural cases. Each is a contract, input rows and the expected accepted rows, quarantined rows and target state. The harness runs every case on DuckDB and Polars by default and on Spark when enabled, and any engine that produces a different outcome fails the run. Spark is opt-in because its startup makes the suite slow, which is the Spark tax again, paid once in CI instead of on every edit.

Tests written from real disagreements. The cases that justify this are the ones where every engine was internally consistent and still disagreed:

  • JSON layout. One engine detected whether a file was a single JSON value or JSON Lines; the Spark reader was told to treat every file as one value. Ten JSON Lines files produced ten rows on Spark instead of two hundred, with no error, while the local dry run passed. A conformance case now runs the same rows in both layouts on every engine.
  • Float width. Table creation treated float as 32-bit while the Spark path cast it to 64-bit, so Delta refused the write. A test now walks every type map and checks they agree on what float and double mean.
  • Rule order. The first run of the conformance suite found the Polars adapter evaluating a quality rule before the transform that created its column, which DuckDB got right. It was fixed in the adapter.

The lesson is not that one engine is wrong. It is that a local pass proves the rule on the local engine, and only a cross-engine check tells you whether that still holds on Spark.

A worked example

The Engine & Scale notebook writes a small contract with two row rules, generates 500 rows with a share of deliberately invalid values, saves them once to Parquet so every engine reads identical input, then runs the contract on Polars and DuckDB (and Spark if you enable it) and compares the good and bad counts. The same notebook goes on to SCD Type 2 merges, incremental loads that read only new files, and a targeted backfill, each driven by contract settings rather than hand-written merge code.

Matching counts on 500 generated rows is a useful smoke test. It is not proof that every rule, type and file format agrees; that is what the conformance suite is for.

When you might not need this

  • Your data is genuinely large and Spark-only. If every meaningful test needs production-scale data, a local engine adds little; invest in fast platform test runs instead.
  • Your rules are few and stable. A handful of checks that rarely change do not justify a contract runtime. Local Spark or Databricks Connect is enough.
  • You are committed to one platform's pipeline framework. Platform expectations keep rules beside the pipeline, which is simpler if you never run them elsewhere.
  • Your team already uses a multi-backend library well and tests each rule on each backend it runs on.

Limits worth knowing

  • Local success is not production success. Permissions, catalog behaviour, Delta table properties and runtime versions only exist on the platform. Keep a platform integration run before deployment.
  • Engine support is per feature. Most contract features run on all three engines; some reader options apply to the Spark file reader only, and LakeLogic logs a warning when they are given to another engine. Check the conformance results for the features you use.
  • Spark conformance is opt-in. If you never enable it in your CI, you are trusting the cases someone else ran.
  • No cost figures here. Whether local runs save money depends on how you pay for compute; measure before quoting a saving.

Key takeaways

  1. Keep the rule separate from the engine so you can test it without starting a cluster.
  2. A fast local loop is half the answer; the other half is knowing when the local engine and Spark disagree.
  3. Run the same cases on every engine you deploy to, and treat any difference as a failure.
  4. Read paths (file layouts, JSON shape, type widths) cause as many disagreements as rule logic; test them too.
  5. Keep at least one run on the real platform before release; local engines cannot see permissions, catalogs or runtime versions.

Our guide to testing data contracts locally before running on Databricks walks through the local half of this loop step by step.

Try it

Open the Engine & Scale notebook in Google Colab and run one contract on Polars and DuckDB against the same rows. Switch ENGINE to spark to add the third engine.

See LakeLogic in action.