-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增:新增frame插件,用于从内存读取frame数据,写入flow通道
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"flow": { | ||
"name": "", | ||
"uid": "", | ||
"param": { | ||
} | ||
}, | ||
"nodes": [ | ||
{ | ||
"id": "FakerInput", | ||
"name": "faker", | ||
"type": "input", | ||
"properties": { | ||
"rows":10, | ||
"columns": ["name","address","city","street_address","date_of_birth","phone_number"], | ||
"randoms":[ | ||
{"key":"sex","values":["男:1","女:2","未知:3"]} | ||
] | ||
} | ||
} | ||
], | ||
"edges": [ | ||
|
||
] | ||
} |
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,32 @@ | ||
{ | ||
"flow": { | ||
"name": "", | ||
"uid": "", | ||
"param": { | ||
} | ||
}, | ||
"nodes": [ | ||
{ | ||
"id": "FrameInput", | ||
"name": "frame", | ||
"type": "input", | ||
"properties": { | ||
"frame_name":"frame_input" | ||
} | ||
}, | ||
{ | ||
"id": "Console", | ||
"name": "out", | ||
"type": "translate", | ||
"properties": { | ||
"row": 100 | ||
} | ||
} | ||
], | ||
"edges": [ | ||
{ | ||
"startId": "frame", | ||
"endId": "out" | ||
} | ||
] | ||
} |
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,24 @@ | ||
import unittest | ||
|
||
from NiceFlow.core.flow import Flow | ||
from NiceFlow.core.manager import FlowManager | ||
|
||
|
||
class TestFrameInput(unittest.TestCase): | ||
|
||
def test_frame_input(self): | ||
path = "faker_input.json" | ||
myFlow: Flow = FlowManager.read(path) | ||
myFlow.run() | ||
result_dict = myFlow.get_result() | ||
duck_df = list(result_dict.values())[0] | ||
|
||
|
||
path = "frame_input.json" | ||
myFlow2: Flow = FlowManager.read(path) | ||
myFlow2.set_result("frame_input",duck_df) | ||
myFlow2.run() | ||
|
||
myFlow3: Flow = FlowManager.read(path) | ||
myFlow3.set_result("frame_input",duck_df) | ||
myFlow3.run() |
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,23 @@ | ||
import json | ||
|
||
import duckdb | ||
from NiceFlow.core.flow import Flow | ||
from NiceFlow.core.plugin import IPlugin | ||
|
||
|
||
# 从内存dataframe读取数据 | ||
class FrameInput(IPlugin): | ||
|
||
def init(self, param: json, flow: Flow): | ||
super(FrameInput, self).init(param, flow) | ||
|
||
def execute(self): | ||
super(FrameInput, self).execute() | ||
frame_name = self.param["frame_name"] | ||
|
||
# 写入结果 | ||
frame:duckdb.DuckDBPyRelation = self.flow.get_result()[frame_name] | ||
self.set_result(frame) | ||
|
||
def to_json(self): | ||
super(FrameInput, self).to_json() |