[text] 4044

Viewer

  1. Big
  2. cat hive test.txt
  3. cp hivetest..txt pigtest.txt
  4. hdfs dfs -mkdir pigpractice
  5. hdfs dos -put pigtest.txt pigpractice
  6. hdfs dfs -ls pigpractice 
  7. pig
  8. grunt> student = LOAD ‘pigpractice/pigtest.txt’ USING PigStorage(‘,’)
  9. as (sid:int,sname:chararray,marks:int,course:chararray);
  10. ————-
  11. // displaying the data from a table. 
  12.  
  13. dump student;
  14. ————
  15. // copying the data from pig table to text file into HDFS. 
  16. STORE student INTO ‘pigpractoc/test’
  17. >> USING PigStorage(‘#’)
  18. or
  19. > STORE student INFO ‘pigpractice/test2’ USING PigStorage(‘\t’);
  20. ——————
  21. // display the resulted files in HDFS. 
  22. oracle: hdfs dfs -ls pigpractice/test
  23. or
  24. cloudera
  25. hdfs dfs -cat pigpractice/test2/part*
  26. —————
  27. // copy the text file from hdfs to linux 
  28. hdfs dfs -get pigpractice/test/part-m-00000
  29. cat part-m-0000
  30. ————
  31. //display the student data by grouping on course and store into the groupcourse bag 
  32. grunt> coursegroup = GROUP student BY course;
  33. grunt> dump coursedata;
  34. ——————
  35. //Display student name and marks with the alias column studentmarks from student bag and store into aliascoursedata bag. 
  36. grunt>coursedata = FOREACH student GENERATE sname AS studentname,marks AS aliascoursedata; 
  37. ——————
  38. grunt>coursedata = FOREACH student GENERATE sname AS studentname,marks AS aliascoursedata; 
  39.  
  40. grunt> studmarks = FILTER student BY marks > 90; 
  41. grunt> dump student;
  42. —————
  43. //Display student name and marks from student bag, who got more than 85 and store the result rows into bag studentmarks. 
  44.  
  45. studentmarks = FILTER (FOREACH student GENERATE sname,marks) BY marks > 85; 
  46.  
  47. ———-
  48. grunt>student5 = LIMIT student 5; 
  49. grunt>dump student5; 
  50. ————
  51. //display the student name, course and marks from student bag by grouping on course and store into the groupstud bag. 
  52.  
  53. grunt> groupstud = GROUP (FOREACH student GENERATE sname,course,marks) BY course; 
  54. grunt>dump groupstud
  55.  
  56. ———
  57. //Display all the students with the descending order on marks and store into bag studorder.
  58. grunt> studorder = ORDER student BY marks desc; 
  59. grunt> dump studorder;
  60.  
  61. ———
  62. display the student name, course and marks from student bag with the ascending order on marks and store into the studordernew bag. 
  63.  
  64. grunt> studordernew = ORDER (FOREACH student GENERATE sname,marks) BY marks ; 
  65. grunt> dump studordernew;
  66.  
  67. ————
  68. //Display all the students by grouping on course by using column index and store into bag temp. 
  69.  
  70. grunt> describe student;
  71. student:{sid: int,sname: chararray,marks: int,course: chararry}
  72. grunt> temp = GROUP student by $3;
  73. grunt> dump temp;
  74. ——————
  75. //Display all the course names and their corresponding highest marks for each course and store into bag temp1. 
  76.  
  77. grunt>describe temp;
  78. temp: {group: chararray,student: {(sid: int,sname: chararray,marks: int,course: chararay)}}
  79. grunt> temp1 = foreach temp generate group as grp, MAX(student.marks);
  80. Grunt>dump temp1;
  81. ——————
  82. //Using all aggregation functions store the result into bag groupresult 
  83. grunt> groupresult = foreach temp generate group,MAX(student.marks) as maxmarks,
  84. MIN(student.marks) as minmarks, SUM(student.marks) as totmarks,
  85. AVG(student.marks) as avgmarks, COUNT(student) as totalstudents;
  86.  
  87. grunt>describe groupresult;
  88. groupresult: {group: chararry,maxmarks: int,minmarks: int,totmarks: long,avgmarks: double,totals}
  89. grunt>dump group;
  90. ———
  91. //cogroup : Grouping the data from two tables with a common column. 
  92. nano
  93. sudo nano teacher.txt
  94. Hdfs dfs -put teacher.txt pigpractice

Editor

You can edit this paste and save as new:


File Description
  • 4044
  • Paste Code
  • 05 May-2024
  • 3.56 Kb
You can Share it: