锯齿结果数组Gremlin查询 [英] Jagged Result Array Gremlin Query

查看:80
本文介绍了锯齿结果数组Gremlin查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请您帮我编写一个查询,以将遍历中的每个源顶点及其关联的边和顶点返回为每个此类源顶点上的数组的查询?简而言之,我需要一个包含3个元组的数组的结果集,其中每个元组的项1是源顶点,而项2和3是关联的数组.

Please may you help me to write a query that returns each source vertex in my traversal along with its associated edges and vertices as arrays on each such source vertex? In short, I need a result set comprising an array of 3-tuples with item 1 of each tuple being the source vertex and items 2 and 3 being the associated arrays.

谢谢!

在图形数据上进行扩展,并添加了我当前的问题查询. 改进的Gremlin示例图形代码(抱歉,认为没有人会真正运行它.)

EDIT 1: Expanded on the graph data and added my current problem query. EDIT 2: Improved Gremlin sample graph code (apologies, didn't think anyone would actually run it.)

g.addV("blueprint").property("name","Mall").
addV("blueprint").property("name","HousingComplex").
addV("blueprint").property("name","Airfield").
addV("architect").property("name","Tom").
addV("architect").property("name","Jerry").
addV("architect").property("name","Sylvester").
addV("buildingCategory").property("name","Civil").
addV("buildingCategory").property("name","Commercial").
addV("buildingCategory").property("name","Industrial").
addV("buildingCategory").property("name","Military").
addV("buildingCategory").property("name","Resnameential").
V().has("name","Tom").addE("designed").to(V().has("name","HousingComplex")).
V().has("name","Tom").addE("assisted").to(V().has("name","Mall")).
V().has("name","Jerry").addE("designed").to(V().has("name","Airfield")).
V().has("name","Jerry").addE("assisted").to(V().has("name","HousingComplex")).
V().has("name","Sylvester").addE("designed").to(V().has("name","Mall")).
V().has("name","Sylvester").addE("assisted").to(V().has("name","Airfield")).
V().has("name","Sylvester").addE("assisted").to(V().has("name","HousingComplex")).
V().has("name","Mall").addE("classification").to(V().has("name","Commercial")).
V().has("name","HousingComplex").addE("classification").to(V().has("name","Resnameential")).
V().has("name","Airfield").addE("classification").to(V().has("name","Civil"))

请注意,以上内容是我们数据的非常简化的呈现.

Please note that the above is a very simplified rendering of our data.

所需的查询结果

我需要将每个蓝图顶点作为基础,并将其每个相关的边/顶点作为数组.

Needed Query Results

I need to bring back each blueprint vertex as a base with each of its associated edges / vertices as arrays.

当前,我执行这个非常麻烦的查询,该查询获取蓝图并分配标签,获取架构师并分配标签,然后选择两个标签.解决方案还可以;但是,当我需要包括边缘或需要获得蓝图分类顶点(工业,军事,住宅,商业等)时,它会变得凌乱.实际上,我需要为每个蓝图拉回的关联数据越多,我的解决方案就变得越草率.

Currently I do this very cumbersome query that gets the blueprints and assigns a label, gets the architects and assigns a label, then selects both labels. The solution is ok; however, it gets messy when I need to include edges or I need to get blueprint classification vertices (industrial, military, residential, commercial, etc.). In effect, the more associated data that I need to pull back for each blueprint, the sloppier my solution becomes.

我当前的查询看起来像这样:

My current query looks something like this:

g.V().hasLabel("blueprint").as("blueprints").
outE().or(hasLabel("designed"),hasLabel("assisted")).inV().as("architects").
select("blueprints").coalesce(out("classification"),constant()).as("classifications").
select("blueprints","architects","classifications")

以上内容产生了很多重复.如果以下项目的数量:蓝图为b,架构师为a,分类为c,则结果集包含b * a * c结果.我想要一个蓝图,其中包含与之相关的一系列建筑师和与之相关的一系列分类(如果有).

The above produces a lot of duplication. If the number of: blueprints is b, architects is a, and classifications is c, the result set comprises b * a * c results. I'd like one blueprint with an array of its associated architects and an array of its associated classifications, if any.

并发症

我正在尝试在一个查询中执行此操作,以便可以从图中获取所有蓝图数据以填充过滤列表.一旦有了包含所有顶点,边线及其属性的列表,用户就可以单击指向斑点的链接,浏览到项目站点等.每次我获得新页面或更改过滤器时,都希望一次访问服务器.

Complications

I'm trying to do this in one query so that I can get all blueprint data from the graph to populate a filtered list. Once I have the list comprising all of the vertices, edges, and their properties, users can then click links to blobs, browse to project sites, etc. Accordingly, I've got pagination as well as filtering to think about and I'd prefer to make one trip to the server each time I get a new page or the filters change.

推荐答案

我想出了一个答案;但是,它使查询的计算费用增加了三倍.不确定是否可以进一步优化.

I figured out an answer; however, it quadruples the compute charge for the query. Not sure if this can be optimized further.

g.V().hasLabel("blueprint").
project("blueprints","architects").
by().
by(outE().or(hasLabel("designed"),hasLabel("assisted")).inV().dedup().fold())

我刚刚解决了蓝图和架构师,但是分类只需要另一个by(...遍历...)和投影标签.

I just solved for blueprints and architects, but classifications just needs another by(...traversal...) and projection label.

我可能只需要在一个查询中获取蓝图,在并行查询中获取它们的每个关联项目,然后将它们全部整合到API中即可.对于API数据层来说,这将是非常糟糕的设计,但出于性能方面的考虑可能是必需的.

I may have to just get the blueprints in one query, get each of their associated items in parallel queries, then put it all together in the API. That would be very bad design for the API data layer but may be necessary for performance reasons.

这篇关于锯齿结果数组Gremlin查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆