ETLMCPData Conveyance Works
Log in Start free
Docs

Transform rules: how a rule list is applied

How a pipeline's rule list runs: in order, on stored rows at delivery, with the rules the editor writes and the checks run on save and preview.

A pipeline's transform is a list of rules that etlmcp applies in order, top to bottom, each time a run delivers. The first rule works on the rows as they were pulled and stored, and every later rule works on what the rule before it left. A pipeline may hold at most 50 rules, and the list as a whole has a size cap too. With no rules, rows pass through to the destination unchanged.

Where the rules run

etlmcp stores each platform's rows before any rule touches them. When a run reaches delivery, it reads the stored rows back, applies the pipeline's rules to them, and sends only the result to the destination. Three things follow from that:

  • Your rules never change the stored figures. Two pipelines on the same source can apply different rules to the same rows.
  • A change to the rules takes effect on the next run that delivers. Nothing is pulled from the platform again because you edited a rule.
  • query_data over MCP and Query data over the REST API return the stored rows, before any pipeline's rules. To see a pipeline's rules from outside the app, read its transform field with list_pipelines or Get pipeline.

If a rule fails while a run is applying it, the run ends as failed with the rule's message, and it is not retried. The rows that run pulled are already stored by then.

Order matters

Because each rule sees only what the previous one produced, the same rules in a different order give a different table. Plan for these cases:

  • A Select drops every column it does not list. A Derive placed before it keeps its new column only if the Select names it; a Derive placed after it can use only the columns the Select kept.
  • A Derive that uses a renamed column must come after the Rename and use the new name.
  • A Filter placed after a Group by tests the grouped totals, not the daily rows. Placed before it, it decides which rows go into each total.
  • A Limit keeps the first rows of whatever reaches it. Placed before a Filter or a Group by, it decides which rows those rules ever see.
  • Once a Group by leaves a column out, later rules cannot use it.

The rules the editor writes

The pipeline page has a rule editor. Each rule is one line: you pick its kind from a list and type the rest as text, and the editor turns that line into the JSON rule that is stored. The editor's own examples:

In the editor Stored op Example line What it does
Filter filter impressions > 100 keeps rows where the expression is true
Derive derive roas = conversion_value / cost adds a calculated column
Round round cost:2, cpc:2 rounds named columns to that many decimal places
Select select date, campaign_name, cost keeps only the listed columns, in that order
Rename rename cost -> spend gives columns new names
Set constant segment = retail writes a fixed value into a column on every row
Group by group date, campaign_name totals rows that share the listed columns
Limit limit 100 keeps that many rows

What you can write in a Filter or Derive line is on expression syntax, with details on the filter, derive and group by rules.

Two kinds of rule exist only as JSON: fx, which converts an amount column into another currency with rates you give, and a group with an agg other than sum (max, min, avg or count). The editor's Group by always sums. When a pipeline already holds one of these rules, the editor shows it as a locked line with its JSON, keeps it in its place in the list when you save, and lets you remove it, but not edit it.

When rules are checked

Rules are checked before any data runs: each time you save the pipeline and each time the preview refreshes. The editor first reads every line and stops at the first one it cannot turn into a rule, naming it by its number in the list. The server then checks the whole list: that each rule has the parts its kind needs, that every expression parses, and that the list is within the limits. A list over the size cap is refused with rules are too large (max {…} KB). Any error stops the save, and the stored rules stay as they were.

The server's messages count rules from zero, so rule 0 is the first line in the editor and rule 2 the third. Every message and its fix is on transform validation errors.

The preview

As you type, the editor waits for a short pause and then runs your rules on a sample of the source's stored rows, or on one made-up row when the source has none yet. It shows the first rows of the result and a summary line: how many rows came out, how many your filters struck out, and, on stored rows, how many columns your rules added, which are marked in the table. The preview runs the same checks as Save and the same rule engine as a run, so rules that preview cleanly also pass on save. A run still works on all the stored rows it delivers, so a rule can meet a value there that the sample did not hold. The column types your destination gets are on column types.

Related