Query icon
Switch icon
Queries icon
Log icon
Fail icon

DuckDB Parquet Coordinate Inversion and Geofence Integrity Gate

Audit Parquet telemetry with DuckDB for missing, inverted and Null Island coordinates and geofence breaches, splitting clean rows from a quarantine file.

Categories
Data

Audits a Parquet dataset that carries latitude and longitude columns for coordinate defects before it reaches GIS platforms and analytical warehouses. Coordinate inversions (abs(latitude) > 90, or latitude and longitude swapped) crash spatial indexers such as PostGIS, H3 and S2. Uninitialized sensor defaults pile up as artificial "Null Island" (0.0, 0.0) points, and rows with missing coordinates or points far outside the service area distort maps and routing models.

The flow reads the file you point it at with embedded DuckDB, classifies every row, compares the anomaly rates with your thresholds and acts on the result. A fully clean file is written to a curated output file. A file with contained noise is split into a curated file and a quarantine file that carries the reason and severity of each rejected row. When the inversion rate or the overall anomaly rate exceeds your limits, the whole batch is copied to an emergency file and the execution fails. The file itself is not changed, and the outputs are Kestra execution output files, so chain an upload task if you want them in a bucket.

The input is a plain Parquet file with numeric latitude and longitude columns (WGS84). It is not a geometry check: a GeoParquet file that only has a WKB geometry column needs those two columns added first.

How it works

  1. audit_and_profile_spatial_integrity (io.kestra.plugin.jdbc.duckdb.Query, fetchType: FETCH_ONE) mounts telemetry_parquet_uri with inputFiles and classifies each row, in this order:
    • MISSING_OR_NONFINITE_COORDINATE: latitude or longitude is NULL, NaN or infinite. Without this branch a NULL would fall through every comparison and be counted as clean.
    • COORDINATE_INVERSION: abs(latitude) > 90, or the point only falls inside the bounding box when latitude and longitude are swapped.
    • NULL_ISLAND: both coordinates are within 0.0001 of zero.
    • OUT_OF_BOUNDS_COORDINATE: abs(longitude) > 180 or the point is outside the bounding box.
    • CLEAN: everything else.
  2. The same query counts each category, computes anomaly_rate and inversion_rate, and returns one verdict: EMPTY_BATCH, SPATIAL_VALID, ANOMALOUS_QUARANTINE_QUALIFIED or CRITICAL_INVERSION_DRIFT.
  3. route_by_spatial_verdict (io.kestra.plugin.core.flow.Switch) runs the matching branch:
    • SPATIAL_VALID: curate_clean_dataset writes curated_spatial_telemetry.parquet.
    • ANOMALOUS_QUARANTINE_QUALIFIED: partition_and_quarantine_records writes the clean rows to curated_spatial_telemetry.parquet and the rest to quarantined_spatial_telemetry.parquet, with anomaly_reason, anomaly_severity and quarantine_timestamp added.
    • CRITICAL_INVERSION_DRIFT: isolate_emergency_dataset copies the whole batch to emergency_quarantine_telemetry.parquet, then trip_circuit_breaker (Fail) fails the execution.
    • EMPTY_BATCH: fail_empty_batch (Fail) fails the execution, because a file with no rows is not proof of valid data.

What you get

  • In-process validation of coordinate quality with DuckDB, with no GIS server, database or cluster to run.
  • Detection of swapped latitude/longitude pairs, impossible latitudes, missing coordinates, Null Island defaults and geofence breaches, with a count for each.
  • A quarantine file that keeps the original columns and says why each row was rejected.
  • A failed execution when producer drift pushes the anomaly rate over your limits.

Who it's for

  • Geospatial Engineers & GIS Architects: Teams that maintain location pipelines, connected-vehicle fleets or mapping platforms.
  • Data Platform Engineers: Engineers who put quality gates between edge devices and the data lake.
  • Analytics Engineers: Teams that protect warehouse tables from corrupt coordinates.

Why orchestrate this with Kestra

A standalone script leaves no execution history, output files or failure signal. In Kestra the gate runs with a recorded verdict, the quarantine and emergency files are stored as execution outputs, a Switch makes the routing visible, and the failed execution can trigger alerts or stop downstream flows.

Prerequisites

  • A Kestra instance with the DuckDB JDBC plugin (io.kestra.plugin.jdbc.duckdb).
  • A Parquet file with numeric latitude and longitude columns, available as a kestra:// internal storage URI or a namespace file URI.

Secrets

  • None required: DuckDB runs in-process against files in task storage.

Quick start

  1. Import this blueprint into your Kestra instance.
  2. Execute it with telemetry_parquet_uri set to a Parquet file in internal storage, for example the output of an upstream ingestion flow.
  3. Set the bounding box (min_latitude, max_latitude, min_longitude, max_longitude) to your service area. The defaults describe Greater London.
  4. Open the execution logs for the verdict and the counts, and download the curated and quarantine files from the task outputs.
  5. Tune max_inversion_rate and max_quarantine_rate to the tolerance your downstream consumers need.

How to extend

  • Trigger on landing: Add a Schedule trigger with an inputs: block, or call this flow as a subflow after your ingestion flow and pass it the new file URI.
  • Upload the results: Chain an io.kestra.plugin.aws.s3.Upload or io.kestra.plugin.gcp.gcs.Upload task to push curated_spatial_telemetry.parquet to your lake bucket.
  • Alert on failure: Add a Slack or PagerDuty notification in a flow-level errors block or in the CRITICAL_INVERSION_DRIFT branch.
  • Polygon geofences: Load the DuckDB spatial extension and replace the bounding box with ST_Contains against a polygon.

Links

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

New to Kestra?

Use blueprints to kickstart your first workflows.