深入学习Gremlin(12):数学运算
第12期 Gremlin Steps:
math()
本系列文章的Gremlin示例均在HugeGraph图数据库上执行,环境搭建可参考准备Gremlin执行环境,本文示例均以其中的“TinkerPop关系图”为初始数据。
数学运算说明
在Gremlin中有一个专门负责科学计算功能的step math()
。 math()
不同于常见的函数组合和嵌套形式,提供了一种易于读取的基于字符串的数学处理器。
-
math()
支持by()
,其中多个by()
按照在math()运算表达式
中首次引用变量的顺序应用。 - 保留变量
_
是指传入math()
的当前遍历器对象。
math()
支持的运算符包括:+
,-
,*
,/
,%
,^
math()
支持的内嵌函数包括:
-
abs
: absolute value,绝对值 -
acos
: arc cosine,反余弦 -
asin
: arc sine,反正弦 -
atan
: arc tangent,反正切 -
cbrt
: cubic root,立方根 -
ceil
: nearest upper integer,向上最接近的整数 -
cos
: cosine,余弦 -
cosh
: hyperbolic cosine,双曲余弦 -
exp
: euler’s number raised to the power (e^x),以e为底的指数 -
floor
: nearest lower integer,向下最近接的整数 -
log
: logarithmus naturalis (base e),以e为底的对数 -
log10
: logarithm (base 10),以10为底的对数 -
log2
: logarithm (base 2),以2为底的对数 -
sin
: sine,正弦 -
sinh
: hyperbolic sine,双曲正弦 -
sqrt
: square root,平方根 -
tan
: tangent,正切 -
tanh
: hyperbolic tangent,双曲正切 -
signum
: signum function,签名功能
实例说明
(待补充…)
math()
step是从TinkerPop 3.3.x开始有的,HugeGraph目前基于TinkerPop 3.2.5,因此暂不支持math()
step,后续适配到3.3.3或更高版本后会补充math
的实例说明。如果感兴趣,可以先参考TinkerPop官网对于math()
step的实例说明