dagron/ docs
Start · from 0.12.0

Steps & ETL

A step is a task dagron already knows how to run. The task names it with step: and configures it with with:; dagron supplies the command and the image, and checks with: by the step's own rules before the run is made. Five steps cover an extract and its cleaning: data from Postgres, a JSON API, a file drop or an Airbyte connector, landed as files, then cleaned with a YAML recipe. There is no script to write and no image to build per pipeline.

What a step task is

A step task is a leaf task with step: in place of a command. When a workflow is expanded, dagron checks its with: and turns it into an ordinary task: the step's binary as its command, the step's image unless the task names one, and with: passed as JSON in DAGRON_STEP_WITH. The executors see nothing new.

StepBinary and imageWhat it does
csv-cleandagron-step-csv, mancube/dagron-step-csvCleans a CSV, JSON lines or Parquet file with a YAML recipe.
sql-exportdagron-step-sql, mancube/dagron-step-sqlExports a query's rows from Postgres to CSV, JSON lines or Parquet.
http-extractdagron-step-http, mancube/dagron-step-httpPages through a JSON API and lands its records as JSON lines.
file-fetchdagron-step-fetch, mancube/dagron-step-fetchCopies a file drop (SFTP, FTPS, HTTPS) into the landing location, each file whole.
connectordagron-step-connector, installed into the connector's own imageRuns an existing Airbyte source and lands each stream as JSON lines.

csv-clean: clean with a recipe

One image cleans every pipeline's data. The cleaning is a YAML recipe in the workflow, so changing it is a change to the workflow file, and nothing is built per pipeline.

A csv-clean task
- name: clean_orders
  step: csv-clean
  with:
    input:   s3://lake/raw/shop/orders/ds={{ ds }}/orders.parquet
    output:  s3://lake/clean/shop/orders/ds={{ ds }}/orders.parquet
    rejects: s3://lake/rejects/shop/orders/ds={{ ds }}/orders.csv
    recipe:
      steps:
        - transform: { customer_email: [trim, lower] }
        - filter:    { status: "!= test" }
        - cast:      { id: int, amount: decimal(2), updated_at: timestamp }
        - dedupe:    [id]

The recipe's steps run in order, each a mapping with one key:

StepDoes
rename, select, dropName, keep or remove columns; select and drop take wildcards.
transformtrim, lower, upper, on a column or a wildcard.
replaceWhole values, a substring, or a regular expression with $1 groups. A pattern runs in time linear in the cell, so a recipe cannot hang the step.
filterKeeps a row only if every condition holds: not_null, a wildcard, a comparison (">= 0"), { in: [...] }.
castint, decimal(N), float, date, timestamp; narrower than a language's parser on purpose.
derive, splitAdd columns from a template ("{first} {last}") or by splitting a value.
dedupeKeeps the first row of each key.

A row a filter, a cast or a dedupe drops goes to rejects where it is set, as it was read, with the recipe step that dropped it and why (cast: amount is not decimal(2)). on_invalid: fail fails the task on the first value that does not cast instead (exit 3).

Formats. The same recipe reads and writes CSV (with a delimiter, no header, or an encoding such as windows-1252), JSON lines (nested objects flattened to customer.email) and Parquet. .gz or .zst after the suffix compresses as it streams. The recipe's casts are the output's schema: an int column is a Parquet INT64, a decimal(2) a DECIMAL(18, 2). A * in the input's last part reads every file it matches as one input. Options go with the location: input: { url: "s3://raw/*.csv.gz", delimiter: ";" }.

Writing a recipe. dagron-step-csv init --sample FILE drafts one from a sample; preview shows what each step keeps and drops; test holds a pipeline to its expected output, rejects and schema; --check compiles a recipe against a file's header without reading a row, for CI. dagron-step-csv schema prints the recipe language as a JSON Schema for an editor's completion, which dagron-api also serves. In the console, the Blocks palette's Clean CSV block adds the task and checks the recipe as saving would.

It does not evaluate code or run a command. That is what makes a recipe safe to accept from people who may not run arbitrary code. Logic a recipe cannot express belongs in a task of its own, beside this one.

sql-export: a query's rows to a file

A sql-export task
- name: extract_orders
  step: sql-export
  env:
    - { name: SQL_PASSWORD, value_from: { secret: SHOP_DB_PASSWORD } }
  with:
    engine: postgres
    dsn: postgres://etl@shop-db:5432/shop      # the user, never the password
    query: >-
      SELECT id, customer_email, amount, status, updated_at FROM orders
      WHERE updated_at >= date '{{ ds }}' AND updated_at < date '{{ ds }}' + 1
    output: s3://lake/raw/shop/orders/ds={{ ds }}/orders.parquet

with: takes four keys: engine, dsn, query and output. The password comes from SQL_PASSWORD, given from a secret, and a DSN that carries one is refused. The output is CSV, JSON lines or Parquet by its suffix, typed Parquet straight from Postgres's COPY, with the clean step's output options. null_as keeps a NULL apart from an empty string in every format, which an export's rows need. The task's timeout_secs bounds the export.

Postgres only, as a step. Other stores unload with their own statement (ClickHouse's INSERT INTO FUNCTION s3(…), Snowflake's COPY INTO, BigQuery's EXPORT DATA), run by dagron-step-sql as an ordinary task in its exec mode. That binary also runs one statement with a row and byte budget (SQL_MODE exec, scalar, rows, script) against ClickHouse, StarRocks, Doris, MySQL, Postgres, Redshift, Snowflake, BigQuery, Databricks or DuckDB, and checks that a partition holds the same rows on two stores (dagron-step-sql parity); its README has both.

http-extract: a JSON API's records

An http-extract task
- name: extract_reviews
  step: http-extract
  env:
    - { name: REVIEWS_API_TOKEN, value_from: { secret: REVIEWS_API_TOKEN } }
  with:
    url: https://api.example.com/v1/reviews
    params: { day: "{{ ds }}" }
    auth: { bearer: REVIEWS_API_TOKEN }      # the variable's name, not the token
    records: data                         # where the list is in each response
    paginate: { cursor: { from: next_cursor, param: cursor } }
    max_pages: 500
    output: s3://lake/raw/shop/reviews/ds={{ ds }}/reviews.ndjson

Paging is one of page (a page number until a page has no records), offset, cursor (from the body, sent back as a parameter), next_url and link (the Link header's rel="next"). Omitted, it is one request. max_pages (1000 by default) and max_page_bytes (64 MiB) bound a run, which fails past them rather than page forever.

Auth is { bearer: VAR } or { header: X-Api-Key, value_from: VAR }, from a variable the task is given from a secret. A credential in the URL, in a header, or in anything that looks like a key is refused, and one is masked in every error message. It goes over plain http:// only to this machine, unless allow_plain_http says the network is trusted.

Each record lands one to a line as the API sent it: key order and numbers as written. A 429, a 5xx or a failed connection is retried (retries, 5 by default, with a backoff that honours Retry-After). A 4xx, retries run out, or records missing where records: says fail the run and land nothing.

file-fetch: a partner's file drop

A file-fetch task
- name: fetch_partner
  step: file-fetch
  env:
    - { name: PARTNER_SFTP_KEY, value_from: { secret: PARTNER_SFTP_KEY } }
  with:
    source: sftp://dagron@sftp.partner.example/outbox/orders_{{ ds }}.csv
    auth: { private_key: PARTNER_SFTP_KEY }          # or { password: VAR }
    host_key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA…  # the server's, pinned
    output: s3://lake/raw/partner/orders/ds={{ ds }}/orders.csv

Sources: sftp://, ftps:// (FTP over TLS, explicit AUTH TLS) and https://. Plain ftp:// is refused, as it sends the password in the clear. SFTP trusts the one host key host_key pins, never a key on first sight. FTPS and HTTPS are verified against the system's roots, or against ca_cert alone where it pins a partner's own CA or a self-signed certificate.

Several files: a * or ? in an SFTP or FTPS path's last part fetches every file it matches, up to max_files, into an output ending in /, each under its own name. The files land byte for byte, each whole, and none lands until all are fetched. max_bytes (10 GiB unless set) caps them together.

connector: a SaaS source through Airbyte

Writing connectors one by one is a maintenance sink, so this step runs one that exists: an Airbyte source, in its own image, as Airbyte publishes it. dagron installs the adapter, dagron-step-connector, into the task at /dagron/bin from the operator's DAGRON_CI_EXEC_IMAGE. The step therefore runs on the Docker or Kubernetes executor with that setting.

A connector task
- name: extract_payments
  step: connector
  docker_image: airbyte/source-stripe:7.1.0       # the connector, as published
  env:
    - { name: PAYMENTS_API_KEY, value_from: { secret: PAYMENTS_API_KEY } }
  with:
    config:                                     # the connector's own config
      account_id: acct_1234
      client_secret: { from_env: PAYMENTS_API_KEY }
      start_date: "2024-01-01T00:00:00Z"
    streams: [charges, customers]
    output: s3://lake/raw/payments/ds={{ ds }}/      # charges.ndjson, customers.ndjson
    state: s3://lake/state/payments.json         # only the new rows, run to run

Which images run, on which architectures, and the connectors' licences are on the connectors' compatibility page, docs/CONNECTORS.md. examples/etl/declarative/extract/saas_faker.yaml extracts and cleans Airbyte's faker source, which needs no account.

Extract, then clean

examples/etl/declarative/extract/shop_daily.yaml is one day of a shop in four step tasks, with no script and no image of its own. The examples on this page are taken from it.

shop_daily
extract_orders   step: sql-export     Postgres → raw/shop/orders/ds=…/orders.parquet
extract_reviews  step: http-extract   a paged JSON API → raw/shop/reviews/ds=…/reviews.ndjson
clean_orders     step: csv-clean      → clean/shop/orders/ds=…/orders.parquet
clean_reviews    step: csv-clean      → clean/shop/reviews/ds=…/reviews.parquet

Each extract takes one day ({{ ds }}), and each clean keeps a rejects file saying why every dropped row went. A re-run of a day writes the same objects, byte for byte, so retrying a failed day or backfilling another is safe; the compose stack's test holds it to that. partner_drop.yaml fetches a partner's SFTP file and cleans it; partner_batch.yaml fetches every file of a day from FTPS with a wildcard and cleans them as one input.

Run it on this machine, from a checkout
$ PG_URL=postgres://etl:etl@127.0.0.1:5432/shop examples/etl/declarative/extract/e2e.sh
$ examples/etl/declarative/extract/compose-e2e.sh   # or the compose stack, with MinIO as the lake

Rebuilding models after a SQL change: State plans

A state plan is the other way SQL runs: given a change to a project's SQL, rebuild the models it touches and nothing else. The plan comes from the planner, dagron-state envelope joins it with the target's manifest (each model's command, env and secrets, and which plans need no reviewer), and the rebuild is one ordinary run, each model a task running the manifest's command (dagron-step-sql in the example). A plan bigger than the manifest's auto_approve waits for a person, in the console under State plans.

The console's State plans page with a pending plan open: a rebuild for prod at a commit in a repository, waiting on the state-prod pipeline's review gate, the bound envelope's sha256, 2 of 5 models rebuild with 60% pruned, and a table of the two models, why each rebuilds and what it waits on
A plan waiting for its reviewer, opened from State plans → Pending.
  1. Pending, Applied, Scratchpad: plans waiting on a gate; every rebuild a plan made, and who let it through (a person, or the target's auto_approve); and a place to paste a plan and explain it, which runs nothing.
  2. Where it came from: the target, the commit and repository, and the gate it waits on.
  3. The bytes: the envelope the gate binds, by its sha256. Approving sends that hash back, and the apply job submits those bytes or nothing.
  4. What rebuilds: how many of the project's models, each with why (changed, or downstream of one, through which column) and what it waits on. Below it: each model's SQL, the command and env from the manifest, and Approve or Reject.

examples/state is the pipeline: plan, the review when one is needed, apply, then commit the new state. It runs offline as far as the explanation. STATE_PLAN_USECASES.md says where a plan comes from and why each piece is as it is.

Moving an existing pipeline

Four worked examples move a SaaS extract to dagron from a tool teams already run. Each keeps the source, the streams and the lake layout it had, and swaps the platform around them for two steps: connector (the same Airbyte connector image) and csv-clean (the normalization, dbt model or pandas function, as a recipe).

Moves fromSourceShows
An Airbyte connection (OSS or Cloud)airbyte/source-stripeThe connection's settings, field by field; two cleans.
An Airflow DAG: an Airbyte sync, then PythonOperatorsHubSpotdefault_args, >>, schedules and backfills; an auth choice in the config.
A Meltano project (a Singer tap and target)GitHubMoving from a tap to the Airbyte source for the same API.
A managed Fivetran connectionSalesforceYour own OAuth app in place of the vendor's; loading a warehouse from the lake.

Each needs a real account and the secrets its header names. They are in examples/etl/declarative/migrate, with the concepts of the five tools side by side.

What 0.12.0 does not do

Where the rest is