Skip to content

Transform Function

When specifying a transform function, all of its parameters are automatically populated with the appropriate dataframes of type polars.LazyFrame.

# input is of type LazyFrame
def transform(input):
...

A transform function must return a value. The return type can be one of the following:

  • polars.LazyFrame
  • polars.DataFrame
  • pandas.DataFrame

Input parameters also expose a special attribute called ds_meta. This attribute contains metadata about the DataSnapshot being used. The following fields are available through this attribute:

AttributeTypeDescription
transform_idstrThe Transform ID of the dataframe
artifact_dirstrThe directory path where the artifacts are stored
data_snapshot_idstrThe DataSnapshot ID of the dataframe
build_idstrThe Build ID of the dataframe
row_countintNumber of rows
column_countintNumber of columns
file_sizeintThe size of the parquet file
creation_datestrThe date when the dataset was created
columnslistThe columns of the dataframe

This is useful when pulling artifacts from upstream transforms. In this case, you can specify the upstream transform and call the artifact_dir:

def transform(excel_ingest):
artifact_path = excel_ingest.ds_meta.artifact_dir

DataSpace injects certain system environment variables to communicate with the runner on where to store certain files.

Name Description
TRANSFORM_ID The transformId of the current transform
ARTIFACT_FOLDER The artifact folder of the current build. Should be used to persist artifacts after build
META_FOLDER The meta folder of the current build. Will be populated with metadata about the dataset if generated
DATASET_FOLDER The dataset folder of the current build. Will be populated with the generated parquet file
PREVIOUS_BUILD_FOLDER The current transforms previous build folder
PREVIOUS_DATASET_PATH The current transforms previous generated dataset file path
PREVIOUS_ARTIFACT_FOLDER The current transforms previous generated artifact folder