DataFusion Functions
This page is generated from the Apache DataFusion project's documents:
- DataFusion Scalar Functions
- DataFusion Aggregate Functions
- DataFusion Window Functions
- DataFusion Special Functions
Scalar Functions
Math Functions
- abs
- acos
- acosh
- asin
- asinh
- atan
- atan2
- atanh
- cbrt
- ceil
- cos
- cosh
- cot
- degrees
- exp
- factorial
- floor
- gcd
- isnan
- iszero
- lcm
- ln
- log
- log10
- log2
- nanvl
- pi
- pow
- power
- radians
- random
- round
- signum
- sin
- sinh
- sqrt
- tan
- tanh
- trunc
abs
Returns the absolute value of a number.
abs(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT abs(-5);
+----------+
| abs(-5) |
+----------+
| 5 |
+----------+
acos
Returns the arc cosine or inverse cosine of a number.
acos(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT acos(1);
+----------+
| acos(1) |
+----------+
| 0.0 |
+----------+
acosh
Returns the area hyperbolic cosine or inverse hyperbolic cosine of a number.
acosh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT acosh(2);
+------------+
| acosh(2) |
+------------+
| 1.31696 |
+------------+
asin
Returns the arc sine or inverse sine of a number.
asin(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT asin(0.5);
+------------+
| asin(0.5) |
+------------+
| 0.5235988 |
+------------+
asinh
Returns the area hyperbolic sine or inverse hyperbolic sine of a number.
asinh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT asinh(1);
+------------+
| asinh(1) |
+------------+
| 0.8813736 |
+------------+
atan
Returns the arc tangent or inverse tangent of a number.
atan(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT atan(1);
+-----------+
| atan(1) |
+-----------+
| 0.7853982 |
+-----------+
atan2
Returns the arc tangent or inverse tangent of expression_y / expression_x.
atan2(expression_y, expression_x)
Arguments
- expression_y: First numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
- expression_x: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
Example
> SELECT atan2(1, 1);
+------------+
| atan2(1,1) |
+------------+
| 0.7853982 |
+------------+
atanh
Returns the area hyperbolic tangent or inverse hyperbolic tangent of a number.
atanh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT atanh(0.5);
+-------------+
| atanh(0.5) |
+-------------+
| 0.5493061 |
+-------------+
cbrt
Returns the cube root of a number.
cbrt(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT cbrt(27);
+-----------+
| cbrt(27) |
+-----------+
| 3.0 |
+-----------+
ceil
Returns the nearest integer greater than or equal to a number.
ceil(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT ceil(3.14);
+------------+
| ceil(3.14) |
+------------+
| 4.0 |
+------------+
cos
Returns the cosine of a number.
cos(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT cos(0);
+--------+
| cos(0) |
+--------+
| 1.0 |
+--------+
cosh
Returns the hyperbolic cosine of a number.
cosh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT cosh(1);
+-----------+
| cosh(1) |
+-----------+
| 1.5430806 |
+-----------+
cot
Returns the cotangent of a number.
cot(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT cot(1);
+---------+
| cot(1) |
+---------+
| 0.64209 |
+---------+
degrees
Converts radians to degrees.
degrees(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT degrees(pi());
+------------+
| degrees(0) |
+------------+
| 180.0 |
+------------+
exp
Returns the base-e exponential of a number.
exp(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT exp(1);
+---------+
| exp(1) |
+---------+
| 2.71828 |
+---------+
factorial
Factorial. Returns 1 if value is less than 2.
factorial(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT factorial(5);
+---------------+
| factorial(5) |
+---------------+
| 120 |
+---------------+
floor
Returns the nearest integer less than or equal to a number.
floor(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT floor(3.14);
+-------------+
| floor(3.14) |
+-------------+
| 3.0 |
+-------------+
gcd
Returns the greatest common divisor of expression_x and expression_y. Returns 0 if both inputs are zero.
gcd(expression_x, expression_y)
Arguments
- expression_x: First numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- expression_y: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT gcd(48, 18);
+------------+
| gcd(48,18) |
+------------+
| 6 |
+------------+
isnan
Returns true if a given number is +NaN or -NaN otherwise returns false.
isnan(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT isnan(1);
+----------+
| isnan(1) |
+----------+
| false |
+----------+
iszero
Returns true if a given number is +0.0 or -0.0 otherwise returns false.
iszero(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT iszero(0);
+------------+
| iszero(0) |
+------------+
| true |
+------------+
lcm
Returns the least common multiple of expression_x and expression_y. Returns 0 if either input is zero.
lcm(expression_x, expression_y)
Arguments
- expression_x: First numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- expression_y: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT lcm(4, 5);
+----------+
| lcm(4,5) |
+----------+
| 20 |
+----------+
ln
Returns the natural logarithm of a number.
ln(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT ln(2.71828);
+-------------+
| ln(2.71828) |
+-------------+
| 1.0 |
+-------------+
log
Returns the base-x logarithm of a number. Can either provide a specified base, or if omitted then takes the base-10 of a number.
log(base, numeric_expression)
log(numeric_expression)
Arguments
- base: Base numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT log(10);
+---------+
| log(10) |
+---------+
| 1.0 |
+---------+
log10
Returns the base-10 logarithm of a number.
log10(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT log10(100);
+-------------+
| log10(100) |
+-------------+
| 2.0 |
+-------------+
log2
Returns the base-2 logarithm of a number.
log2(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT log2(8);
+-----------+
| log2(8) |
+-----------+
| 3.0 |
+-----------+
nanvl
Returns the first argument if it's not NaN. Returns the second argument otherwise.
nanvl(expression_x, expression_y)
Arguments
- expression_x: Numeric expression to return if it's not NaN. Can be a constant, column, or function, and any combination of arithmetic operators.
- expression_y: Numeric expression to return if the first expression is NaN. Can be a constant, column, or function, and any combination of arithmetic operators.
Example
> SELECT nanvl(0, 5);
+------------+
| nanvl(0,5) |
+------------+
| 0 |
+------------+
pi
Returns an approximate value of π.
pi()
pow
Alias of power.
power
Returns a base expression raised to the power of an exponent.
power(base, exponent)
Arguments
- base: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- exponent: Exponent numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT power(2, 3);
+-------------+
| power(2,3) |
+-------------+
| 8 |
+-------------+
Aliases
- pow
radians
Converts degrees to radians.
radians(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT radians(180);
+----------------+
| radians(180) |
+----------------+
| 3.14159265359 |
+----------------+
random
Returns a random float value in the range [0, 1). The random seed is unique to each row.
random()
Example
> SELECT random();
+------------------+
| random() |
+------------------+
| 0.7389238902938 |
+------------------+
round
Rounds a number to the nearest integer.
round(numeric_expression[, decimal_places])
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- decimal_places: Optional. The number of decimal places to round to. Defaults to 0.
Example
> SELECT round(3.14159);
+--------------+
| round(3.14159)|
+--------------+
| 3.0 |
+--------------+
signum
Returns the sign of a number.
Negative numbers return -1.
Zero and positive numbers return 1.
signum(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT signum(-42);
+-------------+
| signum(-42) |
+-------------+
| -1 |
+-------------+
sin
Returns the sine of a number.
sin(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT sin(0);
+----------+
| sin(0) |
+----------+
| 0.0 |
+----------+
sinh
Returns the hyperbolic sine of a number.
sinh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT sinh(1);
+-----------+
| sinh(1) |
+-----------+
| 1.1752012 |
+-----------+
sqrt
Returns the square root of a number.
sqrt(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
tan
Returns the tangent of a number.
tan(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT tan(pi()/4);
+--------------+
| tan(PI()/4) |
+--------------+
| 1.0 |
+--------------+
tanh
Returns the hyperbolic tangent of a number.
tanh(numeric_expression)
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
Example
> SELECT tanh(20);
+----------+
| tanh(20) |
+----------+
| 1.0 |
+----------+
trunc
Truncates a number to a whole number or truncated to the specified decimal places.
trunc(numeric_expression[, decimal_places])
Arguments
- numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.
- decimal_places: Optional. The number of decimal places to
truncate to. Defaults to 0 (truncate to a whole number). If
decimal_placesis a positive integer, truncates digits to the right of the decimal point. Ifdecimal_placesis a negative integer, replaces digits to the left of the decimal point with0.
Example
> SELECT trunc(42.738);
+----------------+
| trunc(42.738) |
+----------------+
| 42 |
+----------------+