FeTL 0.1.0

dotnet add package FeTL --version 0.1.0
                    
NuGet\Install-Package FeTL -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FeTL" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FeTL" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FeTL" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FeTL --version 0.1.0
                    
#r "nuget: FeTL, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FeTL@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FeTL&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FeTL&version=0.1.0
                    
Install as a Cake Tool

FeTL

FeTL is a small F# library for ETL pipelines that are idempotent: a second run with the same inputs does no work.

dotnet add package FeTL

FeTL does these tasks:

  • It makes a hash from the parameters of each step and from the steps before it.
  • It makes the file names from that hash.
  • It saves and loads the outputs through plug-ins.
  • It knows the graph of the steps, and it runs the steps in a correct sequence.
  • It starts processes and sends HTTP requests for the steps that need them.

FeTL does not do these tasks. A plug-in does them:

  • The file formats and the data types (a Codec).
  • The places that keep the data: a folder, an S3 bucket, a DuckDB database (an IStore or a Sink).
  • The transformations (the code of each node).

Example

open System.IO
open FeTL

let store = LocalStore "data"

// A parameter of the run, and a file that the pipeline does not make.
let factor = Etl.param<float> "factor"
let input = Source.file "in/prices.txt"

// A node: a name, its arguments, a sink and code.
let prices =
    Etl.node "prices" input (Sink.file store Codec.json) (etl {
        let! file = input
        return File.ReadAllLines file.Path |> Array.map float
    })

let smoothed (window: int) =
    Etl.node "smoothed" (prices, factor, window) (Sink.file store Codec.json) (etl {
        let! values = prices
        let! k = factor
        return values |> Array.windowed window |> Array.map (fun part -> k * Array.average part)
    })

let engine = Engine(log = store)
engine.Set(factor, 2.0)
let result = engine.Run(smoothed 3).Result

The first run builds two outputs. The second run reads their stamps and runs no code. A run with factor = 10 uses the output of prices and writes the output of smoothed again, in the same file:

data/prices/be60e916f0b9a997.json            the output: the name of the node and its id
data/prices/be60e916f0b9a997.json.stamp      the stamp: the hash of the inputs and the hash of the content
data/smoothed/3-bf80ca1c55690241.json        the label `3` is the argument `window`
data/smoothed/3-bf80ca1c55690241.json.stamp
data/_fetl/smoothed/3-bf80ca1c55690241.json  the log of the last build: the arguments and the inputs

engine.Plan node gives the steps of a run and builds nothing. A node is Unknown in a plan when it builds only if a node before it changes its content. Graph.mermaid gives the graph:

flowchart LR
    n0(["file<br/>home-me-in-prices.txt<br/>(probe)"])
    n1["prices<br/>(build)"]
    n2(["factor<br/>(probe)"])
    n3["smoothed<br/>3<br/>(build)"]
    n0 --> n1
    n1 --> n3
    n2 --> n3

The rules

A node has a name, a version, arguments and code. An output has two hashes, and they have different functions.

  1. The arguments are all that the output is made from. They are the parameters and the nodes that the code gets values from. A node in the arguments is a dependency: FeTL finds it there, with no second list.
  2. The id of a node is the hash of its name, its version and its arguments. A node in the arguments gives its id. The id says what the node is, and it gives the name of the output. It is known with no run, and new data in a source does not change it.
  3. The content hash of an output is the hash of its data. The sink makes it when it saves the output, and keeps it in a stamp with the output. The content hash of a source is the hash of its value.
  4. A stored node runs in two conditions. The sink has no output for its id, or the content of a node in its arguments is different from the last build. The stamp has the hash of the inputs of the last build.
  5. An output that did not change stops the work. If a node runs again and gives the same content, the nodes after it do not run.
  6. The code can get a value only from a node in its arguments. A different node is an error. Without this rule, the node would not run again when that node changes.

A change of the id gives a new output with a new name, and the old output stays. A change of the content of an input writes the output again in the same place. Thus:

  • A value in the arguments, for example window, gives one file for each value.
  • A source or a parameter of the run (Etl.param) gives one file, which a run with new data writes again.

There are three types of nodes:

Function Sink When the code runs Use
Etl.node, Etl.file Yes Rule 4 The steps that do work
Etl.calc No In each run that needs its value Small work between two steps
Etl.source, Etl.param, Source.file No In each run Data that the pipeline does not make

A source gives a small value that changes when the data changes: a path with a size and a time, the ETag of an S3 object, the largest date in a table. A source can have only sources in its arguments.

A node with no sink has no content hash of its own. Its content changes when the content of a node before it changes.

A run reads the stamp of each stored node, from the sources to the node that it runs. The engine keeps no other state: the stamps are in the sinks, with the outputs.

Hashes

Hash.ofValue gives the same hash in each process. It accepts numbers, text, dates, enumerations, tuples, records, unions, lists, arrays, Map, Set and nodes. A different value is an error, for example a function or a Dictionary. Hash.canonical gives the text that the hash is made from.

The version of the code is manual. Change it with Etl.version when a change of the code changes the output.

File names

A sink gets a Slot (the name, a label and the id). Slot.Path "parquet" is name/label-id16.parquet, and Slot.Ident is name_id16, for a table. The label is the text of the arguments that are not nodes. The name can contain /. node.Slot gives the slot with no run.

Plug points

Plug point Type In the library What you add
A place for files IStore (6 members) LocalStore S3: Uri gives s3://bucket/key, Write and Import are an upload
A file format Codec<'T> Codec.json Parquet, Arrow, CSV, arrays of numbers
A place for outputs Sink<'T> (Stamp, Save, Load) Sink.file store codec A table in DuckDB or in a database
External data Etl.source Source.file, Source.fileContent An S3 object, a prefix, a table
A service Engine.Handle and Etl.perform none A connection to a database, an S3 client

For a tool that reads and writes files by address, such as DuckDB, use Etl.file. The code gets a Blob and writes it with Blob.WriteFile. The store gives the address to write to, and the file gets its final name only after the code ended with no failure. The value of the node is the Blob, and the next node reads Blob.Uri.

A sink decides what "the same content" is. Sink.file and Etl.file use the hash that the store gives when it writes the file: IStore.Write and IStore.WriteAt give the content hash of what they wrote. FeTL does not read an output again for its hash. LocalStore gives the SHA-256 of the bytes:

  • For a codec, the hash is made while the codec writes. A codec that writes a part of the file a second time gets the hash of the complete file, with one more read.
  • For a tool that writes to an address, LocalStore reads the file one time before the file gets its final name.

The table sink of the DuckDB example uses a hash of the rows that does not change with their sequence. A sink that cannot make such a hash gives a new hash for each build: the nodes after it then run after each build.

tests/FeTL.Tests/DuckDbTests.fs is an example with DuckDB: a CSV source, a Parquet file that DuckDB writes, a table sink with its stamps in a table, and a handler. tests/FeTL.Tests/PlugTests.fs has a store that is not a folder. The library has no S3 package and no DuckDB package.

A node that reads what the pipeline does not make

Two hashes control a node. The hash of the inputs, in its stamp, says if the node runs. The content hash says if the nodes after it run. FeTL does not see what a process or a request reads, and it does not know if the same inputs give the same bytes. Thus the author selects one of four forms:

Form The step How to make the node When it runs
1 Makes its output from its inputs only: it converts, compresses, renders, compiles The inputs and the parameters are in the arguments, with Proc.Version for a tool When an input, a parameter or the version of the tool changes
2 Reads data from outside, and a small question finds a change A source for that data is in the arguments: Source.file, Http.head, a query When the value of the source changes
3 Reads data from outside, and only the step can find a change: a mirror, a scraper, an export A source of time is in the arguments: Source.eachRun or Source.every period In each run, or one time in each period
4 Changes a thing that is not its output: it loads a table, it sends a message The output is a small record of what the step did. The effect must be safe to do again As form 1 or 2, and again after a failure

In form 3 the node runs in each run, and its content hash controls the nodes after it: with the same output, they do not run. For each form:

  • A current stamp starts no code. The output is complete, or it is not there.
  • A step can run more than one time for the same inputs: after a failure, after a cancellation, after the loss of a stamp, and for two runs at the same time. A second run must be safe.
  • A step that gives different bytes for the same inputs is correct, and the nodes after it run after each of its runs.

A set of files

Etl.files is a node whose output is many files, for example the files of a process. The code gets a writer. Its tools write to out.Scratch, and the code then registers each file of the output:

let frames (scene: Node<Blob>) =
    Etl.files "frames" (scene, Proc.Version("blender", [ "--version" ])) store (fun out ->
        etl {
            let! input = scene
            let! _ = Proc.Run(cli { Exec "blender"; Arguments [ "-b"; input.Uri; "-o"; out.Scratch + "/frame_####" ] })
            do! out.RegisterFolder(out.Scratch, "*.png")
        })
frames/a1b2c3d4e5f60718/frame_0001.png          a file of the set
frames/a1b2c3d4e5f60718.files.json              the manifest: path, length and SHA-256 of each file
frames/a1b2c3d4e5f60718.files.json.stamp        the stamp of the node
  • The value of the node is a FileSet: set.Files, set.Blob path and set.Blobs. Give a tool the files of the set, not the folder: a file of an older build that is not in the manifest stays in the store.
  • The content hash of the node is the hash of the manifest. The nodes after it run again only when a file is new, different or gone.
  • Register reads each file one time for its hash. A file that is in the last manifest with the same hash does not go to the store again.
  • A file goes to the store with IStore.Import. LocalStore moves a file of the scratch folder, with no second write, and it copies a file of a different folder.

A node has two folders of this computer:

Folder In the code Use
The scratch folder out.Scratch, Etl.scratch New and empty in each run. The engine removes it after the code
The workspace out.Workspace, Etl.workspace It stays between the runs: for a tool of form 3 that updates a folder

Engine(workFolder = "...") gives the folder for the two. Put it on the disk of the store: a move is then a change of the name. With no such folder, a scratch folder is in the temporary folder of the system, and a node cannot have a workspace. FeTL does not trust a workspace: each run makes the hash of each file that the code registers.

A process

Proc.Run starts a process and gives its exit code, its output and its error output. Fli describes the command (cli { ... }), and FeTL starts the process with its own code:

let commit =
    Etl.node "commit" repository (Sink.file store Codec.json) (etl {
        let! folder = repository
        let! result = Proc.Run(cli { Exec "git"; Arguments [ "rev-parse"; "HEAD" ]; WorkingDirectory folder.Path })
        return result.Text
    })
  • The output and the error output are read while the process runs, each by its own reader.
  • A cancellation of the run stops the process and each process that it started. CancelAfter of the description does the same after its time, and the result is a TimeoutException.
  • An exit code that is not in okExitCodes (0 if not given) is a ProcessFailedException, with the command and the last lines of the error output.
  • The folder of the process is the scratch folder of the node, if the description gives none.
  • onLine gets each line while the process runs.
  • Proc.Version(program, arguments) is a source: the first line that the tool writes for its version.
  • FeTL does not apply Verb, UserName, Credentials, WindowStyle and Output of a description: a description with one of them is an error.

FeTL does not call Command.execute and Command.executeAsync of Fli. In Fli 1.1001.0 they do not end for a process that writes more than the pipe holds, and they do not stop a process after a cancellation: tests/FliChecks/fli-checks.fsx shows the two.

HTTP

In the code of a node, FsHttp works with no help: let! gets the result of Request.sendAsync, and the request stops with the run. Http has the nodes that each pipeline writes:

let prices =
    let head = Http.head "prices-head" url (fun url -> http { HEAD url; AuthorizationBearer token })
    Http.download "prices" head store "csv" (fun url -> http { GET url; AuthorizationBearer token })
  • Http.head is a source: one HEAD request, with the ETag, the time of the last change and the length (form 2).
  • Http.download keeps the body of a GET request in a store, as a stream. It runs when the source changes.
  • Http.fetch is the download for a server that gives no ETag, no time and no length (form 3). Its trigger is a source of time. With the same body, the nodes after it do not run.
  • The function makes the request, thus a secret is in no argument, no hash and no log.
  • A status that is not 2xx is an HttpFailedException.

An HttpPolicy has the retries and the limit. Http uses HttpPolicy.Default: 3 retries, a first delay of 1 second, and 8 requests at the same time. Use one policy for one server.

  • A retry is for a failure that can go away: no connection, a connection that stops, a timeout, and the statuses 408, 429, 500, 502, 503 and 504. A different status, for example 404, gets no retry.
  • The delay becomes two times as long after each retry. If the server gives Retry-After, the delay is that time.
  • A download that stops in the body starts again from its start.
  • policy.Send request gives code the same retries and the same limit. It sends again only a request whose method is safe to send again: GET, HEAD, PUT, DELETE and OPTIONS. A POST gets no retry.
  • A cancellation of the run stops a request and a delay.

How the code of a node runs

The code of a node is effectful code: EffectfulCode, a copy of the file of FCCTT. etl { } makes a value of type Etl<'T>. In it:

Construct What it gets
let! on a node, or on an array of nodes The value of the node, or an array of the values
let! on a Task<'T>, a Task, a ValueTask<'T> or a ValueTask The result of the task
let! on an Async<'T> The result. The computation starts with the cancellation token of the run
let! on other Etl<'T> code The result of that code
for on an IAsyncEnumerable<'T> Each item. The enumerator gets the cancellation token of the run
let! token = Etl.cancellationToken The cancellation token of the run

The code does not call the engine. It makes an effect (Effect.Need, Effect.Await, Effect.Slot, or an effect of a plug-in) and stops. The engine answers the effect, and the code continues. Thus:

  • The engine sees each value that the code gets, and it applies rule 6.
  • A failure of an answer is raised in the code at the let!. A try there can catch it.
  • A test can give different answers to the same code: Engine.Handle.
  • Code that waits uses no thread.

The code is a value in a node, thus it runs in the dynamic mode of EffectfulCode (deferDynamic). The engine drives each frame itself (Frame.MoveNext, Frame.Resume, Frame.Fail) because an answer can be a task. It does not use Scheduler.run.

The nodes in the arguments of a node run at the same time. Engine(maxParallel = n) limits the code that runs at the same time. Code that waits is not in that number.

Cancellation

Engine(cancellationToken = token) gives a token to the run. Give Etl.cancellationToken to each call in the code that accepts a token, for example to HttpClient. After the cancellation:

  • The engine starts no code.
  • Code that waits gets OperationCanceledException at its let!, also for a task that has no token. Its finally and use then run.
  • The run ends with OperationCanceledException, not with NodeFailedException.
  • A node that stopped has no stamp, and the next run builds it.

A store and a sink get no token. The engine stops its wait for them, and a sink that continues gives a complete output with its stamp.

What FeTL does not do

  • It does not find a change of the code. Change the version.
  • It does not keep the old data of an output. New data in a source writes the output again in its place.
  • It does not find dependencies while the code runs. The arguments give them before the run. For a list that is known only at run time, run the node of the list first, then make the nodes from its value.
  • It does not delete the outputs of ids that no node has now. The logs in _fetl/ say what an output is.
  • It does not release values. An engine keeps each value that it loaded until the end of the run.
  • It does not limit the tasks that wait at the same time. An HttpPolicy limits its requests. A different task has no limit: a fan-out of 5,000 of them runs 5,000 at the same time.
  • It does not delete a file that left a set of files. The file stays in the store, and the set does not have it.
  • It does not stop the other nodes when a node fails. The run ends after each node that started came to its end.
  • It does not know what a handler reads. Put all that changes the output in the arguments.
  • It does not see two different nodes with one id. A name must identify the code and the type of a node.
  • It does not stop two runs that write one output at the same time. Each file is complete, but the stamp can be the stamp of the other run. The next run then builds the node again.
  • It does not skip a node whose code gives different bytes for the same inputs. The result is correct, and the nodes after it run.

Build and test

dotnet test FeTL.slnx -c Release

The library targets .NET 10. It has two package references: Fli, for the description of a command, and FsHttp, for the HTTP requests. The tests use MSTest, and DuckDB.NET for the DuckDB example. The tests of the processes need Linux with bash: they read /proc and use GNU cp.

To release a version, push a tag such as v0.1.0. The Release workflow runs the tests, packs that version and pushes it to nuget.org with the NUGET_TOKEN secret of the repository.

Licence

FeTL is under the MIT License: see LICENSE. Credit for orgination of the alebraic effects deisgn: https://github.com/zhxxch/EffectfulCode

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 0 12/1/2026