我们在前边一些小节中看到,小精灵时胡这样的步骤如sum, count,mean,它们可以用来进行一些基本的数学运算。在阿帕奇TinkerPop3.3.1中引入了新的math步骤,数学运算作为小精灵图遍历的一部分,我们把可进行一些科学计算。这些运算符是基于Java Math类的,如果您还不熟悉这些类,熟悉这些类是很有必要的。注意如果您所使用的图引擎支持阿帕奇Tinkerpop3.3.1及以上版本,那么您可以使用这些功能。
As we have seen in some of the prior sections, there are some Gremlin steps such as sum, count and
mean that can be used to perform some fairly basic mathematical operations. In Apache TinkerPop
version 3.3.1 a new math step was introduced that allows us to perform scientific calculator style
mathematical operations as part of a Gremlin graph traversal. As these operators build upon the
Java Math class it is worth becoming familiar with that class if you are not already. Be aware that
this functionality will only be available to you if the graph implementation that you are using
supports Apache TInkerPop 3.3.1 or higher.
下表按字母序总结了您可以使用的运算符。
The table below provides a summary of the available operators sorted alphabetically.
math步骤不同于整个表达式是按字符串传递的查询的其它的步骤。这意味着您可以在遍历中使用您所分配的标签,但是您不可以在表达式中使用额外的变量或者静态常量比如Math.PI我们有其它的方法来解决这下问题,如下所示。笔者不打算给每个运算符举一个例子,但是这些例子可以提供基本的构造块,您可以在您的小精灵查询用到数学运算时使用它们。
The math step behaves differently from other steps that we have looked at so far in as much as the
entire expression is passed in as a single string. This means that you can use labels you have
assigned as part of a traversal but you cannot use external variables or static constant references
such as Math.PI inside the expression itself. There are ways to easily work around this however as
we shall see below. I have not attempted to give an example of every single operator being used but
the examples provided should provide all of the basic building blocks you will need to incorporate
mathematical operators into your own Gremlin queries.
这些特征要求您使用的图数据库系统支持Tinkerpop3.3.1及以上版本。
These features require that the graph database system you are using supports a
TinkerPop version of 3.3.1 or higher.
浙公网安备 33010602011771号