forked from apache/incubator-wayang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WAYANG-#8] add TextFileSinkOperator
Signed-off-by: bertty <[email protected]>
- Loading branch information
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pywayang.operator.base import WyOperator | ||
|
||
class SinkUnaryOperator(WyOperator): | ||
|
||
def __init__(self, name:str): | ||
super().__init__(name, None, str, 0, 1) | ||
|
||
def __str__(self): | ||
return super().__str__() | ||
|
||
def __repr__(self): | ||
return super().__repr__() | ||
|
||
|
||
|
||
class TextFileSink(SinkUnaryOperator): | ||
|
||
path: str | ||
|
||
def __init__(self, path: str): | ||
super().__init__('TextFileSink') | ||
self.path = path | ||
|
||
def __str__(self): | ||
return super().__str__() | ||
|
||
def __repr__(self): | ||
return super().__repr__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
python/src/pywayang/platforms/python/operators/PyTextFileSinkOperator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pywayang.operator.sink import TextFileSink | ||
from pywayang.platforms.python.operators.PythonExecutionOperator import PythonExecutionOperator | ||
from pywayang.platforms.python.channels import ( | ||
Channel, | ||
ChannelDescriptor, | ||
PyIteratorChannel, | ||
PyIteratorChannelDescriptor | ||
) | ||
from typing import Set | ||
|
||
class PyTextFileSinkOperator(TextFileSink, PythonExecutionOperator): | ||
|
||
def __init__(self, origin: TextFileSink = None): | ||
path = None if origin is None else origin.path | ||
super().__init__(path) | ||
pass | ||
|
||
def execute(self, inputs: Channel, outputs: Channel): | ||
self.validateChannels(inputs, outputs) | ||
if isinstance(inputs[0], PyIteratorChannel) : | ||
file = open(self.path,'w') | ||
py_in_iter_channel: PyIteratorChannel = inputs[0] | ||
iterable = py_in_iter_channel.provide_iterable(); | ||
for element in iterable: | ||
file.write(str(element)) | ||
file.close() | ||
|
||
else: | ||
raise Exception("Channel Type does not supported") | ||
|
||
|
||
def getInputChannelDescriptors(self) -> Set[ChannelDescriptor]: | ||
return {PyIteratorChannelDescriptor} | ||
|
||
def getOutputChannelDescriptors(self) -> Set[ChannelDescriptor]: | ||
raise Exception("The PyTextFileSource does not support Output Channels") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from pywayang.platforms.python.operators.PythonExecutionOperator import PythonExecutionOperator | ||
from pywayang.platforms.python.operators.PyFilterOperator import PyFilterOperator | ||
from pywayang.platforms.python.operators.PyTextFileSourceOperator import PyTextFileSourceOperator | ||
from pywayang.platforms.python.operators.PyTextFileSinkOperator import PyTextFileSinkOperator | ||
|
||
__ALL__ = [ | ||
PythonExecutionOperator, | ||
PyFilterOperator, | ||
PyTextFileSourceOperator | ||
PyTextFileSourceOperator, | ||
PyTextFileSinkOperator | ||
] |