在撰写本书时,从Aus出到您可以直达的地方有59个,我们可以使用下面的查询来验证这一事实。
At the time of writing this book, there were 59 places you could fly to directly (non stop) from
Austin. We can verify this fact using the following query.

如果我们想统计从AUS出发中转一次可以到达多少个地方,我们可以用下面的查询。使用dedup步骤是我们只想知道有多少个不同的地方,而不是去这些地方有多少种不同的方式。
If we wanted to count how many places we could go to from Austin with one stop, we could use the
following query. The dedup step is used as we only want to know how many unique places we can
go to, not how many different ways of getting to all of those places there are.
然而这个查询有一个问题。871个地方包含了我们可以从AUS直达的地方。我们真正想要的是您从AUS出发只可以中转一次到的地方。我们需要有一种方式来记住这些地方,把其中一些从871个中移除掉。这就要用到aggregate了。看下下面修改后的查询语句。
There is however a problem with this query. The 871 places is going to include (some or possibly all
of) the places we can also get to non stop from Austin. What we really want to find are all the places
that you can only get to from Austin with one stop. So what we need is a way to remember all of
those places and remove them from the 871 some how. This is where aggregate is useful. Take a
look at the modified query below
在第一个out步骤后所有找到的顶点都存在了集合里,我们称之为nonstop.接着第二个out我们增加了一个where步骤,它本质上就是只保留不在nonstop集合中的顶点。我们仍然用到了dedup步骤,否则我们就会统计到大量冗余的顶点。
After the first out step all of the vertices that were found are stored in a collection I chose to call
nonstop. Then, after the second out we can add a where step that essentially says "only keep the
vertices that are not part of the nonstop collection". We still do the dedup step as otherwise we will
still end up counting a lot of the remaining airports more than once.
注意数字812比之前查询中统计出来的871小了59,这表明您可以直达的那个地方已经从第二个查询中剔除了。这也告诉我们从Aus出发,您可以到达任何地方。在“集合的重复访问”这一节中我们将会看到各种类型的集合,您可以把它们当作是小精灵查询语句的一部分。
Notice that 812 is precisely 59 less than the 871 number returned by the previous query which
shows the places you can get to non stop were all correctly removed from the second query. This
also tells us there are no flights from Austin to places that you cannot get to from anywhere else!
We will take a more in depth look at the various types of collections that you can use as part of a
Gremlin query in the "Collections revisited" section a bit later.
浙公网安备 33010602011771号