Skip to content

Commit

Permalink
新增:新增frame插件,用于从内存读取frame数据,写入flow通道
Browse files Browse the repository at this point in the history
  • Loading branch information
BleethNie committed Jun 6, 2024
1 parent e02f9cb commit 9ae5a32
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
25 changes: 25 additions & 0 deletions samples/frame_input/faker_input.json
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": [

]
}
32 changes: 32 additions & 0 deletions samples/frame_input/frame_input.json
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"
}
]
}
24 changes: 24 additions & 0 deletions samples/frame_input/frame_input_test.py
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()
23 changes: 23 additions & 0 deletions src/NiceFlow/plugins/frame_input.py
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()

0 comments on commit 9ae5a32

Please sign in to comment.