Transformer instructions
Transformer instructions use DuckDB SQL to create one typed transformed table with the business grain and exact inputs for the Charge job. To build a Transform job in the app, see Transformers.
Top-level keys
| Key | Required | Meaning |
|---|---|---|
inputs | No | Names available as typed SQL value parameters. |
queries | Yes | One or more ordered DuckDB SQL statements. |
assertions | No | Named read-only queries that must return no rows. |
Inputs
Each input item has one name:
inputs:
- name: start_date
- name: end_date
- name: billing_month
Use a matching named parameter in SQL:
WHERE usage_date >= CAST(:start_date AS DATE)
AND usage_date < CAST(:end_date AS DATE)
AND billing_month = :billing_month
An input is bound as a value. It cannot change a table name, column name, keyword, operator, clause, or other SQL structure. Input values stay fixed for an attempt and its retries. See Inputs and precedence.
Relation namespaces and origins
Use a namespace placeholder for each table that the SQL reads:
| Placeholder | Origin |
|---|---|
{{loaded}} | Output of a Load job |
{{transformed}} | Output of a Transform job |
{{charged}} | Output of a Charge job |
- Every table that the SQL reads needs one explicit typed origin: a direct Loader, Transformer, or Charge dependency, or an external input. Hypermeter does not find a table by a matching name.
- An external input is not part of the instructions. You declare it on the job as one exact
loaded,transformed, orchargedproduction table with one freshness choice. See Read a table another workflow writes. - A Transformer never reads its own output table. That SQL fails with
transformer_self_read_not_supported. For history, period summaries, and running totals, see History and totals. - Hardcoded
charged.relations are rejected. A{{charged}}."<name>"read is valid only when the Transform job has one matching charged-source mapping.
Queries
Each queries entry contains one query string. Transformer SQL uses DuckDB only, not PostgreSQL syntax.
Instructions that create a table must produce exactly one transformed table. Several statements can prepare temporary data. Instructions with only assertions can validate inputs without publishing a table.
The compiler rejects:
- Reading an undeclared relation, file, URL, extension, or object location.
- Writing outside the one declared output table, or publishing a second output table.
- Transaction control, procedural code, or dynamic SQL.
- A statement that DuckDB cannot parse, bind, or type-check.
Relation aliases
You can name a relation and its columns with an alias. The AS keyword is optional:
SELECT COUNT(*) AS days
FROM generate_series(
TIMESTAMP '2026-05-01', TIMESTAMP '2026-05-31', INTERVAL 1 DAY
) d(day);
This query returns 31, and so does AS d(day). Both forms work with allowed table functions, subqueries, and declared input tables, including joins. Use double quotes for names with spaces, such as "daily series"("usage day"). An alias does not lift the restrictions above.
DuckDB 2.0 rules
Transformer SQL runs on DuckDB 2.0. These rules differ from DuckDB 1.5:
- Integer
//and%by zero stop the query withDivision by zeroinstead of returningNULL. Guard the divisor, for examplea // NULLIF(b, 0). - Write lambdas as
lambda x: x + 1. The arrow formx -> x + 1is refused. ~matches part of a string. Anchor the pattern with^and$to match the whole value.avg()over aDECIMALreturns aDOUBLEthat can differ in the last digit. Round it before an exact comparison.X'AB'is aBLOBof those bytes, not text, andround_even()over aDECIMALreturns aDECIMAL, not aDOUBLE. Cast either if a column needs the old type.- A bare
NULLcolumn has no type and is refused as an output. Cast it, for exampleCAST(NULL AS INTEGER). - A
UNION,EXCEPT, orINTERSECTis refused when its decimal types cannot be checked: inside a correlated orLATERALsubquery, in SQL run from a string such asquery('…'), or over a table thatquery_tablereads by anything but a plain quoted name. Do that work in an earlier step.
Exact numeric values
Use DECIMAL(38,12) for authoritative money and exact fixed-point outputs. DuckDB decimal division produces an approximate DOUBLE, and a cast of that quotient to DECIMAL(38,12) does not restore exact digits. The Charge job rejects approximate operands.
Preserve an authoritative source amount. For a division or multiplication that defines a billed value, pass the authoritative operands to the Charge job and use Ratio or Product. For fixed conversions and approximate ratios, see Preserve exact money provenance.
Output constraints
Hypermeter derives non-null checks for the date columns and the grain identity columns that enabled downstream Charge jobs select. You do not declare these checks.
Preview and Production check the rows before publication. A missing required value fails the Transform job and publishes nothing.
The outputConstraints field is rejected, also as an empty array. Use assertions for additional business checks.
Assertions
Each assertion has a unique name of 1 to 128 characters and one read-only query. The query returns the rows that violate the rule. With zero rows, the assertion passes. See the example.
- Assertions run after the table is built and before publication, in Preview and in Production. A returned row fails the job and publishes nothing.
- An assertion cannot write data, create an object, run procedural code, or control a transaction.
- Diagnostics name the assertion but do not show row values. The returned columns are the evidence of a failed Production run: Show failing rows on the failed job and the
run_check_evidence_gettool show them. - Return the columns that identify the row and, for a comparison,
expected,actual, anddifference, instead ofSELECT 1. See Make a check explain its failures. - A query error, such as invalid SQL, a timeout, or too little memory, means that the assertion could not run. It is not a data violation, and the run diagnosis names the cause.
Example
inputs:
- name: start_date
- name: end_date
- name: billing_month
queries:
- query: |-
CREATE TABLE {{transformed}}.customer_cost_fact AS
SELECT
billing_month,
customer_id,
line_id,
MIN(usage_start) AS charge_start,
MAX(usage_end) AS charge_end,
CAST(SUM(cost_amount) AS DECIMAL(38,12)) AS cost_amount,
MAX(currency) AS currency,
COUNT(*) AS source_line_count
FROM {{loaded}}.invoice_lines_raw
WHERE usage_start >= CAST(:start_date AS TIMESTAMPTZ)
AND usage_start < CAST(:end_date AS TIMESTAMPTZ)
AND billing_month = :billing_month
GROUP BY billing_month, customer_id, line_id
assertions:
- name: customer cost grain is unique
query: |-
SELECT billing_month, customer_id, line_id
FROM {{transformed}}.customer_cost_fact
GROUP BY billing_month, customer_id, line_id
HAVING count(*) > 1
The Loader origin must declare the complete typed schema of invoice_lines_raw.
Prepare the Charge input
The output table needs one row for each business grain, stable non-null grain identities, exact quantities, amounts, rates, currencies, and business periods, and the source identities that reconciliation and repair need. See Prepare the table for a Charge job.
A Transformer can attribute or spread source values to create the fact grain. Leave volume pricing, graduated pricing, ordered commercial adjustments, and final target allocation to the Charge job.
Compilation and runtime verification
Compilation reports diagnostics for SQL parsing, name binding, type checking, origins, output effects, assertions, and numeric domains. A draft with errors stays editable, but you cannot preview or activate it.
At run time, the job fails and publishes nothing when the compiled SQL, the input schemas, or the output declaration no longer match.