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: phase 2 of networkx/nebula engine, writer implementation #31

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

wey-gu
Copy link
Owner

@wey-gu wey-gu commented Mar 27, 2023

partially-implement: #28

example:

from ng_ai import NebulaReader
from ng_ai.config import NebulaGraphConfig

# read data with nebula/networkx engine, query mode
config_dict = {
    "graphd_hosts": "127.0.0.1:29669",
    "user": "root",
    "password": "nebula",
    "space": "basketballplayer",
}
config = NebulaGraphConfig(**config_dict)
reader = NebulaReader(engine="nebula", config=config)
reader.query(edges=["follow", "serve"], props=[["degree"], []])
g = reader.read()
g.show(10)

graph_result = g.algo.pagerank()
from ng_ai import NebulaWriter

writer = NebulaWriter(
    graph=g,
    data=graph_result,
    sink="nebulagraph_vertex",
    config=config,
    engine="nebula",
)
# properties to write
properties = ["pagerank"]

writer.set_options(
    tag="pagerank",
    properties=properties,
    batch_size=256,
    write_mode="insert",
)
# write back to NebulaGraph
writer.write()

result:

(root@nebula) [basketballplayer]> """
                               -> MATCH (v:pagerank)
                               -> RETURN id(v), properties(v).name, v.pagerank.pagerank LIMIT 10;
                               -> """
+-------------+----------------------+----------------------+
| id(v)       | properties(v).name   | v.pagerank.pagerank  |
+-------------+----------------------+----------------------+
| "player114" | "Tracy McGrady"      | 0.011051906163893978 |
| "player150" | "Luka Doncic"        | 0.009516492295110288 |
| "team204"   | "Spurs"              | 0.04903196906959808  |
| "team218"   | "Raptors"            | 0.01638628218960471  |
| "team229"   | "Heat"               | 0.017044530151108732 |
| "player105" | "Danny Green"        | 0.008024866580699643 |
| "player109" | "Tiago Splitter"     | 0.006968969577862604 |
| "player111" | "David West"         | 0.006968969577862604 |
| "player118" | "Russell Westbrook"  | 0.014443509420925593 |
| "player143" | "Kristaps Porzingis" | 0.008991253709274852 |
+-------------+----------------------+----------------------+
Got 10 rows (time spent 54748/71563 us)

Mon, 27 Mar 2023 14:39:10 CST

@wey-gu wey-gu merged commit 45b3208 into main Mar 27, 2023
@wey-gu wey-gu deleted the networkx branch March 27, 2023 06:42
@wey-gu wey-gu changed the title feat: phase 2 of networkx/nebula engine, writer implementation #30 feat: phase 2 of networkx/nebula engine, writer implementation Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant