Upload operator.py with huggingface_hub
Browse files4 unmodified lines5678891063 unmodified lines74757678777879808180828384858687888987888990919091929394959612 unmodified lines1091101111101111121131141121131141151161171189 unmodified lines12812913013013113213313413113213313413513613713813914014112 unmodified lines15415515615315715815916016116216316416554 unmodified lines220221222214223224225226227228229230231232153 unmodified lines38638738837438939039139239329 unmodified lines42342442541042642742842943043116 unmodified lines4484494504334344514524534544 unmodified lines
from .artifact import Artifactfrom .dataclass import NonPositionalFieldfrom .random_utils import nested_seedfrom .stream import MultiStream, Stream
63 unmodified linesclass SourceOperator(StreamSource): """A class representing a source operator in the streaming system.
A source operator is responsible for generating the data stream from some source, such as a database or a file. This is the starting point of a stream processing pipeline. The `SourceOperator` class is a type of `StreamSource`, which is a special type of `StreamingOperator` that generates an output stream but does not take any input streams. A source operator is responsible for generating the data stream from some source, such as a database or a file. This is the starting point of a stream processing pipeline. The `SourceOperator` class is a type of `StreamSource`, which is a special type of `StreamingOperator` that generates an output stream but does not take any input streams.
When called, a `SourceOperator` invokes its `process` method, which should be implemented by all subclasses to generate the required `MultiStream`. When called, a `SourceOperator` invokes its `process` method, which should be implemented by all subclasses to generate the required `MultiStream`.
"""
caching: bool = NonPositionalField(default=None)
def __call__(self) -> MultiStream: with nested_seed(): multi_stream = self.process() if self.caching is not None: multi_stream.set_caching(self.caching) return multi_stream multi_stream = self.process() if self.caching is not None: multi_stream.set_caching(self.caching) return multi_stream
@abstractmethod def process(self) -> MultiStream:12 unmodified lines caching: bool = NonPositionalField(default=None)
def __call__(self, *args, **kwargs) -> MultiStream: with nested_seed(): multi_stream = self.process(*args, **kwargs) if self.caching is not None: multi_stream.set_caching(self.caching) return self.process(*args, **kwargs) multi_stream = self.process(*args, **kwargs) if self.caching is not None: multi_stream.set_caching(self.caching) return self.process(*args, **kwargs)
@abstractmethod def process(self, *args, **kwargs) -> MultiStream:9 unmodified lines caching: bool = NonPositionalField(default=None)
def __call__(self, multi_stream: Optional[MultiStream] = None) -> MultiStream: with nested_seed(): result = self._process_multi_stream(multi_stream) if self.caching is not None: result.set_caching(self.caching) return result self.before_process_multi_stream() result = self._process_multi_stream(multi_stream) if self.caching is not None: result.set_caching(self.caching) return result
def before_process_multi_stream(self): pass
def _process_multi_stream( self, multi_stream: Optional[MultiStream] = None12 unmodified linesclass SingleStreamOperator(MultiStreamOperator): """A class representing a single-stream operator in the streaming system.
A single-stream operator is a type of `MultiStreamOperator` that operates on individual `Stream` objects within a `MultiStream`. It iterates through each `Stream` in the `MultiStream` and applies the `process` method. The `process` method should be implemented by subclasses to define the specific operations to be performed on each `Stream`. A single-stream operator is a type of `MultiStreamOperator` that operates on individual `Stream` objects within a `MultiStream`. It iterates through each `Stream` in the `MultiStream` and applies the `process` method. The `process` method should be implemented by subclasses to define the specific operations to be performed on each `Stream`.
"""
apply_to_streams: List[str] = NonPositionalField(54 unmodified linesclass PagedStreamOperator(SingleStreamOperator): """A class representing a paged-stream operator in the streaming system.
A paged-stream operator is a type of `SingleStreamOperator` that operates on a page of instances in a `Stream` at a time, where a page is a subset of instances. The `process` method should be implemented by subclasses to define the specific operations to be performed on each page. A paged-stream operator is a type of `SingleStreamOperator` that operates on a page of instances in a `Stream` at a time, where a page is a subset of instances. The `process` method should be implemented by subclasses to define the specific operations to be performed on each page.
Args: page_size (int): The size of each page in the stream. Defaults to 1000. """
page_size: int = 1000153 unmodified linesclass SequentialOperator(MultiStreamOperator): """A class representing a sequential operator in the streaming system.
A sequential operator is a type of `MultiStreamOperator` that applies a sequence of other operators to a `MultiStream`. It maintains a list of `StreamingOperator`s and applies them in order to the `MultiStream`. A sequential operator is a type of `MultiStreamOperator` that applies a sequence of other operators to a `MultiStream`. It maintains a list of `StreamingOperator`s and applies them in order to the `MultiStream`. """
max_steps = None29 unmodified linesclass SourceSequentialOperator(SequentialOperator): """A class representing a source sequential operator in the streaming system.
A source sequential operator is a type of `SequntialOperator` that starts with a source operator. The first operator in its list of steps is a `StreamSource`, which generates the initial `MultiStream` that the other operators then process. A source sequential operator is a type of `SequentialOperator` that starts with a source operator. The first operator in its list of steps is a `StreamSource`, which generates the initial `MultiStream` that the other operators then process. """
def __call__(self) -> MultiStream:16 unmodified lines """
def __call__(self, *args, **kwargs) -> MultiStream: with nested_seed(): return self.process(*args, **kwargs) return self.process(*args, **kwargs)
def process(self, *args, **kwargs) -> MultiStream: assert (operator.py+41-24