跳转至

内置数学函数

函数说明

Nebula Graph 支持以下内置数学函数。

函数 说明
double abs(double x) 返回 x 的绝对值。
double floor(double x) 返回小于或等于 x 的最大整数。
double ceil(double x) 返回大于或等于 x 的最小整数。
double round(double x, int y) 返回 x 四舍五入后的值,y 为小数位数。y 小于 0 时 ,在小数点左侧做四舍五入。
极端情况下请注意浮点数的精度问题。
double sqrt(double x) 返回 x 的平方根。
double cbrt(double x) 返回 x 的立方根。
double hypot(double x, double y) 返回直角三角形(直角边长为 x 和 y)的斜边长。
double pow(double x, double y) 返回 xy 的值。
double exp(double x) 返回 ex 的值。
double exp2(double x) 返回 2x 的值。
double log(double x) 返回以自然数 e 为底 x 的对数。
double log2(double x) 返回以 2 为底 x 的对数。
double log10(double x) 返回以 10 为底 x 的对数。
double sin(double x) 返回 x 的正弦值。
double asin(double x) 返回 x 的反正弦值。
double cos(double x) 返回 x 的余弦值。
double acos(double x) 返回 x 的反余弦值。
double tan(double x) 返回 x 的正切值。
double atan(double x) 返回 x 的反正切值。
double rand() 返回 [0,1) 内的随机浮点数。
int rand32(int min, int max) 返回[min, max)内的一个随机 32 位整数。
用户可以只传入一个参数,该参数会判定为max,此时min默认为0
如果不传入参数,此时会从带符号的 32 位 int 范围内随机返回。
int rand64(int min, int max) 返回[min, max)内的一个随机 64 位整数。
用户可以只传入一个参数,该参数会判定为max,此时min默认为0
如果不传入参数,此时会从带符号的 64 位 int 范围内随机返回。
collect() 将收集的所有值放在一个列表中。
avg() 返回参数的平均值。
count() 返回参数的数量。
max() 返回参数的最大值。
min() 返回参数的最小值。
std() 返回参数的总体标准差。
sum() 返回参数的和。
bit_and() 逐位做 AND 操作。
bit_or() 逐位做 OR 操作。
bit_xor() 逐位做 XOR 操作。
int size() 返回列表或映射中元素的数量。
int range(int start, int end, int step) 返回[start,end]中指定步长的值组成的列表。步长step默认为 1。
int sign(double x) 返回 x 的正负号。
如果 x 为0,则返回0
如果 x 为负数,则返回-1
如果 x 为正数,则返回1
double e() 返回自然对数的底 e(2.718281828459045)。
double pi() 返回数学常数π(3.141592653589793)。
double radians() 将角度转换为弧度。radians(180)返回3.141592653589793

Note

如果参数为NULL,则输出结果是未定义的。

示例

# 支持聚合函数
nebula>  GO FROM "player100" OVER follow YIELD dst(edge) AS dst, properties($$).age AS age \
         | GROUP BY $-.dst \
         YIELD \
         $-.dst AS dst, \
         toInteger((sum($-.age)/count($-.age)))+avg(distinct $-.age+1)+1 AS statistics;
+-------------+------------+
| dst         | statistics |
+-------------+------------+
| "player125" | 84.0       |
| "player101" | 74.0       |
+-------------+------------+
Got 2 rows (time spent 4739/5064 us)

最后更新: June 20, 2023