插入点和边后边不显示

通过insert语句insert点和边,点的属性可显示,但是边不显示

部分代码如下:
解析json数据获取key和value,然后格式化插入图数据库,采用go语言

for _, tactics := range r.Tactics {
		tacticsId := tactics.Tactics_id
		tacticsEnglishName := tactics.English_name
		tacticsChineseName := tactics.Chinese_name

		stmtVertex := fmt.Sprintf("INSERT VERTEX tactic(tactics_id, english_name, chinese_name) VALUES uuid('%s'):('%s', '%s', '%s')", tacticsId, tacticsId, tacticsEnglishName, tacticsChineseName)
		//fmt.Print(stmtVertex)
		// insert vertices and edges
		check(pool.Execute(stmtVertex))
		for _, tech := range tactics.Tech_ids {
			techId := tech.Tech_id
			techEnglishName := tech.English_name
			techChineseName := tech.Chinese_name
			//fmt.Print(techId, techEnglishName, techChineseName)
			stmtVertex := fmt.Sprintf("INSERT VERTEX tech(tech_id, english_name, chinese_name) VALUES uuid('%s'):('%s', '%s', '%s')", techId, techId, techEnglishName, techChineseName)
			//fmt.Print(stmtVertex)
			// insert vertices and edges
			check(pool.Execute(stmtVertex))
			stmtEdge := fmt.Sprintf("INSERT EDGE includes() VALUES uuid('%s') -> uuid('%s'):()", tacticsId, techId)
1 个赞

如果edge是没有属性,是一个空的edge,目前不指定yield值的话,返回的会是一个空列表,所以这里你需要指定一下,然后这个问题可以提一个issue给我们来修正:handshake:

发现另外一个问题,有的数据没插入进去,不知道为啥,过程中也没报错,用的go客户端,没报错也不知道啥原因

具体插入的是什么数据,要给出最小复现步骤,不然没法排查了,谢谢:handshake:

采用pool方式,

check(pool.Execute("CREATE SPACE IF NOT EXISTS attack(partition_num=5, replica_factor=1)"))
	check(pool.Execute("USE attack"))
	// create schema
	check(pool.Execute("CREATE TAG IF NOT EXISTS tactic(tactics_id string, english_name string, chinese_name string)"))
	check(pool.Execute("CREATE TAG IF NOT EXISTS tech(tech_id string, english_name string, chinese_name string)"))
	check(pool.Execute("CREATE TAG IF NOT EXISTS sub_tech(sub_tech_id string, english_name string, chinese_name string, english_desc string, chinese_desc string, Mitigation_english_desc string, Mitigation_chinese_desc string, Detection_english_desc string, Detection_chinese_desc string)"))
	check(pool.Execute("CREATE TAG IF NOT EXISTS case(case_id string, OS string, privilege string, english_desc string, chinese_desc string)"))
	check(pool.Execute("CREATE TAG IF NOT EXISTS command(cmd_id string, cmd_line string, english_desc string, chinese_desc string, cmd_level string, cmd_score double, cmd_regex string)"))
	check(pool.Execute("CREATE TAG IF NOT EXISTS rule(rule_id string, rule_type string, level string, rule_chinese_desc string, rule_regex string)"))
	check(pool.Execute("CREATE EDGE IF NOT EXISTS includes()"))
	check(pool.Execute("CREATE EDGE IF NOT EXISTS subs()"))
	check(pool.Execute("CREATE EDGE IF NOT EXISTS cases()"))
	check(pool.Execute("CREATE EDGE IF NOT EXISTS commands()"))
	check(pool.Execute("CREATE EDGE IF NOT EXISTS rules()"))

这个代码出了创建space成功外,其余的创建tag和边就没有成功,错误日志就是tag不存在,没办法先手动在UI界面里面执行语句。
此外,插入数据的时候没报错,但是有的数据查询没有数据。

代码如下:

for _, tactics := range r.Tactics {
		tacticsId := tactics.Tactics_id
		tacticsEnglishName := tactics.English_name
		tacticsChineseName := tactics.Chinese_name

		stmtVertex := fmt.Sprintf("INSERT VERTEX tactic(tactics_id, english_name, chinese_name) VALUES uuid('%s'):('%s', '%s', '%s')", tacticsId, tacticsId, tacticsEnglishName, tacticsChineseName)
		//fmt.Print(stmtVertex)
		// insert vertices and edges
		check(pool.Execute(stmtVertex))
		for _, tech := range tactics.Tech_ids {
			techId := tech.Tech_id
			techEnglishName := tech.English_name
			techChineseName := tech.Chinese_name
			//fmt.Print(techId, techEnglishName, techChineseName)
			stmtVertex := fmt.Sprintf("INSERT VERTEX tech(tech_id, english_name, chinese_name) VALUES uuid('%s'):('%s', '%s', '%s')", techId, techId, techEnglishName, techChineseName)
			fmt.Print(stmtVertex)
			// insert vertices and edges
			check(pool.Execute(stmtVertex))
			stmtEdge := fmt.Sprintf("INSERT EDGE includes() VALUES uuid('%s') -> uuid('%s'):()", tacticsId, techId)
			//fmt.Print(stmtEdge)
			check(pool.Execute(stmtEdge))

数据为json类型的数据,都解析完毕,插入的语句打印出来也都正确。

创建space和创建tag之间有一个时间差,不是同步的,需要等待大约两个心跳时间,同理,如果执行创建tag/edge,也需要等待两个心跳时间才能插入,总之建模和插入数据不同同时进行,需要等待ready后才能进行,这里你如果用程序执行的话,要么控制下执行时间,要么用catch做下ready的尝试。

那个我都试了,12秒,24秒,甚至1分钟都等了,那个先不管也行,我手动执行语句也可以做,但是插入数据有的没插入上就很难搞了,看不到错误。

插入的时候客户端没有报错么?

没报错,我以为都插入成功了,所以去查了部分数据,结果有的数据查询结果为空

你可以单独用go client调用那条对应没插入成功的语句看看,把执行结果打出来

服务端是单机部署吗,看看服务端的日志。

单机部署的,docker启动的,是在这下面吗?nebula-docker-compose/logs/graph

INSERT VERTEX tech(tech_id, english_name, chinese_name) VALUES uuid(‘T1078’):(‘T1078’, ‘Valid Accounts’, ‘有效账户’)
这句话没插入成功,但是手动执行可以执行成功


字符串’'引号不对吧?

修正引号后,插入能成功,并且查询也成功,你自己再检查一下吧:

不是,这个是贴的问题,我手动执行可以成功

INSERT VERTEX tech(tech_id, english_name, chinese_name) VALUES uuid(‘T1078’):(‘T1078’, ‘Valid Accounts’, ‘有效账户’)

不知道为啥贴完就单引号就变了

原因已找到,具体原因
connpool.SpaceDesc{
Name: “attack”,
Exists: false,
NumPartitions: 10,
ReplicaFactor: 1,
Charset: “utf8”,
Collate: “utf8_bin”,
},
name指定错误,虽然在语句里面指定了使用正确的db, check(pool.Execute(“USE attack”)), 但是还会导致一些数据无法插入。 如果name指定正确,就能正确插入。

2 个赞