文章内容是 【Nebula】单机部署的两种方式:Docker compose和rpm安装,以及web方面页面 的后续,对于部署方面可以进行参考上一篇,本文只说图形化界面的简单使用以及多跳查询参数化单元测试demo,数据的导入可以参考 使用图数据库 Nebula Graph 数据导入快速体验知识图谱 OwnThink
前言
我部署的测试服务器是 腾讯云轻量级服务器 2核4G8M,如果你已经完成了上述的数据导入工作,那么现在的nebula中应该有一个test space,一个tag : entity,一个 edge : relation。
导入上述数据可能偏多,导入的时候可以终止导入,看自己情况,我是导入了大概2500w左右的数据,但是很多数据都是只有出度或者只有入度,查询时最好选择双向,还有条数限制最好不要超过10,如果页面出现502 bad gate way ,可能就是nebula崩掉了
三种访问Nebula的方式
图探索可视化
开始探索 ——> 2112156115398865856 ——> 点击红色圆圈 ——>方向选择双向——>单步1 ——> 结果限制 10以下(太多可能会崩) ——> 拓展
这种可以帮助查看一些点的VID
控制台
GO FROM "-1732611724496872146" OVER relation YIELD relation.name AS Name, $$.entity.name AS Value;
有些可能结果为空,需要指定方向
java客户端
引入依赖
<dependency>
<groupId>com.vesoft</groupId>
<artifactId>client</artifactId>
<version>2.6.1</version>
</dependency>
直接运行下方单元测试:
/**
* @auther jiefei
* @date 2022/2/20
*/
@RunWith(Parameterized.class)
public class NebulaTest {
private NebulaPool pool;
private Session session;
private String nGQL;
public NebulaTest(String nGQL) {
this.nGQL = nGQL;
}
@Before
public void init() {
try{
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(5);
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669));
pool = new NebulaPool();
boolean init = pool.init(addresses, nebulaPoolConfig);
if (!init) {
System.err.println("初始化失败");
System.exit(1);
}
session = pool.getSession("user", "password", false);
session.execute("USE test;");
}catch (Exception e){
e.printStackTrace();
}
}
@After
public void close() {
session.release();
pool.close();
}
@Parameterized.Parameters
public static Collection<Object> data() {
return Arrays.asList(new Object[] {
"GO 1 TO 2 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 3 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 4 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 5 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 6 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 7 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 8 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 9 STEPS FROM '-1732611724496872146' OVER relation;",
"GO 1 TO 10 STEPS FROM '-1732611724496872146' OVER relation;"
});
}
@Test
public void nebulaTset() throws Exception{
Long start = System.currentTimeMillis();
ResultSet result = session.execute(nGQL);
Long end = System.currentTimeMillis();
System.out.println(nGQL);
if (result.isSucceeded()) {
System.out.println("行数: " + result.getRows().size() + ", 耗时 : " + (end - start) + " ms");
}else {
System.err.println("查询失败");
}
}
}
上方的单元测试展示了2-10跳的一个时间,默认查询为正向,如果是双向会非常非常慢,要好几秒。
GO 1 TO 2 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 102, 耗时 : 57 ms
GO 1 TO 3 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 264, 耗时 : 55 ms
GO 1 TO 4 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 561, 耗时 : 98 ms
GO 1 TO 5 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 973, 耗时 : 84 ms
GO 1 TO 6 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 1468, 耗时 : 98 ms
GO 1 TO 7 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 2095, 耗时 : 136 ms
GO 1 TO 8 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 2844, 耗时 : 197 ms
GO 1 TO 9 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 3702, 耗时 : 191 ms
GO 1 TO 10 STEPS FROM '-1732611724496872146' OVER relation;, 行数: 4662, 耗时 : 246 ms
更多语法参考:https://docs.nebula-graph.com.cn/3.0.0/3.ngql-guide/7.general-query-statements/3.go/