Schedule icon
Query icon
Log icon
If icon
Fail icon

Parquet Data Quality Contract Gate with DuckDB

Validate Parquet schemas, null ratios, uniqueness, and value ranges with DuckDB SQL, halting pipelines on data contract violations.

Categories
CoreData

Data lakes and warehouses often ingest malformed or corrupted Parquet files, leading to silent data degradation, broken BI dashboards, and costly pipeline reprocessing. Catching structural anomalies, unexpected columns, high null ratios, duplicate primary keys, or out-of-bounds values at the ingestion boundary ensures that only compliant data reaches production tables.

This blueprint implements a zero-infrastructure data quality contract gate using embedded DuckDB. It inspects any target Parquet file against a strict contract without moving data to an external cluster or spinning up heavy Python frameworks.

How it works

  1. Self-Contained Sample Generator: The generate_sample_data task (io.kestra.plugin.jdbc.duckdb.Query) synthesizes a sample transaction dataset in Parquet format when inputs.parquet_uri is left blank. If inputs.inject_bad_data is toggled to true, it introduces intentional contract violations (null primary key, duplicate key, negative amount, and an unexpected column) for demo purposes.
  2. Contract Validation: The validate_contract task (io.kestra.plugin.jdbc.duckdb.Query) mounts the Parquet file and runs comprehensive SQL assertions in a single pass:
    • Row count check: Verifies the dataset is non-empty.
    • Schema & Type check: Confirms expected columns exist with compliant data types via DESCRIBE.
    • Column whitelist check: Asserts no unexpected extra columns were added upstream.
    • Null ratio threshold: Computes null proportions on critical columns against inputs.max_null_ratio.
    • Uniqueness constraint: Confirms primary key uniqueness on order_id.
    • Numeric value bounds: Confirms amounts stay within [inputs.min_amount, inputs.max_amount].
  3. Audit Log Report: The log_contract_summary task (io.kestra.plugin.core.log.Log) prints an itemized [PASS] or [FAIL] status for every evaluated rule.
  4. Enforcement Gate: The contract_gate task (io.kestra.plugin.core.flow.If) detects failed checks via jq. If any check failed and inputs.fail_on_violation is enabled, fail_pipeline (io.kestra.plugin.core.execution.Fail) terminates the execution with an itemized failure summary.

What you get

  • In-process SQL contract enforcement for Parquet datasets without external cluster overhead.
  • Automated detection of schema drift, column additions, null spikes, and duplicate records.
  • Itemized pass/fail audit logs for data governance compliance.
  • Configurable threshold parameters (max_null_ratio, min_amount, max_amount).
  • Ready-to-run demo mode that tests both passing and failing contract scenarios with zero configuration.

Who it's for

  • Data engineers looking to gate lakehouse ingestion pipelines before loading into Snowflake, BigQuery, or Databricks.
  • Analytics engineers establishing declarative data contracts across producer and consumer boundaries.
  • Platform teams standardizing lightweight, zero-dependency data quality gates in CI/CD or batch jobs.

Prerequisites

  • A running Kestra instance with the DuckDB JDBC plugin installed.
  • No external databases, cloud services, or API secrets required.

Secrets

  • None required.

Quick start

  1. Add this blueprint to your Kestra instance.
  2. Test Passing Execution: Run the flow with default inputs. The flow generates a clean sample dataset, verifies all 6 checks, logs [PASS] for every rule, and finishes successfully.
  3. Test Failing Gate Execution: Run the flow with inject_bad_data: true. The flow generates a poisoned dataset, flags the violations, logs the failing rules, and aborts the execution via the Fail task.
  4. Validate Custom Parquet Files: Supply your own Kestra internal storage URI (kestra://...) in parquet_uri to audit production datasets.

Links

Orchestrate with Kestra
Orchestrate DuckDB with Kestra
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.