Upload operator.py with huggingface_hub
Browse files4 unmodified lines56789101163 unmodified lines757677787980818283848586878889909192939412 unmodified lines1071081091101111121131141151161179 unmodified lines12712812913013113213313413513613712 unmodified lines15015115215315415515654 unmodified lines211212213214215216217153 unmodified lines37137237337437537637729 unmodified lines40740840941041141241316 unmodified lines4304314324334344354364374 unmodified linesfrom .artifact import Artifactfrom .dataclass import NonPositionalFieldfrom .random_utils import nested_seedfrom .stream import MultiStream, Stream63 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.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@abstractmethoddef process(self) -> MultiStream:12 unmodified linescaching: 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)@abstractmethoddef process(self, *args, **kwargs) -> MultiStream:9 unmodified linescaching: 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 resultdef _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`."""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."""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`."""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."""def __call__(self) -> MultiStream:16 unmodified lines"""def __call__(self, *args, **kwargs) -> MultiStream:with nested_seed():return self.process(*args, **kwargs)def process(self, *args, **kwargs) -> MultiStream:assert (4 unmodified lines567891063 unmodified lines747576777879808182838485868788899091929394959612 unmodified lines1091101111121131141151161171189 unmodified lines12812913013113213313413513613713813914014112 unmodified lines15415515615715815916016116216316416554 unmodified lines220221222223224225226227228229230231232153 unmodified lines38638738838939039139239329 unmodified lines42342442542642742842943043116 unmodified lines4484494504514524534544 unmodified linesfrom .artifact import Artifactfrom .dataclass import NonPositionalFieldfrom .stream import MultiStream, Stream63 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.When called, a `SourceOperator` invokes its `process` method, which should be implemented by all subclassesto generate the required `MultiStream`."""caching: bool = NonPositionalField(default=None)def __call__(self) -> MultiStream:multi_stream = self.process()if self.caching is not None:multi_stream.set_caching(self.caching)return multi_stream@abstractmethoddef process(self) -> MultiStream:12 unmodified linescaching: bool = NonPositionalField(default=None)def __call__(self, *args, **kwargs) -> MultiStream:multi_stream = self.process(*args, **kwargs)if self.caching is not None:multi_stream.set_caching(self.caching)return self.process(*args, **kwargs)@abstractmethoddef process(self, *args, **kwargs) -> MultiStream:9 unmodified linescaching: bool = NonPositionalField(default=None)def __call__(self, multi_stream: Optional[MultiStream] = None) -> MultiStream:self.before_process_multi_stream()result = self._process_multi_stream(multi_stream)if self.caching is not None:result.set_caching(self.caching)return resultdef before_process_multi_stream(self):passdef _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 operationsto 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 instancesin 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 operationsto 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`."""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 `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:return self.process(*args, **kwargs)def process(self, *args, **kwargs) -> MultiStream:assert (
operator.py+41-24