Created
October 4, 2026 02:38
-
-
Save rjdudley/2c01d5910a2f645747783e34aa4ded1b to your computer and use it in GitHub Desktop.
An example Gherkin spec for behavior driven data engineering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: NYC Taxi Trips Pipeline | |
| As a data engineer | |
| I want to transform NYC taxi trip data through a medallion architecture | |
| So that I can analyze trip metrics by day and pickup location | |
| Background: | |
| Given the bronze source table "samples.nyctaxi.trips" with columns: | |
| | tpep_pickup_datetime | TIMESTAMP | | |
| | tpep_dropoff_datetime | TIMESTAMP | | |
| | trip_distance | DOUBLE | | |
| | fare_amount | DOUBLE | | |
| | pickup_zip | INT | | |
| | dropoff_zip | INT | | |
| And the bronze source stores all timestamps in UTC | |
| # --- Silver Layer --- | |
| Scenario: Display timestamps in Eastern time | |
| Given a trip has tpep_pickup_datetime and tpep_dropoff_datetime in UTC | |
| When the silver streaming table "silver.nyctaxi.trips_cleaned" processes the trip | |
| Then pickup_datetime and dropoff_datetime preserve the original UTC instants as TIMESTAMP_LTZ | |
| And the pipeline session timezone is set to America/New_York so timestamps display as Eastern time | |
| And the display correctly accounts for Daylight Saving Time or Standard Time at the time of the trip | |
| Scenario: Pad zip codes to five characters | |
| Given a trip has pickup_zip and dropoff_zip as integers | |
| When the silver streaming table "silver.nyctaxi.trips_cleaned" processes the trip | |
| Then pickup_zip is converted to a string left-padded with zeros to 5 characters | |
| And dropoff_zip is converted to a string left-padded with zeros to 5 characters | |
| Scenario: Calculate trip duration | |
| Given a trip has a pickup and dropoff datetime | |
| When the silver streaming table "silver.nyctaxi.trips_cleaned" processes the trip | |
| Then trip_duration_minutes is calculated as the difference between dropoff and pickup times in minutes | |
| Scenario: Route invalid records to bronze quarantine table | |
| Given a trip has a null pickup or dropoff datetime | |
| When the silver streaming table "silver.nyctaxi.trips_cleaned" processes the trip | |
| Then the record is excluded from the silver table | |
| And the record is saved in the streaming table "bronze.nyctaxi.invalid_trips" | |
| And similarly, trips with trip_distance <= 0 are excluded from silver and saved in invalid_trips | |
| And trips with fare_amount < 0 are excluded from silver and saved in invalid_trips | |
| Scenario: Invalid trips table schema | |
| Then the streaming table "bronze.nyctaxi.invalid_trips" has the same columns as the bronze source: | |
| | tpep_pickup_datetime | TIMESTAMP | | |
| | tpep_dropoff_datetime | TIMESTAMP | | |
| | trip_distance | DOUBLE | | |
| | fare_amount | DOUBLE | | |
| | pickup_zip | INT | | |
| | dropoff_zip | INT | | |
| Scenario: Silver output schema | |
| Then the silver streaming table "silver.nyctaxi.trips_cleaned" has columns: | |
| | pickup_datetime | TIMESTAMP | | |
| | dropoff_datetime | TIMESTAMP | | |
| | trip_distance | DOUBLE | | |
| | fare_amount | DOUBLE | | |
| | pickup_zip | STRING | | |
| | dropoff_zip | STRING | | |
| | trip_duration_minutes | DOUBLE | | |
| # --- Gold Layer --- | |
| Scenario: Aggregate daily trip metrics by pickup zip | |
| Given the silver table "silver.nyctaxi.trips_cleaned" contains cleaned trip data | |
| When the gold materialized view "gold.nyctaxi.trips_metrics" processes the data | |
| Then trips are grouped by trip_date and pickup_zip | |
| And trip_date is the Eastern date extracted from pickup_datetime via the session timezone | |
| And the following metrics are calculated: | |
| | metric | aggregation | | |
| | trip_count | COUNT(*) | | |
| | avg_fare_amount | AVG(fare_amount) | | |
| | total_fare_amount | SUM(fare_amount) | | |
| | avg_trip_distance | AVG(trip_distance) | | |
| | avg_trip_duration_minutes | AVG(trip_duration_minutes) | | |
| Scenario: Gold output schema | |
| Then the gold materialized view "gold.nyctaxi.trips_metrics" has columns: | |
| | trip_date | DATE | | |
| | pickup_zip | STRING | | |
| | trip_count | BIGINT | | |
| | avg_fare_amount | DOUBLE | | |
| | total_fare_amount | DOUBLE | | |
| | avg_trip_distance | DOUBLE | | |
| | avg_trip_duration_minutes | DOUBLE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment