Azure cosmosdb 关于Gremlin的动态内子句

Azure cosmosdb 关于Gremlin的动态内子句,azure-cosmosdb,gremlin,Azure Cosmosdb,Gremlin,我正在Azure Cosmo DB上使用Gremlin,而且对它来说是相当陌生的 我将尝试使事情变得简单,我的图表是这样的: 我有两种类型的顶点:identies和infos。信息是在edge中“定义”身份的电子邮件和电话号码 例: 一个身份可以有无限多的电话号码或电子邮件。它可以有1封电子邮件和0个电话号码,反之亦然 我希望获得与其他给定身份验证共享至少一个值(电话号码或电子邮件)的所有身份验证顶点 我知道我可以选择数组中给定标识(id:1234)的所有值,如下所示: g.V().hasLab

我正在Azure Cosmo DB上使用Gremlin,而且对它来说是相当陌生的

我将尝试使事情变得简单,我的图表是这样的:

我有两种类型的顶点:
identies
infos
。信息是在edge中“定义”身份的电子邮件和电话号码

例:

一个身份可以有无限多的电话号码或电子邮件。它可以有1封电子邮件和0个电话号码,反之亦然

我希望获得与其他给定身份验证共享至少一个值(电话号码或电子邮件)的所有身份验证顶点

我知道我可以选择数组中给定标识(
id:1234
)的所有值,如下所示:
g.V().hasLabel('identity').hasId('1234').in('defines').values('value')

我知道我可以通过给定的电子邮件、电话列表选择所有标识顶点,如:

g.V('info')。有('value',在('123342356','test@email.com“)).out('defines')

但是,我没有做到以下几点:
g.V('info')。具有('value'),
在(g.V().hasLabel('identity').hasId('1234').in('defines').values('value'))中
.out('defines')

谢谢你的帮助


Axel

当询问有关Gremlin的问题时,最好包括一个创建一些示例数据的Gremlin脚本,因为它提供了大量的上下文,并允许您获得经过充分测试和工作的遍历版本-如下所示:

g.addV('identity').property('name','ident1').as('1').
  addV('identity').property('name','ident2').as('2').
  addV('identity').property('name','ident3').as('3').
  addV('identity').property('name','ident4').as('4').
  addV('identity').property('name','ident5').as('5').
  addV('infos').property('info','321-333-1111').as('1111').
  addV('infos').property('info','321-333-2222').as('2222').
  addV('infos').property('info','321-333-3333').as('3333').
  addV('infos').property('info','321-333-4444').as('4444').
  addV('infos').property('info','321-333-1144').as('1144').
  addV('infos').property('info','321-333-5555').as('5555').
  addV('infos').property('info','1@here.com').as('1@').
  addV('infos').property('info','2@here.com').as('2@').
  addV('infos').property('info','3@here.com').as('3@').
  addV('infos').property('info','4@here.com').as('4@').
  addV('infos').property('info','35@here.com').as('35@').
  addE('defines').from('1111').to('1').
  addE('defines').from('2222').to('2').
  addE('defines').from('3333').to('3').
  addE('defines').from('4444').to('4').
  addE('defines').from('1144').to('1').
  addE('defines').from('1144').to('4').
  addE('defines').from('5555').to('5').
  addE('defines').from('1@').to('1').
  addE('defines').from('2@').to('2').
  addE('defines').from('3@').to('3').
  addE('defines').from('4@').to('4').
  addE('defines').from('35@').to('3').
  addE('defines').from('35@').to('5').iterate()
因此,我从您的问题中得出结论,您知道要开始的“身份”,以及它定义的“信息”:

gremlin> g.V().has('identity','name','ident4').in('defines').values('info')
==>321-333-4444
==>321-333-1144
==>4@here.com
如果我们想知道还有谁会分享这一点,我们只需沿着这些“定义”边往回走:

您得到4个结果,因为有4条边被遍历-在示例数据中计算它们。复制不是很好,所以:

gremlin> g.V().has('identity','name','ident4').
......1>   in('defines').
......2>   out('defines').
......3>   dedup().
......4>   values('name')
==>ident4
==>ident1
通常,
dedup()
不是最好的方法。在遍历过程中消除重复可能更好,在您的情况下,这可能更好,因为您已经知道“开始标识”及其存在。我推测你想要的是你不知道的其他“身份”顶点

gremlin> g.V().has('identity','name','ident4').as('exists').
......1>   in('defines').
......2>   out('defines').
......3>   where(neq('exists')).
......4>   values('name')
==>ident1
请注意,当“标识”不共享“信息”时,我们不会得到任何结果:

如果您希望查看匹配的数据及其匹配的“标识”,请执行以下操作:

gremlin> g.V().has('identity','name','ident3').as('exists').
......1>   in('defines').as('shared').
......2>   out('defines').as('matched').
......3>   where(neq('exists')).
......4>   select('matched','shared').
......5>     by('name').
......6>     by('info')
==>[matched:ident5,shared:35@here.com]

当询问有关Gremlin的问题时,最好包括一个创建一些示例数据的Gremlin脚本,因为它提供了大量的上下文,并允许您获得经过充分测试和工作的遍历版本,如下所示:

g.addV('identity').property('name','ident1').as('1').
  addV('identity').property('name','ident2').as('2').
  addV('identity').property('name','ident3').as('3').
  addV('identity').property('name','ident4').as('4').
  addV('identity').property('name','ident5').as('5').
  addV('infos').property('info','321-333-1111').as('1111').
  addV('infos').property('info','321-333-2222').as('2222').
  addV('infos').property('info','321-333-3333').as('3333').
  addV('infos').property('info','321-333-4444').as('4444').
  addV('infos').property('info','321-333-1144').as('1144').
  addV('infos').property('info','321-333-5555').as('5555').
  addV('infos').property('info','1@here.com').as('1@').
  addV('infos').property('info','2@here.com').as('2@').
  addV('infos').property('info','3@here.com').as('3@').
  addV('infos').property('info','4@here.com').as('4@').
  addV('infos').property('info','35@here.com').as('35@').
  addE('defines').from('1111').to('1').
  addE('defines').from('2222').to('2').
  addE('defines').from('3333').to('3').
  addE('defines').from('4444').to('4').
  addE('defines').from('1144').to('1').
  addE('defines').from('1144').to('4').
  addE('defines').from('5555').to('5').
  addE('defines').from('1@').to('1').
  addE('defines').from('2@').to('2').
  addE('defines').from('3@').to('3').
  addE('defines').from('4@').to('4').
  addE('defines').from('35@').to('3').
  addE('defines').from('35@').to('5').iterate()
因此,我从您的问题中得出结论,您知道要开始的“身份”,以及它定义的“信息”:

gremlin> g.V().has('identity','name','ident4').in('defines').values('info')
==>321-333-4444
==>321-333-1144
==>4@here.com
如果我们想知道还有谁会分享这一点,我们只需沿着这些“定义”边往回走:

您得到4个结果,因为有4条边被遍历-在示例数据中计算它们。复制不是很好,所以:

gremlin> g.V().has('identity','name','ident4').
......1>   in('defines').
......2>   out('defines').
......3>   dedup().
......4>   values('name')
==>ident4
==>ident1
通常,
dedup()
不是最好的方法。在遍历过程中消除重复可能更好,在您的情况下,这可能更好,因为您已经知道“开始标识”及其存在。我推测你想要的是你不知道的其他“身份”顶点

gremlin> g.V().has('identity','name','ident4').as('exists').
......1>   in('defines').
......2>   out('defines').
......3>   where(neq('exists')).
......4>   values('name')
==>ident1
请注意,当“标识”不共享“信息”时,我们不会得到任何结果:

如果您希望查看匹配的数据及其匹配的“标识”,请执行以下操作:

gremlin> g.V().has('identity','name','ident3').as('exists').
......1>   in('defines').as('shared').
......2>   out('defines').as('matched').
......3>   where(neq('exists')).
......4>   select('matched','shared').
......5>     by('name').
......6>     by('info')
==>[matched:ident5,shared:35@here.com]

嗨,斯蒂芬,谢谢你的回答!这很有帮助,并指出我可能没有以最有效的方式构建图表。事实上,我计划复制«infos»模式,以便它们始终只连接到单个标识节点。这就是为什么我希望比较这些值,而不是遍历图表。出于好奇,有没有一种方法可以像我尝试的那样比较价值观?谢谢这不是一个很好的图形查询。也许有一种方法可以将所有内容都编写为一次遍历,但为了可读性,我只需执行两次单独的遍历:第一次遍历将“infos”存储在列表中,然后在第二次遍历中将该列表传递给
in()
。这很有意义。谢谢StephenHi Stephen,谢谢你的回答!这很有帮助,并指出我可能没有以最有效的方式构建图表。事实上,我计划复制«infos»模式,以便它们始终只连接到单个标识节点。这就是为什么我希望比较这些值,而不是遍历图表。出于好奇,有没有一种方法可以像我尝试的那样比较价值观?谢谢这不是一个很好的图形查询。也许有一种方法可以将所有内容都编写为一次遍历,但为了可读性,我只需执行两次单独的遍历:第一次遍历将“infos”存储在列表中,然后在第二次遍历中将该列表传递给
in()
。这很有意义。谢谢斯蒂芬