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








沒有留言:
張貼留言