gremlin - Is there an efficient way to see how many edges and verticies were created in a gremlin Upsert?
问题描述
Using a query like the following
g.V().has('person','name','marko').
fold().
coalesce(unfold(),
addV('person').property('name','marko')).
property('age',29)
Is there an efficient way to also return how many verticies were created?
I.e. 0 in the case that the marko vertex exists, 1 in the case that the marko vertex does not exist.
解决方案
I think I'd go with union()
:
gremlin> g.V().has('person','name','marko').
......1> fold().
......2> union(coalesce(unfold(),
......3> addV('person').property('name','marko')).
......4> property('age',29),
......5> count(local))
==>v[1]
==>1
gremlin> g.V().has('person','name','darko').
......1> fold().
......2> union(coalesce(unfold(),
......3> addV('person').property('name','marko')).
......4> property('age',29),
......5> count(local))
==>v[13]
==>0
It's the reverse of what you asked for in terms of 1 and 0 existence but I suppose that would be easy enough to remedy if you really needed to but it would add additional complexity to the traversal around that count(local)
which is pretty easy to read right now as it is.
推荐阅读
- c - 如何使用 CRTSCTS 监听串口
- r - 创建函数时无法创建错误语句
- python - Python:从 300 个数据集创建大小为 12 的数据框,使其包含 0:12、1:13、2:14 等
- angular - 从我的自定义中间件返回到角度时,asp .net core api cors 问题
- node.js - TypeError:无法读取未定义的属性“长度”。在节点 js
- javascript - 无法遍历 mxgraph 中的 xml 文件以获取子节点的指定属性值?
- python - AdaBoost 与 SVM 基分类器的执行时间
- php - 在 Laravel 中加入多个模型进行查询的最佳方法是什么
- c# - C# ASP.NET MVC - AJAX Post 方法不更新 ModelView
- amazon-web-services - 将时间戳作为 Appsync 中的日期类型放入 Elasticsearch 集群