gpt4 book ai didi

groovy - "Supernodes"在泰坦

转载 作者:行者123 更新时间:2023-12-04 17:52:55 27 4
gpt4 key购买 nike

我正在开发一个可以很好地与图形数据库( Titan )配合使用的应用程序,但它在处理具有许多边的顶点时遇到问题,即 supernodes .

上面的 super 节点链接指向 Titan 作者的一篇博客文章,解释了解决问题的方法。解决方案似乎是通过对边进行过滤来减少顶点的数量。

不幸的是我想groupCount边或顶点的属性。例如我有 100 万用户,每个用户都属于一个国家。我怎样才能做一个快速的groupCount计算出每个国家的用户数量?

到目前为止,我尝试过的内容可以在这个精心制作的 groovy 脚本中显示:

g = TitanFactory.open('titan.properties')  // Cassandra
r = new Random(100)
people = 1e6

def newKey(g, name, type) {
return g
.makeType()
.name(name)
.simple()
.functional()
.indexed()
.dataType(type)
.makePropertyKey()
}

def newLabel(g, name, key) {
return g
.makeType()
.name(name)
.primaryKey(key)
.makeEdgeLabel()
}

country = newKey(g, 'country', String.class)
newLabel(g, 'lives', country)

g.stopTransaction(SUCCESS)

root = g.addVertex()
countries = ['AU', 'US', 'CN', 'NZ', 'UK', 'PL', 'RU', 'NL', 'FR', 'SP', 'IT']

(1..people).each {
country = countries[(r.nextFloat() * countries.size()).toInteger()]
g.startTransaction()
person = g.addVertex([name: 'John the #' + it])
g.addEdge(g.getVertex(root.id), person, 'lives', [country: country])
g.stopTransaction(SUCCESS)
}

t0 = new Date().time

m = [:]
root = g.getVertex(root.id)
root.outE('lives').country.groupCount(m).iterate()

t1 = new Date().time

println "groupCount seconds: " + ((t1 - t0) / 1000)

基本上是一个根节点(为了 Titan 没有“所有”节点查找),链接到许多 person通过具有 country 的边属性(property)。当我在 100 万个顶点上运行 groupCount() 时,它需要一分钟多的时间。

我意识到 Titan 可能会遍历每条边并收集计数,但是有没有办法让它在 Titan 或任何其他图形数据库中运行得更快?可以对索引本身进行计数,以便不必遍历吗?我的索引正确吗?

最佳答案

如果您将“国家”设为 primary key 'lives' 标签,然后您可以更快地检索特定国家/地区的所有人。但是,在您的情况下,您对组计数感兴趣,该计数需要检索该根节点的所有边,以便对它们进行迭代并将国家/地区分桶。

因此,这个分析查询更适合图分析框架 Faunus .它不需要根顶点,因为它通过完整的数据库扫描来执行 groupcount,从而避免了 super 节点问题。 Faunus 还使用 Gremlin 作为查询语言,因此您只需稍微修改您的查询:

g.V.country.groupCount.cap...

哈,
马蒂亚斯

关于groovy - "Supernodes"在泰坦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133339/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com