有时,查询的结果是键值对的集合,我们需要或对键排序,或对值以升序或降序排列。小精灵给我们提供了方法,在这些场景中,我们可以控制顺序。它是怎么工作的,可以从下面的例子中看到。
Sometimes, when the results of a query are a set of one or more key:value pairs, we need to sort by
either the key or the value in either ascending or descending order. Gremlin offers us ways that we
can control the sort in these cases. Examples of how this works are shown below.
在Tinkerpop3.3开始,有一些句法的改变。以前的关键字的valueDecr,valueIncr,keyDecr,keyIncr现在是使用by(key,asc)或者by(value,desc)等。
In Tinkerpop 3.3 changes to the syntax were made. The previous keywords
valueDecr, valueIncr, keyDecr and keyIncr are now specified using the form
by(keys,asc) or by(values,desc) etc.
下面的例子展示了使用order对由group步骤创建的Map的键进行排序,和不用order之间的差异。
The following example shows the difference between running a query with and without the use of
order to sort using the keys of the map created by the group step.

注意local是如何做为order的参数使用的。这是必需的,这样在最后的列表构造的时候排序已经完成了。如果您不想使用local,那么order就不起作用。那时,整个结果就是一个单一个实体,它会作用于整个结果。

Notice also how local is used as a parameter to order. This is required so that the ordering is done
while the final list is being constructed. If you do not specify local then order will have no effect as
it will be applied to the entire result which is treated as a single entity at that point.

在这个例子中我们把路线的数字做为值字段把它按降序排列。

In this example we make the numbers of runways the key field and sort on it in descending order.

 

 

posted on 2022-04-17 19:58  bokeyuannicheng0000  阅读(19)  评论(0)    收藏  举报