Hydra ETL
Build your first job
GuideTransformsscript
Workshop 32 · 18 minutes

Implementing a reviewed custom rule

A practical workshop for a classification rule is too specific for built-in operations. Build the smallest manifest, validate it, run it and read the result.

Context — a classification rule is too specific for built-in operations

The task is currently manual and its assumptions are not recorded. Hydra turns it into files that can be reviewed and rerun.

Where things stand

  • The current result is fragile. Its assumptions are split between tools, clicks and memory.
  • Reruns are uncertain. The write mode or orchestration rule is not visible beside the data.
  • Evidence is missing. A colleague cannot compare a declared rule with a concrete before and after state.

The question

How do you express this rule with Hydra’s script operation and prove exactly what it changes?

  • Use one minimal input fixture
  • Declare one operation per step
  • Validate the DSL before running
  • Compare the complete before and after states

The solution in one line

One script step between a deterministic CSV source and a replaceable CSV destination.

data/input.csv6 steps
amount,country
720,DE
90,FR
What you do

Use a minimal fixture that exposes the rule.

Step 1 · fixture ready

Steps

1. capture the before state

  1. Use a minimal fixture that exposes the rule.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
amount,country
720,DE
90,FR
Check — before state recorded

2. declare the fixture

  1. Read the known input.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
version: "1.0"
sources:
  input:
    type: csv
    connection:
      base_path: "data"
    extract:
      table: input.csv
Check — input identifier is input

3. add the script step

  1. Write one operation with explicit parameters.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
version: "1.0"
steps:
  - script:
      inputs: [amount, country]
      outputs:
        risk_band: str
      mode: row
      code: |
        risk_band = "high" if amount > 500 and country != "FR" else "standard"
Check — one script operation declared
Trap — Declare the input/output contract; the restricted runtime exposes only those values.

4. make the result observable

  1. Write a replaceable CSV.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
version: "1.0"
destinations:
  result:
    type: csv
    connection:
      base_path: "out"
    load:
      table: result.csv
      mode: replace

---
version: "1.0"
pipeline:
  from: input
  to: result
Check — result.csv will contain the after state

5. validate the operation

  1. Ask Hydra to parse the step.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
$ hdrctl test script-workshop

ok  transformations.yaml — 1 step(s) valid
Operations: script

✅ All tests pass — ready to execute.
Check — one step counted: script

6. run and compare after to before

  1. Inspect the exact output.
  2. Compare the file with the explanation in the workbench.
  3. Record the shown check before moving to the next step.
$ hdrctl run script-workshop

✅ Pipeline completed successfully

amount,country,risk_band
720,DE,high
90,FR,standard
Check — expected after state reproduced

Expected result

  • The after state matches the stated rule.
  • One operation is counted by `hdrctl test`.
  • The fixture can be rerun without accumulating rows.

Reading the results

Compare columns, row count and ordering—not just one visible value. Declare the input/output contract; the restricted runtime exposes only those values.

What the counters do—and do not—prove

They prove how many records entered and left this run. They do not replace checking the target schema, the business meaning of values or the reason a workflow step was skipped.

The rule to carry forward

Declare the input/output contract; the restricted runtime exposes only those values.

Did we answer the question?

objectiveresultwhere
Configuration explicityesthe relevant YAML block
Safe rerunyesthe destination or workflow policy
Observable resultyesthe command output and counters
Hidden manual ruleremovedthe rule now lives in versioned text

Before and after

  • Before — a classification rule is too specific for built-in operations requires a person to remember the order, options and checks.
  • After — one reviewed manifest and one command produce the same observable result.
  • What is really gained — The durable gain is the contract: a colleague can read the configuration, reproduce the run and challenge the assumptions.

Close by

0 / 0 on this page