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



What is ROUND() function in Apache Pig ?

  • The ROUND() function returns a number rounded to a given number of digits.
  • The ROUND() function can round to the right or left of the decimal point.
  • The ROUND() function is used to get the value of an expression rounded to an integer (if the result type is float) or rounded to a long (if the result type is double).
 Apache Pig round

Learn Apache Pig - Apache Pig tutorial - Apache Pig round - Apache Pig examples - Apache Pig programs

Syntax

grunt> ROUND()

Example

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

wikitechy_math.txt

7
18 
11 
4.5 
7.9 
5.1 
  • You have loaded this file into Pig with a relation named math_data as given below.
grunt> math_data = LOAD 'hdfs://localhost:9000/pig_data/wikitechy_math.txt' USING PigStorage(',')
   as (data:float);
  • Now you can calculate round values of the contents of the wikitechy_math.txt file using ROUND() function as given below.
grunt> round_data = foreach math_data generate (data), ROUND(data);

Verification

  • Verify the contents of the relation using the Dump operator as given below.
grunt> Dump round_data;

Output

  • ยท The above statement stores the result in the relation named round_data.
(7.0,7) 
(18.0,18) 
(11.0,11) 
(4.5,5) 
(7.9,8) 
(5.1,5) 


Related Searches to Apache Pig ROUND()