# Expressions

Bei der Konfiguration von Pipelines erlauben gewisse Felder vom Typ Expression die Verwendung von Ausdrücken ("Expressions"). Diese Expressions werden zur Laufzeit durch tatsächliche Werte ersetzt.

Weitere Information können in der Dokumentation der Jinja Templating Sprache (opens new window) nachgeschlagen werden.

Aus Sicherheitsgründen geschieht die Evaluation der Expressions in einer restriktiven "Sandbox"-Umgebung. Aus diesem Grund sind gewissen Funktionalitäten der Jinja Templating Sprache eingeschränkt.

# Beispiel

Konfiguration einer HTTP-Section mit einer Expression:

{
  "section": "HTTP",
  "options": {
    "url": "/path/to/details/{{ item['@id'] }}",
    "foreach": {
      "target_path": ""
    }
  }
}

Die Expression {{ item['@id'] }} wird zur Laufzeit durch tatsächliche Werte ersetzt, basierend auf dem item in der Pipeline.

Angenommen die vorhergehende Section gibt folgende Daten in der Pipeline weiter:

[
  { "@id": 1 },
  { "@id": 2 },
  { "@id": 3 }
]

Dann werden in der HTTP-Section 3 Requests abgesetzt an folgende URLs, die durch das Evaluieren der Expressions entstanden sind:

  • /path/to/details/1
  • /path/to/details/2
  • /path/to/details/3

# Verfügbare Kontext-Variablen

Folgende Variablen können in den meisten Fällen für Expressions verwendet werden:

  • item

    • Das Item in der ETL Pipeline, auf welchem die Section gerade operiert.
    • Typ: Dict
    • Beispiel: {{ item['@id'] }}
  • store

    • Ermöglicht den Zugriff auf die Store-Daten im momentan gesetzten Kontext.
    • Typ: Dict
    • Beispiel: {{ store.store_key }}
  • env

    • Ermöglicht Zugriff auf vordefinierte Variabeln, welche bei der Installation des Systems bereitgestellt werden. Dies ermöglicht es, beispielsweise auf Secrets zuzugreifen, ohne dass diese in der Pipeline gespeichert werden. Hinweis: die Umgebungsvariabeln benötigen im Setup den Präfix ETL_ENV_, welcher aber dann in der Kontext-Variabel entfernt wird.
    • Typ: Dict
    • Beispiel: {{ item.FOO_API_SECRET }}

# Filters

Expressions unterstützen die Builtin Filters (opens new window) der Jinja Template Engine. Zusätzlich können nachfolgende Filter verwendet werden.

# fromjson

fromjson(value)

Der fromjson Filter wird zum Parsen eines JSON Strings verwendet.

# chain

chain(value)

Der chain Filter wird verwendet um mehrere Liste aneinander zu hängen.

>>> [[1, 2], [3, 4]]|chain
[1, 2, 3, 4]

# zip

zip(value)

Der zip-Filter kombiniert Elemente aus mehreren Listen.

Beispiel:

>>> [["a", "b", "c"], [1, 2, 3]] | zip
[("a", 1), ("b", 2), ("c", 3)]

# nossikon

nossikon(value)

Mit dem nossikon-Filter wird Text mit der Nossikon Schriftart dargestellt. Diese Schriftart ist für historische Phonetische Zeichen optimiert.

search(value, pattern, flags=0)

Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding Match. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string. If the value is not a string, None is returned.

>>> 'Some string' | search('stri?') | boolean
True

# match

match(value, pattern, flags=0)

If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding Match. Return None if the string does not match the pattern; note that this is different from a zero-length match. If the value is not a string, None is returned.

If you want to locate a match anywhere in string, use search instead.

>>> 'Some string' | match('^.*str[^!]+$') | boolean
True

# sub

sub(value, pattern, repl, count=0, flags=0)

Replace a string with the functionality of python RegEx re.sub function documented at https://docs.python.org/3/library/re.html#re.sub

If the value is not a string, the value is returned.

# split

split(value, sep, maxsplit=-1)

Split a string into a list of strings. If the value is not a string, the value is returned.

# omit

omit(value, *keys)

Accepts a dict and returns the same object but without selected keys.

# parse_datetime

parse_datetime(value, timezone_aware=True)

Parse a string and return a datetime.datetime.

This function will convert the input timezone to the configured timezone, even if the input contains timezone information. To disable timezone awareness, set timezone_aware to False.

Raise ValueError if the input is well formatted but not a valid datetime. Return None if the input isn't well formatted.

# strftime

strftime(value, format)

Accepts a datetime object and formats it as string with the defined format.

See the python format code documentation for details: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

# now

now(value)

Returns the current time as a datetime object with the configured timezone.

Since Jinja filters operate on a value, this filter has to be operated on any value. The value itself is not relevant.

Example usage:

{% set foo = None|now %}

# today

today(value)

Returns the current time as a date object.

Since Jinja filters operate on a value, this filter has to be operated on any value. The value itself is not relevant.

Example usage:

{% set foo = None|today %}

# timedelta

timedelta(value, days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

Accepts a datetime object and changes it relative to the timedelta.

Example:

{{ '2024-04-01T09:00:00' | parse_datetime | timedelta(days=2) }}

For a negative operation, simply define negative arguments:

{{ '2024-04-01T09:00:00' | parse_datetime | timedelta(days=-2) }}

If you want to just have a timedelta object for a later operation, apply the filter on a None value:

{% set foo = None | timedelta(days=-2) %}

# rjust

rjust(value, width, fillchar=' ')

Right-justify a string to given width and character. The default character is space. If the value is not a string, it will be converted to one.

Example:

>>> "hello"|rjust(10)
'     hello'
>>> "4"|rjust(3, '0')
'004'

# Functions

# queryset_source

queryset_source(model, filter, values)

Funktion zum Laden von Daten aus der Datenbank.