假设我有来自各个农场的苹果。所以树结苹果,农场有树。我想要一份苹果列表,其中还包含对它们来自的农场的引用。
g = new TinkerGraph();
// apples
a1 = g.addVertex("a1");
a1.setProperty("type", "apple");
a2 = g.addVertex("a2");
a2.setProperty("type", "apple");
a3 = g.addVertex("a3");
a3.setProperty("type", "apple");
// trees
t1 = g.addVertex("t1");
t1.setProperty("type", "tree");
t2 = g.addVertex("t2");
t2.setProperty("type", "tree");
// farms
f1 = g.addVertex("f1");
f1.setProperty("type", "farm");
f1.setProperty("uid", "f1");
f2 = g.addVertex("f2");
f2.setProperty("type", "farm");
f2.setProperty("uid", "f2");
g.addEdge(t1, a1, "bears");
g.addEdge(t1, a2, "bears");
g.addEdge(t2, a3, "bears");
g.addEdge(f1, t1, "has");
g.addEdge(f2, t2, "has");
Run Code Online (Sandbox Code Playgroud)
我想遍历图表来报告每个苹果,并在其中包含农场 ID。我尝试过这样的事情:
g.V.has("type", "apple").copySplit(_().in("bears").in("has").map("uid"),
_().map()).fairMerge
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:
==>{uid=f1}
==>{type=apple}
==>{uid=f1}
==>{type=apple}
==>{uid=f2}
==>{type=apple}
Run Code Online (Sandbox Code Playgroud)
我想要的是:
==>{uid=f1, type=apple} …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 gremlin 控制台的输出转换为 json 格式,
例如: gremlin>g.V(409608).valueMap()
样本输出:[eName:[FS-BR-GOJU-ENB-G001_MW],lng:[000086.2119100],modulation:[2048],city:[Jamshedpur],hopType:[1+0],eType:[MICROWAVE], cTime:[Sat Mar 03 20:37:27 IST 2018],aendSapId:[FS-BR-JMDP-ENB-6005],vendor:[CERAGON],domain:[MW],location:[POINT (86.21191 22.79906)] ,state:[Jharkhand],mTime:[Sat Mar 03 20:37:27 IST 2018],lat:[000022.7990600],sapId:[FS-BR-GOJU-ENB-G001]]
我怎样才能将它转换成 json ?
这"g.V(409608).valueMap()"只是一个例子,我正在寻找一种可以将任何类型的查询输出转换为 json 的函数/方式。
实际上,我正在尝试开发一个功能,其中我将 gremlin 查询作为字符串(“gremlin 查询”),并且我需要它的 JSON (USING JAVA)输出。
我将 JanusGraph 与 Cassandra 和 ElasticSearch 后端一起使用。我使用以下脚本来创建我的架构和索引。
// Create a Janus Graph instance, according to the configuration file provided
// in the open() method below, and define the schema and index.
// This is intended to be loaded and run inside the Gremlin Console from the Janus
// Graph download. Usage :load janus-ualschema.groovy
println "\n=======================================";[]
println "Creating in-memory Janus Graph instance";[]
println "=======================================\n";[]
// Create a new graph instance
graph = JanusGraphFactory.open("conf/janusgraph-useractivitylogs.properties")
mgmt = graph.openManagement()
println "\n====================";[]
println "Defining EDGE …Run Code Online (Sandbox Code Playgroud) 有一个新版本,但文档有点缺乏工作示例。
Github 票证:https : //github.com/jbmusso/gremlin-javascript/issues/109
我一直在努力让一个例子起作用。任何帮助表示赞赏:
gremlin-server: 3.3.2 with config gremlin-server-modern.yaml
npm gremlin lib: 3.3.2
import gremlin from 'gremlin';
import DriverRemoteConnection from 'gremlin/lib/driver/driver-remote-connection';
import { Graph } from 'gremlin/lib/structure/graph';
const graph = new Graph()
const g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin', { mimeType: 'application/vnd.gremlin-v3.0+json' }));
const fetchById = async (id) => {
const result = await g.V(id).toList()
console.log(result);
}
const addUser = async (name) => {
const newVertex = await g.addV().property('name','marko').property('name','marko a. rodriguez').next()
console.log(newVertex)
}
addUser()
fetchById(0)
Run Code Online (Sandbox Code Playgroud)
[]
{ value: …Run Code Online (Sandbox Code Playgroud) 我正在处理一个沿多个边缘导航并最终生成String. 根据图形内容,此遍历可能为空。如果遍历最终为空,我想改为返回一个默认值。
这是我目前正在做的事情:
GraphTraversal<?, ?> traversal = g.traversal().V().
// ... fairly complex navigation here...
// eventually, we arrive at the target vertex and use its name
.values("name")
// as we don't know if the target vertex is present, lets add a default
.union(
identity(), // if we found something we want to keep it
constant("") // empty string is our default
)
// to make sure that we do not use the default if we have a value... …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试访问 AWS Neptune 服务器,但在尝试连接时收到以下错误。
我正在从 AWS 学习本教程,但没有成功:https : //docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin.html
有没有人遇到过这个问题?
我认为这是因为入站/出站规则,但即使我允许所有流量,它也不起作用。
终点也是正确的。双重检查。
conf/neptune-remote.yml
hosts: [neptuneTest.cu7geofyk01wr.us-east-1.neptune.amazonaws.com]
port: 8182
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}
Run Code Online (Sandbox Code Playgroud)
错误
\,,,/
(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
ERROR org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler - Could not process the response
io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: Invalid handshake response getStatus: 500 Internal Server Error
at io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13.verify(WebSocketClientHandshaker13.java:191)
at io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.finishHandshake(WebSocketClientHandshaker.java:216)
at org.apache.tinkerpop.gremlin.driver.handler.WebSocketClientHandler.channelRead0(WebSocketClientHandler.java:69)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at …Run Code Online (Sandbox Code Playgroud) 我通过远程连接到 janusGraph
cluster = Cluster.build()
.addContactPoints(uri.split("\\|"))
.port(port)
.serializer(new GryoMessageSerializerV1d0(GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance())))
.maxConnectionPoolSize(poolSize)
.maxContentLength(10000000)
.create();
gts = AnonymousTraversalSource
.traversal()
.withRemote(DriverRemoteConnection.using(cluster));
Run Code Online (Sandbox Code Playgroud)
由于 gts 是线程安全的,我将 gts 保持在静态上下文中。每个线程使用相同的对象,并且没有一个线程通过调用 gts.close() 关闭 gts 每个线程运行查询,例如:
result = gts.V().has("foo","bar").valueMap().toList()
我不关闭 gts(graphTraversalSource) 不是由创建的 graphTraversal 对象gts.V()
我目前正在使用 gremlin-python 来研究图表。我想获得具有两个以上出边的所有顶点。我正在使用匿名遍历根据边缘计数过滤掉用户,但下面是我得到的错误。
AttributeError: 'list' 对象没有属性 'out'
我对此很陌生,不确定我在这里做错了什么。这是可用的有限 gremlin-python 教程/文档中描述的方式。
我是小鬼的新手。使用 nodejs 我连接了 gremlin 并添加了几个顶点。
假设我有 10 个不同的顶点并与边相连。有没有办法读取和迭代nodejs中的数据。它就像带有条件的简单选择查询..(选择 * from users where username='john')
async get_vertices_by_props(input) {
var graph_data = await this.get_vertex(input.label,input.property_name)
// some code here..
}
async get_vertex(label, property) {
if (!label || !property || !value) {
return error;
}
return await this.g.V().hasLabel(label);
}
Run Code Online (Sandbox Code Playgroud) 我有一个创建顶点和边“创建”的查询。边缘有一个属性“on”,它是 unix datetime 长。当我在 Azure Cosmos DB 终端中使用以下段执行查询时,它按预期工作 - 返回一个带有“On”属性的对象,该属性是一个数字。
.project('Id', 'CreatedOn')
.by('id')
.by(
select('createdEdge')
.by('on')
)
Run Code Online (Sandbox Code Playgroud)
当我使用 Gremlin.NET 从我的应用程序代码执行此查询时,它失败并显示错误:
不支持 JSON 类型。
我在源代码中看到Gremlin.NET 的反序列化逻辑似乎不处理任何数字类型。真的是这样吗?有没有办法使用 long、float、int 属性类型?
gremlin ×10
janusgraph ×3
tinkerpop3 ×2
cassandra ×1
console ×1
graph ×1
gremlinnet ×1
javascript ×1
json ×1
node.js ×1
output ×1
tinkerpop ×1
titan ×1