概述
Schema总览算法通过统计起、终点schema信息、其间的边schema信息及相应边数,实现对图结构的整体展示。
示例图

在一个空图中运行以下语句定义图结构并插入数据:
ALTER GRAPH CURRENT_GRAPH ADD NODE {
account (),
movie (),
country (),
director ()
};
ALTER GRAPH CURRENT_GRAPH ADD EDGE {
follow ()-[]->(),
like ()-[]->(),
filmedIn ()-[]->(),
direct ()-[]->()
};
INSERT (David:account {_id: "David"}),
(Emily:account {_id: "Emily"}),
(Alice:account {_id: "Alice"}),
(Titanic:movie {_id: "Titanic"}),
(Avatar:movie {_id: "Avatar"}),
(Mexico:country {_id: "Mexico"}),
(JC:director {_id: "James Cameron"}),
(David)-[:follow]->(Alice),
(Emily)-[:follow]->(Alice),
(Alice)-[:like]->(Titanic),
(Titanic)-[:filmedIn]->(Mexico),
(JC)-[:direct]->(Titanic),
(JC)-[:direct]->(Avatar);
create().node_schema("account").node_schema("movie").node_schema("country").node_schema("director").edge_schema("follow").edge_schema("like").edge_schema("filmedIn").edge_schema("direct");
insert().into(@account).nodes([{_id:"David"}, {_id:"Emily"}, {_id:"Alice"}]);
insert().into(@movie).nodes([{_id:"Titanic"}, {_id:"Avatar"}]);
insert().into(@country).nodes({_id:"Mexico"});
insert().into(@director).nodes({_id:"James Cameron"});
insert().into(@follow).edges([{_from:"David", _to:"Alice"}, {_from:"Emily", _to:"Alice"}]);
insert().into(@like).edges({_from:"Alice", _to:"Titanic"});
insert().into(@filmedIn).edges({_from:"Titanic", _to: "Mexico"});
insert().into(@direct).edges([{_from:"James Cameron", _to:"Titanic"}, {_from:"James Cameron", _to:"Avatar"}]);
创建HDC图
将当前图集全部加载到HDC服务器hdc-server-1
上,并命名为 my_hdc_graph
:
CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static"
}
hdc.graph.create("my_hdc_graph", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static"
}).to("hdc-server-1")
参数
算法名:schema_overview
参数名 |
类型 |
规范 |
默认值 |
可选 |
描述 |
---|---|---|---|---|---|
order |
String | asc , desc |
/ | 是 | 根据count 值对结果排序 |
完整返回
CALL algo.schema_overview.run("my_hdc_graph", {}) YIELD r
RETURN r
exec{
algo(schema_overview).params() as r
return r
} on my_hdc_graph
结果:
node schema(src) |
edge schema |
node schema(dest) |
count |
---|---|---|---|
account | follow | account | 2 |
account | like | movie | 1 |
movie | filmedIn | country | 1 |
director | direct | movie | 2 |
流式返回
CALL algo.schema_overview.stream("my_hdc_graph", {}) YIELD r
FILTER r.`node schema(src)` = "account"
RETURN r
exec{
algo(schema_overview).params().stream() as r
where r.`node schema(src)` == "account"
return r
} on my_hdc_graph
结果:
node schema(src) |
edge schema |
node schema(dest) |
count |
---|---|---|---|
account | follow | account | 2 |
account | like | movie | 1 |