Wednesday, 17 August 2022

Hive: Mathematical functions

 

Below table summarize the mathematical functions.

Function

Description

Example

abs(n)

Return absolute value of a number.

SELECT name,abs(rating) from emp;

acos(n)

Return arc cosine value of n.

SELECT name,acos(rating) from emp;

asin(n)

Return arc sin value of n

SELECT name,asin(rating) from emp;

atan(n)

Return arc tangent of a number

SELECT atan(109);

bin(n)

Return number in binary format.

SELECT name,gender_age.age,bin(gender_age.age) from emp;

ceil(n)

ceiling(n)

Return ceiling value of n

SELECT rating,ceil(rating),ceiling(rating) from emp;

conv(n, fromBase, toBase)

Convert number from one base to other base

SELECT name,gender_age.age,conv(gender_age.age,10,2) FROM emp;

 

cos(n)

Return cosine of the value.

SELECT rating,cos(rating) FROM emp;

degrees(n)

Convert radians to degrees.

SELECT degrees(90);

e()

Return the value of e.

SELECT e();

exp(n)

Return  e to the power n.

SELECT rating,exp(rating) FROM emp;

floor(n)

Return floor of this value.

SELECT rating, floor(rating) FROM emp;

hex(n)

Return hexadecimal of this number

SELECT gender_age.age,hex(gender_age.age) FROM emp;

hex(string)

Convert each character into hexadecimal format.

SELECT hex('ABC');

ln(n)

Return natural log of a number

SELECT ln(1.23);

log(base, n)

return logarithm of a number

SELECT 1000, log(1000, 10);

log2(n)

Return base-2 logarithm of the number n.

SELECT log2(10);

log10(n)

Return base 10 logarithm of a number

SELECT log10(100);

negative(n)

Negate the number, return -n

SELECT negative(10);

pi

Return the value of pi

SELECT pi()

pmod( int m, int n )

pmod( double m, double n )

Return positive modulus of a number

SELECT PMOD(10, 3);

positive(n)

This method return n.

select positive(10);

pow(m, n)

Return m to the power n

SELECT pow(10, 2);

radians(n)

Convert degrees to radins

SELECT radians(5156.620156177409);

rand(seed)

Return random number

SELECT rand(1000);

SELECT rand();

round( double value [, int n] )

round the double to n integer places

SELECT round(10.09872);

sign(n)

Return sign of a number. If the number is -ve, it return -1.0, for positive it return 1.0, 0.0 otherwise.

SELECT sign(10);

sin(n)

Return sin of a number

SELECT sin(10.09);

sqrt(n)

Square root of a number.

SELECT sqrt(16);

tan(n)

Return tangenet of a number.

SELECT tan(90);

unhex(string)

Inverse of hex function

SELECT unhex('ABCDDF');

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment