pig tutorial - apache pig tutorial - Apache Pig - EXP() - pig latin - apache pig - pig hadoop



What is EXP() function?

  • The exponential function, exp(x), calculates the value of e to the power of x, where e is the base of the natural logarithm, 2.718281828... .
  • You can enter the command exp using either the 1-D or 2-D calling sequence.
  • For example, exp(-1) is equivalent to . ... exp(1) is used instead.
 exp function in apache pig

Learn apache pig - apache pig tutorial - exp function in apache pig - apache pig examples - apache pig programs

EXP() function in Apache Pig

  • The EXP() function of Pig Latin is used to get the Euler’s number e raised to the power of x for given expression.

Syntax:

grunt> EXP(expression)

Example:

  • Ensure that we have a file named wikitechy_exp.txt in the HDFS directory /pig_data/.
  • This file contains integer and floating point values as shown below.

Wikitechy_exp.txt

5 
16 
9 
2.5 
5.9 
3.1
  • You have loaded this file into Pig with a relation named exp_data as given below.
grunt> exp_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_exp.txt' USING PigStorage(',')
   as (data:float);
  • You compute the exp values of the contents of the wikitechy_exp.txt file using EXP() function as given below.
grunt> exp_data = foreach math_data generate (data), EXP(data);

The above statement stores the result in the relation named exp_data.

Verification:

  • Now you can verify the contents of the relation using the Dump operator as given below.
grunt> Dump exp_data;

Output:

The output shows that the result in the file>exp _data.

(5.0,148.4131591025766) 
(16.0,8886110.520507872) 
(9.0,8103.083927575384) 
(2.5,12.182493960703473) 
(5.9,365.0375026780162) 
(3.1,22.197949164480132) 

Related Searches to Apache Pig - EXP()