Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the becustom domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home4/joyplace/public_html/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home4/joyplace/public_html/wp-includes/functions.php on line 6114

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home4/joyplace/public_html/wp-includes/functions.php:6114) in /home4/joyplace/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":620,"date":"2015-12-20T04:52:45","date_gmt":"2015-12-20T10:52:45","guid":{"rendered":"https:\/\/www.bigdatainrealworld.com\/?p=620"},"modified":"2023-03-29T07:38:41","modified_gmt":"2023-03-29T12:38:41","slug":"beginners-apache-pig-tutorial-ordering-records","status":"publish","type":"post","link":"https:\/\/www.bigdatainrealworld.com\/beginners-apache-pig-tutorial-ordering-records\/","title":{"rendered":"Apache Pig Tutorial – Ordering Records"},"content":{"rendered":"

Apache Pig Tutorial – Ordering Records<\/h1>\n

Goal of this tutorial is to learn Apache Pig concepts in a fast pace. So don\u2019t except lengthy posts. All posts will be short and sweet. Most posts will have (very short) \u201csee it in action\u201d video.<\/strong><\/span><\/p>\n

In the previous post<\/a> we look at how to group records and we also found average volume of stocks from year 2003. In this post we will see how to order or sort records using Apache Pig.<\/p>\n

First lets load, group and find the average volume of stocks symbol from year 2003.<\/p>\n

grunt> stocks = LOAD '\/user\/hirw\/input\/stocks' USING PigStorage(',') as (exchange:chararray, symbol:chararray, date:datetime, open:float, high:float, low:float, close:float, volume:int, adj_close:float);\n\ngrunt> filter_by_yr = FILTER stocks by GetYear(date) == 2003;\n\ngrunt> grp_by_sym = GROUP filter_by_yr BY symbol;\n\ngrunt> avg_volume = FOREACH grp_by_sym GENERATE group, ROUND(AVG(filter_by_yr.volume)) as avgvolume;<\/pre>\n

\u00a0Ordering Records<\/h2>\n

Use the ORDER operator to order the records. By default records are ordered in ascending order. Use DESC to order records in descending order.<\/p>\n

grunt>\u00a0avg_vol_ordered = ORDER avg_volume BY avgvolume DESC;<\/pre>\n

We can also choose to perform ordering with multiple columns . In the below instruction, the records will be ordered by symbol and the volume. In the below instruction group <\/span>\u00a0refers to the symbol column.<\/p>\n

grunt>\u00a0avg_vol_ordered = ORDER avg_volume BY group, avgvolume DESC;<\/pre>\n

Display Results<\/h2>\n
grunt> DUMP avg_vol_ordered;<\/pre>\n

\u00a0See It In Action<\/h2>\n