Create Operators with the Python Subengine

Create operators in Python using the Python subengine, and use them to build graphs in the SAP Data Intelligence Modeler.

When you run a graph in the Modeler, the main engine that coordinates all subengines breaks the graph into large subgraphs. The advantage is that every operator in the same subgraph is run by the same subengine. The main engine then starts a subengine process for each subgraph.

Data Type Mapping

The following table shows the data type mapping between the Modeler and the Python subengine.

Modeler Data Type

Python Subengine Data Type

string

str

blob

bytes

int64

int

uint64

int

float64

float

byte

int

message

Message

[ ]x

Replace the letter x with any of the allowed data types, excluding message. For example, [ ]string, [ ]uint64, [ ]blob, and so on.

list

If you create operators that receive or send data types that have no direct mapping to Modeler data types, you must create ports with type python 3.9.
Operators created with ports of type python 3.9 can communicate with any Python object, including objects with no corresponding Modeler type, such as set, numpy arrays, and so on. There's one exception: Subengine-specific types can't cross the boundary between two Modeler groups. However, if you place your Python-specific object inside the body of a message, then the body is correctly serialized and deserialized with pickle (a Python module) when crossing the boundary between two groups.
Create the message type using the format Message(body, attributes), where:
  • body can be any object.

  • attributes is a dictionary-mapping string to any object.

If m is an object of type message, then you can use the commands m.body and m.attributes to access the fields initialized in the class constructor. The attributes argument is optional in the message constructor. If you want an empty attributes string, you can construct your message using the format Message(body).

SAP recommends that you don't use a message inside the body of another message. Instead, use a dictionary inside the body of a message. The dictionary must have the keys "Body" and "Attributes". Using a message object as the body of another message can result in unexpected behavior when you transfer the message across the boundary of different subengines.

Therefore, SAP recommends to always prefer dictionaries over messages inside the body of a message, because it won't change type during the communication.

# DO NOT DO THE FOLLOWING:
inner_msg = Message("body_of_inner_msg")
outer_msg = Message(body=inner_msg, attributes={})
# If you want to have a message as the body of another message, do this instead:
inner_msg = {"body": "body_of_inner_msg"}
outer_msg = Message(inner_msg)

Methods to Create Python Operators

Use one of the following two methods to create your own Python operators:
  • Normal usage: To create normal Python subengines, use only the Modeler user interface.

  • Advanced usage: To create new Python operators, use the advanced method, which shows you how to use your own machine and then upload the new operators to SAP Data Intelligence. The advanced usage method of creating operators is useful when you want to code in your own IDE and create unit tests for your operators.