Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ngdi UDF gateway #20

Merged
merged 3 commits into from
Mar 17, 2023
Merged

feat: ngdi UDF gateway #20

merged 3 commits into from
Mar 17, 2023

Conversation

@wey-gu wey-gu added the wip label Mar 16, 2023
@wey-gu wey-gu changed the title WIP: feat: ngdi UDF gateway feat: ngdi UDF gateway Mar 16, 2023
@wey-gu
Copy link
Owner Author

wey-gu commented Mar 16, 2023

Run ngdi API gateway to handle call with HTTP

It's either a cURL call or a UDF query from ngdi-graphd.

  • Query from ngdi-graphd
-- Prepare the write schema
USE basketballplayer;
CREATE TAG IF NOT EXISTS pagerank(pagerank string);
:sleep 20;
-- Call with ngdi()
RETURN ngdi("pagerank", ["follow"], ["degree"], "spark", {space: "basketballplayer", max_iter: 10}, {write_mode: "insert"})

Where the parameters are:

  • algo_name: the name of the algorithm, e.g. pagerank

  • edge_types: the edge types to be used in the algorithm, e.g. ["follow"]

  • edge_weights: the edge weights to be used in the algorithm, e.g. ["degree"]

  • mode: the mode(engine) to be used in the algorithm, e.g. spark, networkx

  • algo_context: the context to be used in the algorithm, e.g. {space: "basketballplayer", max_iter: 10}

  • Call with cURL

curl -X POST \
     -H "Content-Type: application/json" \
     -d '{
          "write_context": {
              "write_mode": "insert"
          },
          "read_context": {
              "edge_types": ["follow"],
              "read_mode": "scan",
              "edge_weights": ["degree"]
          },
          "algo_context": {
              "name": "pagerank",
              "space": "basketballplayer"
          }
     }' \
     http://jupyter:9999/api/v0/spark/pagerank

result example

(root@nebula) [(none)]> 
(root@nebula) [(none)]> RETURN ngdi("pagerank", ["follow"], ["degree"], "spark", {space: "basketballplayer", max_iter: 10}, {write_mode: "insert"})
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ngdi("pagerank",["follow"],["degree"],"spark",{space:"basketballplayer",max_iter:10},{write_mode:"insert"})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {body: "{"write_context":{"write_mode":"insert"},"read_context":{"edge_types":["follow"],"edge_weights":["degree"],"read_mode":"scan"},"algo_context":{"max_iter":10,"name":"pagerank","space":"basketballplayer"}}", debug: "curl -X POST -H "Content-Type: application/json" -d '{"write_context":{"write_mode":"insert"},"read_context":{"edge_types":["follow"],"edge_weights":["degree"],"read_mode":"scan"},"algo_context":{"max_iter":10,"name":"pagerank","space":"basketballplayer"}}' http://jupyter:9999/api/v0/spark/pagerank", response: "{"algo_result_stats":[{"_id":"44","pagerank":"44","summary":"count"},{"_id":null,"pagerank":"1.0","summary":"mean"},{"_id":null,"pagerank":"1.2523434472897175","summary":"stddev"},{"_id":"player100","pagerank":"0.18601069183310506","summary":"min"},{"_id":null,"pagerank":"0.20038424529293591","summary":"25%"},{"_id":null,"pagerank":"0.45392364809815694","summary":"50%"},{"_id":null,"pagerank":"1.0722447015912286","summary":"75%"},{"_id":"player150","pagerank":"5.48893951524718","summary":"max"}],"reader_result_stats":[{"_dstId":"81","_rank":"81","_srcId":"81","degree":"81","summary":"count"},{"_dstId":null,"_rank":"0.0","_srcId":null,"degree":"82.44444444444444","summary":"mean"},{"_dstId":null,"_rank":"0.0","_srcId":null,"degree":"22.10316719386613","summary":"stddev"},{"_dstId":"player100","_rank":"0","_srcId":"player100","degree":"-1","summary":"min"},{"_dstId":null,"_rank":"0","_srcId":null,"degree":"80","summary":"25%"},{"_dstId":null,"_rank":"0","_srcId":null,"degree":"90","summary":"50%"},{"_dstId":null,"_rank":"0","_srcId":null,"degree":"90","summary":"75%"},{"_dstId":"player150","_rank":"0","_srcId":"player150","degree":"100","summary":"max"}],"writer_result":true} |
| ", url: "http://jupyter:9999/api/v0/spark/pagerank"}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Got 1 rows (time spent 2302135/2302735 us)

Thu, 16 Mar 2023 20:41:28 CST

poc passed, now implemented in lib
@wey-gu wey-gu merged commit a08c655 into main Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant