有时需要展开一个集合,这样我们可以更进一步的处理它。这就是unfold步骤的工作。如果我们应用unfold步骤到前边的查询语句中,您可以看到它生成了什么。这个由group步骤生成的集合是一个java的HashMap。 unfold步骤把HashMap 转化为了一系列的HashMap.Node元素。
Sometimes it is desirable to unbundle a collection so that we can work on it further. This is what
the unfold step does. If we apply unfold to the previous query you can see what is generated. The
collection that the group step generates is a Java HashMap. The unfold step turns the HashMap into
a series of HashMap.Node elements.

 

如果我们想要一个列表的值,我们可以再用unfold步骤,如下所示。您可以从我们以前讨论中回忆起来:顶点的属性在列表中存储着,即使只有一个属性,也就换而言之,列表的长度是一。注意这个例子说明一个单独的unfold步骤不会反复地从一个集合中分解元素。

If we wanted a list of values we could use unfold again as shown below. You will recall from our
earlier discussion that vertex properties are stored as lists even if there is only one property - a list
of length one in other words. Note that this shows that a single unfold step will not recursively
unbundle elements from a collection.

 

我们可以增加第二个unfold步骤得到城市名,移除掉包含它的列表。

We could add a second unfold to just get the city names back and remove the containing lists.

 

当您想要多次使用unfold时,作为一个替代方案,也可以用 repeat步骤,像下面这样。

As an alternative, repeat can be used when you want to unfold more than once as shown below.

 

如果我们不确定需要unfold多少次,我们可以把查询语句改写成下面这样。repeat的循环将会一直unfold直到只有一个list。最后的unfold会把最后的list移除,只把文本值留给我们。

If we were not sure how many times we needed to unfold we could change the query as follows.
The repeat loop will unfold until there is only a list of lists left. The final unfold will remove the
remaining lists leaving us with just the text values.

 

已经使用unfold步骤获取到了字符串类型的城市名,我们可以再fold一次,使用fold步骤生成一个机场名的列表。这个样式,解绑-做一些处理-再聚合 是相当常用,用起来相当方便的,,特别是在一些更复杂的查询中。

Having used unfold to extract just the city names as strings, we could re-fold one time to produce a
list of airport names using the fold step. This pattern of unfolding, performing an operation and
refolding is one that comes in handy quite often, especially in more complex queries.

 

需要指出的是:keys和values关键字也可以和一些东西一起使用,比如valueMap步骤。这是一个简单的例子。

It is probably worth pointing out that the keys and values keywords can also be used with
something as simple as a valueMap step. Here is a simple example.

 

 

posted on 2022-04-23 21:52  bokeyuannicheng0000  阅读(32)  评论(0)    收藏  举报