farseer-cli 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,24 +4,24 @@ Read this before designing a pipeline. The method gives the loop and the grammar
4
4
 
5
5
  ## 1. What goes where
6
6
 
7
- A pipeline is three things in a folder: `main.py`, `Models/` (one YAML per dataset) and `Code/` (scripts). Every responsibility has one home.
7
+ A pipeline is three things in a folder: `main.py`, `Models/` (one YAML per step) and `Code/` (scripts). Every responsibility has one home.
8
8
 
9
9
  | Part | Holds | Never holds |
10
10
  |---|---|---|
11
11
  | `main.py` | Argument checks and canonical spellings, then one `run_pipeline()` call with `store_type=StoreType.DATASETS` and `pipeline_policy=PipelinePolicy()` | Data reads, business logic, API calls, starting other jobs |
12
- | `Models/<layer>/<name>.yaml` | One dataset: its step, `deps`, `schema`, `quality_rules`, and its load or export mapping. Or one `expand:` fan-out over one axis | Copies per company or period; two run cadences in one folder (use two pipeline folders) |
13
- | `extract` block | How to reach the source: connector, the source-side filter and columns, `optional` for a source that may genuinely be missing | Reshaping; reading another pipeline's output through `deps`; credentials |
14
- | `parse` block | How to read the bytes: format, encoding, separator, decimal, header, start row, positional columns | What the values should be: no fixing, mapping or filtering |
12
+ | `Models/<layer>/<name>.yaml` | One step: its `type`, `deps` and its block, with `schema` and `quality_rules` on a parse step or transform, and a load or export mapping on a load or export. Or one `expand:` fan-out over one axis | Copies per company or period; two run cadences in one folder (use two pipeline folders) |
13
+ | `extract` block | How to reach the source: connector, the source-side filter and columns, `optional` for a source that may genuinely be missing. The step, named `<name>_raw`, stores what the source hands over unread: a file source's file as it came, a typed source's rows as parquet | Anything that reads or checks the data: `parse`, `schema`, `quality_rules`, `write_mode`, `merge_keys`. Reshaping; reading another pipeline's output through `deps`; credentials |
14
+ | `parse` step (`type: parse`, `deps: [<the extract>]`) | How to read the extract's file into the dataset `<name>`: `format` (or a `script`) and, in the block named for the format (`csv:`, `xlsx:`, `json:`), encoding, separator, decimal, header, start row, positional columns. Every extract has one, and only a parse step reads an extract | What the values should be: no fixing, mapping or filtering |
15
15
  | `schema` | The dataset's column contract: every column it keeps, with `type` and `not_null` | Reshaping |
16
- | `quality_rules` | What the values must mean, on extract and transform steps | Comparisons between datasets (write a reconciliation transform) |
16
+ | `quality_rules` | What the values must mean, on parse and transform steps | Comparisons between datasets (write a reconciliation transform) |
17
17
  | SQL transform (`engine: duckdb`, `query`) | All set-based work: filter, join, map, aggregate, reshape, final casts | Procedural row-by-row logic |
18
18
  | `@ibis_transform` (`engine: ibis`, `script`) | Logic that needs Python to compose, still streaming | DataFrames, `.to_pandas()`, `.execute()` |
19
19
  | `@transform` (`engine: python`, `script`) | Only work with no lazy form | Set-based work; I/O, environment reads, the clock |
20
20
  | `Code/` | One script per transform function; a function shared by many datasets through `transform.function` and `transform.args` | Helper modules imported across scripts: each script runs on its own |
21
21
  | `load` block | Column-to-model mapping, labels, import options | Any logic. To change a number, change a transform |
22
22
  | `export` block | File target, format, conflict behaviour | Shaping |
23
- | Files | Mapping tables, read with `source: files` and joined in SQL | |
24
- | The model | Member lists, read with `source: dimensions` to check codes before loading | Guesses: every name comes from the model tools |
23
+ | Files | Mapping tables, read with a `source: files` extract and its parse step, and joined in SQL | |
24
+ | The model | Member lists, read with a `source: dimensions` extract and its parse step to check codes before loading | Guesses: every name comes from the model tools |
25
25
  | Job arguments | The run's slice (period, company), fan-out lists, secrets as secret arguments | Credentials in YAML; truthiness tests (every value is a string) |
26
26
 
27
27
  ## 2. Layers and names
@@ -30,16 +30,16 @@ Start from the target. Before any YAML, write down each variable the pipeline fi
30
30
 
31
31
  | Folder | Holds | Rule |
32
32
  |---|---|---|
33
- | `Models/bronze/` | Extract-only datasets, one per source extraction | Lands the source with its own `schema` and structural rules and nothing else. No transform unless the data needs work |
33
+ | `Models/bronze/` | One extract per source extraction, `<name>_raw`, and the parse step `<name>` that reads it | The extract stores the source's file unread; the parse step reads it with the source's own `schema` and structural rules and nothing else. No transform unless the data needs work |
34
34
  | `Models/silver/` | Conformed rows | Codes cleaned, types settled, mappings joined, and an explicit flag on every row a mapping missed |
35
35
  | `Models/gold/` | One row per target cell | Columns are exactly what the load maps: dimension columns, date or time columns, value columns, and any `custom_fields` |
36
36
  | `Models/load/` | Load steps | Thin: they map `gold` columns, nothing else |
37
37
 
38
- - **Why layer.** Extracting is the slow, metered part. Each extract runs once, and every transform after it can be tested with `query` against the published extract. Rules at each boundary localise a fault to one step. Because the load is thin, the dataset you reconcile is exactly what was imported.
38
+ - **Why layer.** Extracting is the slow, metered part. Each extract runs once, and every transform after it can be tested with `query` against the dataset its parse step published. Rules at each boundary localise a fault to one step. Because the load is thin, the dataset you reconcile is exactly what was imported.
39
39
  - **`name:` equals the file name, and the folder becomes the namespace:** `Models/bronze/erp_sales_lines.yaml` is `bronze.erp_sales_lines`.
40
40
  - **Qualified names are shared by every pipeline on the tenant.** Name datasets after their subject (`bronze.erp_sales_lines`, not `bronze.lines`), so two pipelines never write the same dataset.
41
41
  - **Leaf names must be unique within one step's `deps`.** SQL sees each dependency as a view named by its leaf, and Python sees it as a parameter named by its leaf.
42
- - **Read another pipeline's output** with `extract.type: farseer`, `source: datasets` and its `qualified_name`. It reads the last published version, and there is no ordering between pipelines.
42
+ - **Read another pipeline's output** with `extract.type: farseer`, `source: datasets` and its `qualified_name`, and a parse step with `format: parquet` that reads the extract. It reads the last published version, and there is no ordering between pipelines.
43
43
  - **Keep `StoreType.DATASETS`** unless the pipeline accumulates data (section 8). `FARSEER_FILES`, the engine default, publishes on write and keeps no versions.
44
44
 
45
45
  ## 3. Transforms: SQL, then ibis, then pandas
@@ -83,12 +83,12 @@ Use a `LEFT JOIN` to a mapping and flag the rows that found no match. An `INNER
83
83
 
84
84
  ## 4. Writing schemas
85
85
 
86
- Declare a `schema:` on every extract and transform, listing every column the dataset keeps, each with a `type`. The schema is the dataset's contract with whatever reads it. The one exception is a bronze extract that deliberately captures a source whole.
86
+ Declare a `schema:` on every parse step and transform, listing every column the dataset keeps, each with a `type`. The schema is the dataset's contract with whatever reads it. The one exception is a bronze parse step that deliberately captures a source whole.
87
87
 
88
88
  - **Types:** `str`, `int`, `float`, `datetime`, `bool`, `list[str]`. There is no date or decimal type. A `DECIMAL` column fails `float` and a `DATE` column fails `datetime`, so cast in SQL.
89
- - **Cast or check.** For file payloads (CSV, JSON, Excel) the declared type is a cast: `type: str` keeps `0042` as text. For SQL, Parquet, API and Farseer sources, and for every transform, the type is only a check, so cast in the query.
89
+ - **Cast or check.** The parse step's reader decides. With `format: csv`, `json` or `xlsx` the declared type is a cast, whatever the source, Farseer Files included: `type: str` keeps `0042` as text. With `format: parquet` (the rows a SQL, API or Farseer source hands back), with a parse `script:`, and in every transform, the type is only a check, so cast in the script or query.
90
90
  - **`not_null` is separate from `type`.** Built-in quality checks let nulls pass, so pair them with `not_null`. NaN is not NULL to these checks.
91
- - **Undeclared columns are not dropped.** They land with guessed types, except in JSON, where they are dropped with a warning. Select exactly the columns you want in the query or with the extract's column selection.
91
+ - **Undeclared columns are not dropped.** They land with guessed types, except in JSON, where they are dropped with a warning. Select exactly the columns you want in the query, with the extract's column selection, or with `columns` in the parse step's `csv:` or `xlsx:` block.
92
92
  - **Dates.** There is no format declaration; the reader guesses one format per column from its first value. Keep dates ISO at the source. For an ambiguous `dd/mm/yyyy` source, declare the column `str` and parse it in SQL with an explicit `strptime` pattern.
93
93
  - **Codes are `str`,** always. Declare them, even when the source looks numeric.
94
94
  A gold dataset written the intended way, with SQL, explicit casts, a full schema and its load contract:
@@ -118,7 +118,7 @@ quality_rules:
118
118
  params: { columns: [product_code, region, month] }
119
119
  ```
120
120
 
121
- - **CSV defaults that bite.** The separator is not detected (default `,`). `NA`, `null`, `None`, `n/a` and empty read as NULL, which turns the country code `NA` into a missing value. There is no option to change that, so check such columns on purpose. Set `csv_options.decimal: ","` for decimal commas.
121
+ - **CSV defaults that bite.** The separator is not detected (default `,`). `NA`, `null`, `None`, `n/a` and empty read as NULL, which turns the country code `NA` into a missing value. There is no option to change that, so check such columns on purpose. Set `csv: {decimal: ","}` in the parse step's `parse:` block for decimal commas.
122
122
 
123
123
  ## 5. Quality rules: which kind goes where
124
124
 
@@ -163,13 +163,13 @@ os.environ["FARSEER_ARGS"] = json.dumps(args)
163
163
  **One definition, many datasets.** Use `expand` rather than copied YAML. The grammar topics do not cover this shape, so follow it exactly:
164
164
 
165
165
  ```yaml
166
- # Models/bronze/tb_file.yaml: one extract per company
166
+ # Models/bronze/tb_file_raw.yaml: one extract per company
167
167
  expand:
168
168
  values:
169
169
  - [{key: company, value: C100}]
170
170
  - [{key: company, value: C200}]
171
171
  template:
172
- name: "tb_file_{{ each.company }}"
172
+ name: "tb_file_{{ each.company }}_raw"
173
173
  type: extract
174
174
  extract:
175
175
  type: sharepoint
@@ -179,6 +179,20 @@ expand:
179
179
  # site_url and the credential arguments as usual
180
180
  ```
181
181
 
182
+ ```yaml
183
+ # Models/bronze/tb_file.yaml: one parse step per company, reading that company's extract
184
+ expand:
185
+ values:
186
+ - [{key: company, value: C100}]
187
+ - [{key: company, value: C200}]
188
+ template:
189
+ name: "tb_file_{{ each.company }}"
190
+ type: parse
191
+ deps: ["bronze.tb_file_{{ each.company }}_raw"]
192
+ parse:
193
+ format: csv
194
+ ```
195
+
182
196
  - **`expand:` is the only top-level key.** Everything else, `name` and `type` included, goes under `template:`.
183
197
  - **Each `values:` entry is a list of `{key, value}` pairs,** read as `each.<key>`. `values_expr:` computes the same list from arguments. Every rendered name must be unique.
184
198
  - **A downstream fan-out repeats the same `values:`** and names its dependency with the same key, for example `deps: ["bronze.tb_file_{{ each.company }}"]`. Its SQL then reads the view `tb_file_{{ each.company }}`.
@@ -236,7 +250,7 @@ Storage choices are the hardest to undo. A dataset's store and file format are f
236
250
  | `ICEBERG` (experimental) | One Iceberg table per dataset. Each run writes on its own branch, frozen as a tag when complete | Datasets that accumulate: `append`, `upsert`, incremental SQL extracts | Data that a full rebuild each run would serve as well |
237
251
  | `FARSEER_FILES` (the engine default) | One file per dataset under the pipeline's `Data/` folder. Saving is publishing; there are no versions | Ad hoc output nobody else reads | Anything read downstream: a failing run has already replaced the file |
238
252
 
239
- - **An incremental source gets its own pipeline folder on `ICEBERG`.** Everything that consumes it lives in a `DATASETS` pipeline and reads it with `source: datasets`. That keeps the experimental store to the datasets that need it.
253
+ - **An incremental source gets its own pipeline folder on `ICEBERG`,** holding its extract and the one parse step that reads it. Everything that consumes it lives in a `DATASETS` pipeline and reads the parse step's dataset with `source: datasets`. That keeps the experimental store to the datasets that need it.
240
254
  - **A dataset never changes store.** A run that names a dataset on the wrong store creates it there. For example, a cursor on `DATASETS` is refused only after the dataset exists. Moving it to `ICEBERG` afterwards is refused too, so give the dataset a new name.
241
255
 
242
256
  ### Versions, publication and restore
@@ -244,11 +258,11 @@ Storage choices are the hardest to undo. A dataset's store and file format are f
244
258
  - **Publication waits for the whole run.** By default every dataset publishes only after every step has succeeded, each dataset separately. One failing step therefore publishes nothing, and it holds back every reading position in the pipeline.
245
259
  - **Readers see the last published version.** Other pipelines, `source: datasets` and `query` keep seeing it while a run is in progress. A dataset that was never published reads as missing.
246
260
  - **`restore` makes an earlier published version current again,** and rewinds the reading position to where that version stopped. It cancels any candidate in flight. It does not undo model loads or exports.
247
- - **Nothing is deleted.** Published versions, cancelled candidates, Iceberg snapshots and files superseded by upserts all stay indefinitely, with no expiry and no compaction. A dataset may hold at most 10 unpublished candidates, and abandoned ones are marked cancelled after 24 hours.
261
+ - **Nothing is deleted.** Published versions, cancelled candidates, Iceberg snapshots and files superseded by upserts all stay indefinitely, with no expiry and no compaction. The one exception is an extract's payload, the file it stored, which is removed 30 days after it was stored. A dataset may hold at most 10 unpublished candidates, and abandoned ones are marked cancelled after 24 hours.
248
262
 
249
263
  ### Write modes: decide per dataset
250
264
 
251
- `write_mode` is set per extract or transform and defaults to `overwrite`. `append` and `upsert` work only on `ICEBERG`.
265
+ `write_mode` is set per parse step or transform and defaults to `overwrite`. `append` and `upsert` work only on `ICEBERG`.
252
266
 
253
267
  | | `overwrite` | `append` | `upsert` (with `merge_keys`) |
254
268
  |---|---|---|---|
@@ -264,12 +278,12 @@ Storage choices are the hardest to undo. A dataset's store and file format are f
264
278
  - **`merge_keys` are fixed for the dataset's life.** They must be unique within each run's output, non-null, and finite. Keys cannot be added to a dataset that already has unkeyed history; changing them means a new dataset and a rebuild. A composite key with very many distinct combinations is refused, so lead it with a low-cardinality column, such as the period.
265
279
  - **A mode can change between runs, and nothing stops a harmful change.** Switching a populated dataset from `overwrite` to `append` silently starts accumulating. Change a mode deliberately, with a rebuild if the history no longer fits.
266
280
  - **Rules and `schema:` check the whole accumulated dataset on every run,** including quiet ones, and quality rules load all of it to do so. A rule tightened so that old rows fail it blocks every future publication of that dataset. Budget the validation cost as the history grows.
267
- - **An empty full extract under `overwrite` publishes an empty dataset.** No built-in rule checks a minimum row count. Where an empty source is a fault, put `custom__distinct_count` with `min: 1` on a column that is never null, such as a key.
281
+ - **An empty full extract publishes an empty dataset** through its parse step under `overwrite`. No built-in rule checks a minimum row count. Where an empty source is a fault, put `custom__distinct_count` with `min: 1` on a column that is never null, such as a key.
268
282
  - **Under `upsert`, select columns by name and sort explicitly.** Never read by position.
269
283
 
270
284
  ### Incremental extraction
271
285
 
272
- Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incrementally. Default to extracting the run's slice in full with `overwrite`: it reruns cleanly, and deletions simply disappear. Go incremental only when re-reading the slice is too slow, and only after the source's cursor passes every check below.
286
+ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incrementally. The `cursor_column` stays on the extract; exactly one parse step reads it and carries the `write_mode` and `merge_keys`. Default to extracting the run's slice in full with `overwrite`: it reruns cleanly, and deletions simply disappear. Go incremental only when re-reading the slice is too slow, and only after the source's cursor passes every check below.
273
287
 
274
288
  - **The window is everything strictly after the last committed position, up to a maximum measured at the start, with no lookback.** Three things are never read:
275
289
  - rows that become visible later with a cursor at or below the committed position;
@@ -279,14 +293,14 @@ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incremen
279
293
  - It is a column the source types as a number, a timestamp or a sequence. A text column holding numbers sorts `10.00` below `9.50`: the dataset silently stops growing while the runs stay green.
280
294
  - It is assigned when the row commits. Rows that share the measured maximum and commit after the measurement are lost.
281
295
  - It is never null. The first read refuses null cursors, and later reads skip historical nulls for good.
282
- - **The position advances only when the version publishes,** in the same step that makes it current. A failed run publishes nothing, and the retry may read a wider window.
283
- - **The position is tied to the exact query text,** along with the host, database, table and cursor column. Any edit, a comment or reformatting included, makes later runs refuse until an operator moves the position to the new query through the dataset's watermark endpoint. Treat an incremental query as frozen.
296
+ - **The position advances only when the parse step's version publishes,** in the same action that makes it current. A failed run publishes nothing, and the retry may read a wider window.
297
+ - **The position is tied to the exact query text,** along with the host, database, table and cursor column. Any edit, a comment or reformatting included, makes later runs refuse until an operator moves the position to the new query through the watermark endpoint of the parse step's dataset. Treat an incremental query as frozen.
284
298
  - **A quiet run,** with no new rows, cancels its candidate and keeps the data and the position. It still runs validation.
285
299
  - **There is no lease.** Two runs of one incremental dataset at once cancel each other's work. Give each such dataset one schedule and no overlapping manual runs.
286
300
  - **Rebuilding safely:**
287
301
  1. Stop the schedule.
288
302
  2. Have the operator delete the watermark.
289
- 3. Run once with `write_mode: overwrite`. That reads from the beginning, replaces the table and records a fresh position, and merge keys survive.
303
+ 3. Run once with `write_mode: overwrite` on the parse step. That reads from the beginning, replaces the table and records a fresh position, and merge keys survive.
290
304
  4. Switch back to `append` or `upsert`.
291
305
 
292
306
  Never delete the watermark and rerun under `append`: that stores everything twice. To undo one bad publication, `restore` the previous version instead.
@@ -303,7 +317,7 @@ Only a `sql_database` extract with `cursor_column`, on `ICEBERG`, reads incremen
303
317
 
304
318
  ## 9. Verify
305
319
 
306
- - **Before the first run:** run `check`, confirm every model name with the model tools, and run the extracts once. Then test each SQL transform with `query` against the published extracts, asking for shapes (`DESCRIBE`, `COUNT`, `SUM`, `GROUP BY ... HAVING count(*) > 1`) rather than rows.
320
+ - **Before the first run:** run `check`, confirm every model name with the model tools, and run the extracts and their parse steps once. Then test each SQL transform with `query` against the datasets the parse steps published, asking for shapes (`DESCRIBE`, `COUNT`, `SUM`, `GROUP BY ... HAVING count(*) > 1`) rather than rows.
307
321
  - **After every run:**
308
322
  - `inspect` the run by its UUID: every step OK, `skippedOutputs` empty, each import `commit_confirmed`, and no failed undo.
309
323
  - Query gold for its row count, zero duplicate coordinates, and totals per period against the control totals.