小编Kel*_*nce的帖子

查找与其他人购买相同游戏的人

我正在使用 Amazon Neptune 创建和查询一个简单的图形数据库。我目前正在 AWS Jupyter Notebook 中运行我的代码,但最终会将代码移至 Python (gremlin_python)。正如您可能猜到的那样,我对 Gremlin 和一般图形数据库很陌生。

我有以下数据

g.addV('person').property(id, 'john')
 .addV('person').property(id, 'jim')
 .addV('person').property(id, 'pam')
 .addV('game').property(id, 'G1')
 .addV('game').property(id, 'G2')
 .addV('game').property(id, 'G3').iterate() 

g.V('john').as('p').V('G1').addE('bought').from('p').iterate()
g.V('john').as('p').V('G2').addE('bought').from('p').iterate()
g.V('john').as('p').V('G3').addE('bought').from('p').iterate()

g.V('jim').as('p').V('G1').addE('bought').from('p').iterate()
g.V('jim').as('p').V('G2').addE('bought').from('p').iterate()

g.V('pam').as('p').V('G1').addE('bought').from('p').iterate()
Run Code Online (Sandbox Code Playgroud)

数据库中有 3 个人和 3 个游戏。我的目标是,给定一个人,告诉我哪些人购买了与他们相同的游戏,哪些游戏是那些

查看示例代码(主要来自https://tinkerpop.apache.org/docs/current/recipes/#recommendation)后,我有以下代码尝试查找由以下用户购买的游戏

g.V('john').as('target')   Target person we are interested in comparing against
.out('bought').aggregate('target_games') // Games bought by target
.in('bought').where(P.neq('target')).dedup() // Persons who bought same games as target (excluding target and without duplicates)
.group().by().by(out("bought").where(P.within("target_games")).count()) // Find persons, group by number of co owned games
.unfold().order().by(values, …
Run Code Online (Sandbox Code Playgroud)

python-3.x gremlin amazon-neptune

7
推荐指数
1
解决办法
199
查看次数

如何在NeptuneDB中进行分页以实现高性能

您好,我现在正在使用 aws NeptuneDB(Gremlin)、NodeJs 作为后端、Angular 作为前端构建一个网站。现在我面临一个问题,我想在我的网站上进行分页,因为如果没有分页,我可能会在一次查询中加载并显示 5000 个项目。我知道在 MySQL 中,我们可以使用类似

select * from mydb limit 0, 20;
Run Code Online (Sandbox Code Playgroud)

进行分页。

我可以在 NeptuneDB(或 GraphDB)中实现类似的功能吗?我调查了一段时间,发现了这个: How to Perform pagination in Gremlin

参考这个问题的答案,看来我们无法避免将所有查询结果加载到内存中。这是否意味着有或没有分页没有任何区别。

或者我可以实现 Node 和 Angular 之间的分页(我只是猜测)?

那么有什么提高性能的想法吗?

pagination node.js gremlin angular amazon-neptune

6
推荐指数
1
解决办法
2087
查看次数

将 Gremlin 的字符串命令转换为可执行文件

我创建了一个长 Gremlin 链接命令作为字符串。在 NodeJS 或 Python 中执行它的最佳方法是什么?

g.addV("person").
  property(id, 1).
  property("name", "marko").
  property("age", 29).as("1").
  addV("person").
  property(id, 2).
  property("name", "vadas").
  property("age", 27).as("2").
  addV("software").
  property(id, 3).
  property("name", "lop").
  property("lang", "java").as("3").
  addV("person").
  property(id, 4).
  property("name", "josh").
  property("age", 32).as("4").
  addV("software").
  property(id, 5).
  property("name", "ripple").
  property("lang", "java").as("5").
  addV("person").
  property(id, 6).
  property("name", "peter").
  property("age", 35).as("6").
  addE("created").from("1").to("3").
  property(id, 9).
  property("weight", 0.4).
  addE("knows").from("1").to("2").
  property(id, 7).
  property("weight", 0.5).
  addE("knows").from("1").to("4").
  property(id, 8).
  property("weight", 1.0).
  addE("created").from("3").to("4").
  property(id, 11).
  property("weight", 0.4).
  addE("created").from("3").to("6").
  property(id, 12).
  property("weight", 0.2).
  addE("created").from("4").to("5").
  property(id, 10).
  property("weight", 1.0)
Run Code Online (Sandbox Code Playgroud)

上面给出的命令在 …

node.js python-3.x gremlin tinkerpop3 gremlinpython

5
推荐指数
1
解决办法
548
查看次数

Gremlin 到 AWS Neptune 的 403 禁止错误

非常感谢您提前的帮助

我尝试按照https://docs.aws.amazon.com/neptune/latest/userguide/get-started.html中的说明设置我的 AWS Neptune 环境。设置似乎很好,我可以使用 Neptune Notebook 安装来检查状态。状态消息为:

{
  "status": "healthy",
  "startTime": "Tue May 12 04:24:52 UTC 2020",
  "dbEngineVersion": "1.0.2.2.R2",
  "role": "writer",
  "gremlin": {
    "version": "tinkerpop-3.4.3"
  },
  "sparql": {
    "version": "sparql-1.1"
  },
  "labMode": {
    "ObjectIndex": "disabled",
    "ReadWriteConflictDetection": "enabled"
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,我无法通过 EC2 客户端实例中的 Gremlin 控制台连接到它,我收到 403 禁止错误,如下所示:


         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
gremlin> :remote connect tinkerpop.server conf/neptune-remote.yaml
WARN  org.apache.tinkerpop.gremlin.driver.Cluster  - Using deprecated SSL trustCertChainFile support
ERROR org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler  - Could not …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services gremlin amazon-iam gremlin-server amazon-neptune

5
推荐指数
1
解决办法
3205
查看次数

变量 - 海王星上的 Gremlin

我位于 Gremlin 控制台并连接到 AWS Neptune 数据库

g.V().hasLabel('Risk').toList()

提供了预期的结果,但是当我尝试将结果分配给变量时

risks = g.V().hasLabel('Risk').toList()

我收到下面的消息 - 令牌识别错误显然会出现在变量名称上,因为当我更改变量名称时,消息的位置和“at”部分会发生变化。

{"requestId":"650d7c4b-44d1-43f8-b9a3-fbf085cc3ead","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 3, error message : token recognition error at: 'ks'"}

我在 Tinkerpop 数据库上尝试了同样的操作,并且变量分配有效。我缺少什么?

gremlin tinkerpop amazon-neptune

4
推荐指数
1
解决办法
1864
查看次数

有什么方法可以强制所有带有标签的 Visjs 节点大小相同?

我一直在试验 Visjs.org 库,以使用网络布局构建图形的可视化表示。我想创建一个在节点内有标签的图(我使用圆圈作为节点),所有节点的大小都相同。

我可以让图形出现并且标签确实在节点内。但是,节点始终缩放到标签文本的大小。所以更长的标签=更大的节点。

对于用户来说,这不是我想要的,这似乎暗示了对更大节点的一些意想不到的重要性。我曾尝试使用缩放选项,但无济于事。我可以通过将标签放在节点之外来解决问题,但这不是我想要的。

我想要做的是强制所有节点的大小相同,并且标签仍然在节点内。我附上了我的示例程序。

<html>
<head>
    <script type="text/javascript" src="http://visjs.org/dist/vis.js"></script>
    <link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
        #mynetwork {
            width: 600px;
            height: 400px;
            border: 1px solid lightgray;
        }
    </style>
</head>
<body>
<div id="mynetwork"></div>

<script type="text/javascript">
    // create an array with nodes
    var nodes = new vis.DataSet([
        {id: 1, label: 'Fred'},
        {id: 2, label: 'Bill'},
        {id: 3, label: 'Texas'},
        {id: 4, label: 'North\nCarolina'},
        {id: 5, label: 'Planes'},
        {id: 6, label: 'Books'}
    ]);

    // create an array with edges
    var edges …
Run Code Online (Sandbox Code Playgroud)

html javascript graph vis.js vis.js-network

3
推荐指数
2
解决办法
5041
查看次数

将 Janusgraph 与 AWSKeyspaces 结合使用。从 gremlin 控制台添加顶点时,我收到一条错误消息“锁定写入重试次数超出”

Gremlin 控制台: gremlin> :远程连接tinkerpop.server conf/remote.yaml ==>配置的 localhost/127.0.0.1:8182

gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode

gremlin> graph
==>standardjanusgraph[cql:[cassandra.us-east-2.amazonaws.com]]
gremlin> g = graph.traversal()

==>graphtraversalsource[standardjanusgraph[cql:[cassandra.us-east-2.amazonaws.com]], standard]
gremlin> g.addV('student').property('name', 'Jeffery').property('GPA', 'A+');

Lock write retry count exceeded
Run Code Online (Sandbox Code Playgroud)

我的设置如下

  janusgraph.storage.cql.ssl.enabled: "true"
  janusgraph.index.search.hostname: jce-elastic
  janusgraph.storage.cql.local-datacenter: "us-east-2"
  janusgraph.storage.cql.partitioner-name: DefaultPartitioner
  janusgraph.storage.cql.metadata-schema-enabled: "false"
  janusgraph.storage.cql.metadata-token-map-enabled: "false"
  janusgraph.storage.cql.only-use-local-consistency-for-system-operations: "true"
  janusgraph.log.janusgraph.key-consistent: "true"
  janusgraph.log.tx.key-consistent: "true"
  janusgraph.storage.cql.read-consistency-level: "LOCAL_QUORUM"
  janusgraph.storage.cql.write-consistency-level: "LOCAL_QUORUM"
  janusgraph.graph.assign-timestamp: "false"
Run Code Online (Sandbox Code Playgroud)

以下是服务器日志

jce-janusgraph   | 232996 [gremlin-server-exec-4] WARN  org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker …
Run Code Online (Sandbox Code Playgroud)

gremlin janusgraph amazon-keyspaces

3
推荐指数
1
解决办法
154
查看次数

如果 1 个 Gremlin 查询中不存在顶点和边,则创建

如果边缘尚不存在,我找到以下代码来创建边缘。

g.V().hasLabel("V1")
.has("userId", userId).as("a")
.V().hasLabel("V1").has("userId", userId2)
.coalesce(
        bothE("link").where(outV().as("a")),
        addE("link").from("a")
)
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想创建顶点和边(如果它们不存在于 1 个查询中)。

我用新图尝试以下代码,它只是创建新顶点,但它们之间没有关系。

g.V().hasLabel("V1")
.has("userId", userId).fold()
.coalesce(
        unfold(),
        addV("V1").property("userId", userId1)
).as("a")
.V().hasLabel("V1").has("userId", userId2).fold()
.coalesce(
        unfold(),
        addV("V1").property("userId", userId2)
)
.coalesce(
        bothE("link").where(outV().as("a")),
        addE("link").from("a")
)
Run Code Online (Sandbox Code Playgroud)

graph gremlin janusgraph

2
推荐指数
1
解决办法
1860
查看次数

我可以在 Jupyter Notebook 中使用 Gremlin Python 客户端并避免事件循环错误吗?

我知道图形笔记本项目允许使用魔法命令提交 Gremlin 查询。但是,有时我需要在常规 Jupyter 笔记本单元中使用 Python 进行编码并使用代码连接到服务器。如果使用 Gremlin Python 3.5.2 客户端,我尝试执行以下操作:

server = '<your server endpoint goes here>'
port = 8182

endpoint = f'wss://{server}:{port}/gremlin'

connection = DriverRemoteConnection(endpoint,'g')

g = traversal().withRemote(connection)
Run Code Online (Sandbox Code Playgroud)

由于 Jupyter 事件循环已在运行,因此会引发错误。

有没有解决的办法?

gremlin tinkerpop amazon-neptune gremlinpython graph-notebook

2
推荐指数
1
解决办法
818
查看次数

Gremlin Python 无法运行事件循环

我正在运行 Gremlin Python。首先,我按照此处的说明在本地计算机中进行了安装,然后我在此处运行了该网站的代码,但此时出现以下错误:

    heading('SubgraphStrategy - just Texas airports')
    strategy = SubgraphStrategy(vertices=__.has("region","US-TX"), edges=__.hasLabel('route'))
    g2 = g.withStrategies(strategy)
    verts = g2.V().count().next()

RuntimeError: Cannot run the event loop while another loop is running
Run Code Online (Sandbox Code Playgroud)

我使用以下代码验证了与 Gremlin Server 的图形数据库的连接

%%graph_notebook_config
{
  "host": "localhost",
  "port": 8182,
  "ssl": false,
  "gremlin": {
    "traversal_source": "g"
  }
}
Run Code Online (Sandbox Code Playgroud)

我找到了一些“RuntimeError:在另一个循环运行时无法运行事件循环”的解决方案,例如 Nest_async 但后来我收到了不同的错误。

谢谢

python graph gremlin graph-notebook

2
推荐指数
1
解决办法
1622
查看次数

nodejs gremlin 更新(如果存在)否则创建

我正在针对AWS neptune使用nodejs gremlin,要求是如果顶点存在则更新属性,否则创建一个新顶点,我在下面尝试过

g.V().has('event','id','1').
  fold().
  coalesce(unfold(),
           addV('event').property('id','1'))
Run Code Online (Sandbox Code Playgroud)

但我收到“展开未定义”错误,如何解决此问题?

node.js gremlin amazon-neptune

1
推荐指数
1
解决办法
378
查看次数

在 Docker 镜像中设置 TinkerPop 配置

我正在使用 TinkerPop 的本地实现和 docker imagetinkerpop/gremlin-server:3.4.1 来与 nodeJs 中的图形数据库进行本地交互。

我需要将 IDManager 设置为 ANY,以便它可以接受自定义顶点 ID 的字符串值(目前它仅适用于数字类型)。

我知道我需要设置 TinkerGraph gremlin.tinkergraph.vertexIdManager 的配置,但我不确定如何在我的 docker-compose 文件中使用正确的配置对其进行初始化。 http://tinkerpop.apache.org/docs/current/reference/#_configuration_4

有人知道怎么做吗?

谢谢

gremlin tinkerpop docker gremlin-server

1
推荐指数
1
解决办法
1452
查看次数