To define the Python transformation functionality, you enter Python code snippets on the
Python
tab. Enter code snippets to reconstruct input variables, load a pre-trained model, define output variables, and define additional transformation functionality.
Enter Python code snippets in the following sections of the Python editor:
Pre-Partition Python Code
Defines code that can be interpreted one time and shared among all rows of data.
Use the
Pre-Partition Python Code
section to perform the following tasks:
Declare import statements.
Declare variables.
Initialize variables.
Define helper methods.
Main Python Code
Defines how the Python transformation behaves when it receives an input row while processing a partition. The Python transformation processes the code on the
Main Python Code
section for each partition and each row.
Post-Partition Python Code
Defines how the Python transformation behaves after it processes all input data in a partition. You can call the
generateRow()
method to generate output rows.
Use the following guidelines when you write Python code:
Define variables before you use them. For example, you cannot reference a variable in the
Pre-Partition Python Code
section if the variable is defined in the
Main Python Code
section.
Call the incoming field name to access incoming fields.
The Python code must assign a value to each output field.
To define how the transformation writes data from the incoming fields to output fields, set the output field to the value of the incoming field.
For example, write
output_field = incoming_field
to write the data from the incoming field
incoming_field
to the output field
output_field
.
To access resource files, use the variable
resourceFilesArray
. Specify the resource file using an index such as
resourceFilesArray[0]
.
The Mapping Designer does not validate Python code.