土芭樂數位學堂

BigData 大數據分析, 大數據平台建置及應用 (Hadoop/spark),虛擬核⼼技術,資訊技術的分享, TiddlyWiki教學, Google 服務應用教學, 3D列印創意思維

Pig Latin 練習題解答


grunt>movies = LOAD 'movies_data.csv' USING PigStorage(',') AS (id:int,name:chararray,year:int,rating:float,duration:int);
grunt>publicer = FILTER movies by (year == 1917);
grunt>dump publicer;





grunt>movies04= LOAD 'movies_data.csv' USING PigStorage(',') AS (id:int,name:chararray,year:int,rating:float,duration:int);
grunt>a= foreach movies04 generate duration,rating;
grunt>b= filter a by ($0 is not  null) and ($1 is not null);
grunt>dump b;




grunt>movies = LOAD 'movies_data.csv' USING PigStorage(',');
grunt>a = filter movies by ((int)$4>9000) and ((float)$3>=3.5) and ((float)$3<=4.5);
grunt>dump a;



答案 a:可以;b:由小到大遞增排序




grunt> movies = load ‘/dataset/movies_data.csv’ using PigStorage(‘,’);
// id,name,year, 星等,片長
grunt> b1 = ORDER movies by $4 DESC;
//大到小排序
grunt> b2 = LIMIT b1 1;
grunt> b3 = FOREACH b2 GENERATE $1;
grunt> dump b3;
說明:b.的作法與a.相同,只要改變排序的方式,即可找出答案




grunt> movies = load '/dataset/movies_data/movies_data.csv' using PigStorage(',');
grunt> c1 = ORDER movies by $3;
grunt> c2 = FOREACH c1 GENERATE $2;
grunt> c3 = DISTINCT c2;
grunt> dump c3;

以上問題都只是牛刀小試,接著我們再繼續進擊練習 GO

沒有留言:

張貼留言