SemanticError: Only one variable allowed to use.

"$domain = GO 1 STEPS " \
                  "FROM '159.138.142.152' OVER * REVERSELY " \
                  "WHERE properties($$).name IS NOT EMPTY and labels($$)[0] == 'domain' " \
                  "YIELD id($$) AS url;" \
                  "$data = GO 2 STEPS FROM $domain.url OVER * " \
                  "WHERE properties($$).name IS NOT EMPTY and labels($$)[0] IN ['victim_card', 'victim_phone', 'victim_bank', 'victim_address', 'browser_id'] " \
                  "YIELD properties($$).name as victim_data, $$.browser_id.name as suspect_data; " \
                  "YIELD $domain.url as url, count($data.suspect_data) as suspect_numbers, count(*)-count($data.suspect_data) as victim_numbers;"

为啥不支持两个变量的值返回。

需求是,通过A查询到B, 然后通过B去统计C,最后返回结果,结果要包含B不等于0,C=0的情况

你可以认为 nebula 的变量是一个 Table,用来接收语句的输出。
不支持多个变量的原因是:当行数不一致时,语句语义会变得很复杂,比如需要做笛卡尔积等等。
等价写法:

"$domain = GO 1 STEPS " \
                  "FROM '159.138.142.152' OVER * REVERSELY " \
                  "WHERE properties($$).name IS NOT EMPTY and labels($$)[0] == 'domain' " \
                  "YIELD id($$) AS url;" \
                  "$data = GO 2 STEPS FROM $domain.url OVER * " \
                  "WHERE properties($$).name IS NOT EMPTY and labels($$)[0] IN ['victim_card', 'victim_phone', 'victim_bank', 'victim_address', 'browser_id'] " \
                  "YIELD $domain.url as url, properties($$).name as victim_data, $$.browser_id.name as suspect_data; " \
                  "YIELD $data.url as url, count($data.suspect_data) as suspect_numbers, count(*)-count($data.suspect_data) as victim_numbers;"

Cypher 语法或许可以更自然的表达你的需求

MATCH (a)<--(b:domain)-[*2]->(c) where id(a)=='159.138.142.152' 
WITH a,b,c where labels(c)[0] in ['victim_card', 'victim_phone', 'victim_bank', 'victim_address', 'browser_id']
RETURN id(b), count(*)-count(CASE WHEN labels(c)[0]=='browser_id' THEN true ELSE null END) AS victim_numbers
2 个赞

谢谢哈,但是你这样写不支持现在的语法,我前面试过
SemanticError: `count($$.browser_id.name) AS suspect_numbers’ is not support in go sentence.

上面的写法可以吗?

不行的,就是报错:SemanticError: `count($$.browser_id.name) AS suspect_numbers’ is not support in go sentence.

你重新复制一下,刚才写错了。
这是我本地类似语句的测试:

(root@nebula) [nba]> """
                  -> $var1 = go from "Tim Duncan" over * REVERSELY YIELD id($$) AS url;
                  -> $var2 = go 2 steps from $var1.url over * YIELD $var1.url AS url,properties($$).name AS x,$$.player.name AS y;
                  -> YIELD $var2.url,count($var2.y),count(*)-count($var2.y)
                  -> """
+---------------------+----------------+---------------------------+
| $var2.url           | count($var2.y) | (count(*)-count($var2.y)) |
+---------------------+----------------+---------------------------+
| "Aron Baynes"       | 6              | 1                         |
| "Manu Ginobili"     | 26             | 6                         |
| "Boris Diaw"        | 13             | 3                         |
| "LaMarcus Aldridge" | 13             | 3                         |
| "Shaquile O'Neal"   | 6              | 6                         |
| "Danny Green"       | 10             | 15                        |
| "Dejounte Murray"   | 29             | 31                        |
| "Marco Belinelli"   | 16             | 6                         |
| "Tony Parker"       | 22             | 12                        |
| "Tiago Splitter"    | 9              | 2                         |
+---------------------+----------------+---------------------------+



我想要的结果是,当url存在的时候,count为0的时候,显示url,0, 0

我最开始用管道符来实现的时候,就是现在这个结果,所以改的变量来实现。
现在是实现不了,url, 0, 0 的情况,后面的统计为0,就所有是空的

没太懂你说的 count 为 0,是哪个 count?

分开两个数据都有,合到一起就是全是空

“B 不等于 0,C 等于 0” 是啥?
B 的 count 不等于 0,C 的 count 等于 0 ?

A = ip
B = domain
C、D 是 B对应的统计信息

现在的结果是,通过A 能查到B ,通过B 能统计到C、D,
返回结果是,B,C,D
但是当C,D为0的时候,返回的B,C,D就是空值,就是上面图片的结果

这个是说 C 或 D 携带的属性为 0?你上面的语句也没有判断 为不为0 啊

你期待的是不为空值?

对,就是不为空值,是0就显示0

结果就是需要把上面两张图的结果结合起来

但是现在的写法结合起来,返回的是下面这张图

需要的不是空值,url为对应的值,其他俩为0

把聚合函数去掉测一下。
YIELD $domain.url as url 有值吗


这样?

@kyle
你可以在https://playground.nebula-graph.com.cn/console 上试试

GO FROM "player101" OVER follow REVERSELY 
YIELD src(edge) AS id | 
GO FROM $-.id OVER serve 
WHERE properties($$).name IS NOT EMPTY and properties($$).name in ['Raptors', 'Spurs']
YIELD properties($^).name AS FriendOf | YIELD $-.FriendOf as name, count(*) AS Team;

有5个朋友,但是没有一个朋友在这[‘Raptors’, ‘Spurs’] team,所以结果应该显示0 而不是空白
image


最后一行 YIELD 去掉

所以原因是第二条语句结果已经是空了