在“在TinkerPop3.4引入的valuemap的变化”这一节中,笔者已经举了例子,valueMap步骤的后边用了by(unfold())来展开属性值。您可以回忆一下,这就是说,单个属性值是不会返回的,它们封装在了列表中。这个特性是在TinkerPop3.4引入的。然而您也可以使用以前版本的Tinkerpop得到同样的结果,只是需要做更多的工作。
In the "Changes to valueMap introduced in TinkerPop 3.4" section, I showed some examples that
used by(unfold()) following a valueMap step unroll property values. As you may recall, this means
that single property values are not returned wrapped inside lists. This feature was introduced in
TinkerPop 3.4. However, you can achieve the same results using earlier versions of TinkerPop, it
just takes a bit more work.
如果您跳过了这一节,这有一个新特性的例子,它产生的输出在这。
In case you jumped ahead to this section, here is an example of the new feature and the output it
produces.

 

我们用像下面这样一个查询可以得到同样的结果。用到了一个map步骤来展开然后再打包valueMap步骤的结果,值就会从它们的列表中展开来。

We could use a query like the one below to achieve the same result. A map step is used to
unpackage and then repackage the results of the valueMap step with the values unrolled from their
lists.
 

 

输出看起来和前边查询的很像。这是对的。然而这个查询仍有一个问题。它不是我们想要的,如果任一个属性有列表或者map值与之关联。

The output looks just like that from the prior query, which is good. However, there is still an issue
with the query. It will not do quite what we want if any property has a list or set of values
associated with it.

 

 

让我们想象一下我们要增加一个地区分类 "Bay Area" 给SFA机场顶点,我们可以像下面这样做。
Let’s imagine we wanted to add an additional region classification of "Bay Area" to the San
Francisco airport vertex. We might do that as shown below.

 

我们可以查看valueMap的region属性来验证我们现在有一个列表。

We can look at the valueMap for the region property to validate we now have a list.

 

如果我们打算用到我们刚刚创建的map步骤,它将会试着展开这个属性,在这个例子中不是我们想要的,因为我们想要保留这个列表。我们可以修改一点,这样就可以包含一个choose步骤,让它只展开长度是1的列表。

If we were to use the map step that we just created, it would try to unroll this property which in this
case is not what we want as we want to preserve the list. We can modify this a little to include a
choose step that only unrolls the list if it has a length of one.

 

这次的结果仍然是展开的,除了region属性它仍然是一个列表。

This time the results are still unrolled except for the region property which remained a list.

 

 

posted on 2022-04-25 16:23  bokeyuannicheng0000  阅读(27)  评论(0)    收藏  举报