Styx Operator
Operator(name, n_partitions=1)
¶
Bases: BaseOperator
A stateful operator that executes user-defined stateful functions in Styx.
This class handles function registration, partitioning logic, communication between workers, and execution of distributed function chains.
Initializes the operator with a name and number of partitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the operator. |
required |
n_partitions
|
int
|
The number of partitions. Defaults to 1. |
1
|
register(func)
¶
Registers a function with this operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
type
|
The function class or callable to register. |
required |
set_n_partitions(n_partitions)
¶
Sets the number of partitions and updates the partitioner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_partitions
|
int
|
New number of partitions. |
required |
which_partition(key)
¶
Determines the partition for a given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Any
|
The key to partition. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The partition number. |
BaseOperator(name, n_partitions=1)
¶
Bases: object
Abstract base class for Styx operators.
This class defines the required interface for any operator used in a Styx dataflow. Concrete subclasses must implement partitioning logic.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Name of the operator. |
n_partitions |
int
|
Number of partitions used by the operator. |
Initializes a base operator with a name and number of partitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the operator. |
required |
n_partitions
|
int
|
Number of partitions. Defaults to 1. |
1
|
which_partition(key)
abstractmethod
¶
Determines the partition index for a given key.
This method must be implemented by subclasses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Any
|
A key used to determine the partition. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The partition number corresponding to the key. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not overridden by a subclass. |