Skip to main content
GuideServerConfigure and deploy Tabsdata servers on your machine.TutorialsConfigure data integration workflows within a running Tabsdata server.API ReferenceCLI ReferenceRelease Notes
Version: 2.1.0

Transformers

A transformer function reads data from one or more tables in the Tabsdata server, transforms the data, then writes the transformed data to tables in the server.

Transformers in Action​

collection · world
collection · insights · data product
Table
country
//world
Committed
Table
city
//world
Committed
Transformer
find_big_cities
Table
big_cities
//insights
No versions yet

Transformer Code Anatomy​

find_big_cities.py
1from tabsdatak.api import transformer, TableFrameSpec
2import tabsdatak.api.tableframe as tdf
3
4
1@transformer(
2 input_tables=["world/country", "world/city"],
3 output_tables=["big_cities"],
8)
45def find_big_cities(country: TableFrameSpec, city: TableFrameSpec) -> tuple[TableFrameSpec]:
6 countries = country.rename({"name": "country_name"}).drop(
11 ["population", "continent"]
12 )
13 joined = city.join(countries, left_on="country_code", right_on="code")
7 return (joined.filter(tdf.col("population") > 3_000_000),)
  • Defines the input and output Tables for the Transformer.

    • Tabsdata Tables to read. Use collection/table to reference a Table in another Collection.

    • Tables where the transformed data is written. These belong to the Transformer's Collection.

  • Reads the country and city data, joins it, and returns cities with a population above three million.

    • The arguments receive the data from input_tables in the order listed. An argument is None if the requested Table version does not exist.

    • Renames the country name column, removes unused columns, and joins the country and city data.

    • The returned data is written to the Tables listed in output_tables, in that order. Returning None for a Table leaves its current version unchanged.

For step-by-step guidance on building a transformer, see Transformers under How-to Guides.