josephxsxn

Pig Hive Table Layout Report

May 4th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. /*
  2.  
  3. INPUT for 'raw' is a hdfs dfs -ls -R $pathToTableOnHDFS
  4.  
  5.  
  6. (.{11} ) .* (\d*) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (\/project\/.*)
  7. (.{11} ) .* (\d*) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}) (\/project\/.*)\d{6}_\d.*
  8. */
  9.  
  10. raw = LOAD 'reports/in/$REPORT' using TextLoader();
  11. noStage = FILTER raw BY NOT($0 MATCHES '.*staging.*');
  12. columns = FOREACH noStage GENERATE FLATTEN(REGEX_EXTRACT_ALL($0, '(.{11}) .* (\\d*) (\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}) (\\/project\\/.*)\\d{6}_\\d.*'));
  13. --columns = FOREACH noStage GENERATE FLATTEN(REGEX_EXTRACT_ALL($0, '(.{11}) .* (\\d*) (\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}) (hdfs:\\/\\/hdp2cluster\\/project\\/.*)\\d{6}_\\d.*'));
  14. names = FOREACH columns GENERATE $0 as perms, (biginteger)$1 as bytes, $2 as timstim, $3 as part;
  15. noNullDirs = FILTER names BY NOT(perms is null) and NOT(perms matches 'd.*');
  16.  
  17. --TOTALS
  18. groupall = GROUP noNullDirs ALL;
  19. avgFileSize = FOREACH groupall GENERATE 'COMPLETE VIEW ', COUNT(noNullDirs.part) as fileCount, MIN(noNullDirs.bytes) as minBytes, AVG(noNullDirs.bytes) as avgBytes, MAX(noNullDirs.bytes) as maxBytes;
  20.  
  21. --Per Partition Info
  22. groupparts = GROUP noNullDirs by part;
  23. avgFilesPerPart = FOREACH groupparts GENERATE group, COUNT(noNullDirs.part) as fileCount, MIN(noNullDirs.bytes) as minBytes, AVG(noNullDirs.bytes) as avgBytes, MAX(noNullDirs.bytes) as maxBytes, SUM(noNullDirs.bytes) as partitionSize;
  24. mergable = FILTER avgFilesPerPart BY fileCount > 1;
  25.  
  26.  
  27. mergeordered = ORDER mergable by fileCount desc;
  28. top25merge = LIMIT mergeordered 25;
  29.  
  30.  
  31. --Partition Info
  32. partsProjection = FOREACH noNullDirs GENERATE part;
  33. distparts = DISTINCT partsProjection;
  34. distpartsgroup = GROUP distparts ALL;
  35. totalParts = FOREACH distpartsgroup GENERATE 'TOTAL PARTITION COUNT: ', COUNT(distparts.part);
  36.  
  37.  
  38. --Files Under 128mb
  39. smalls = FILTER noNullDirs BY bytes < 128000000;
  40. smallsgroup = GROUP smalls ALL;
  41. suboptFiles = FOREACH smallsgroup GENERATE 'TOTAL FILES UNDER 128MB: ', COUNT(smalls.bytes);
  42.  
  43.  
  44. --under 1mb
  45. micos = FILTER noNullDirs BY bytes < 1000000;
  46. micosgroup = GROUP micos ALL;
  47. micossuboptFiles = FOREACH micosgroup GENERATE 'TOTAL FILES UNDER 1MB: ', COUNT(micos.bytes);
  48.  
  49. --0 byte files
  50. zeros = FILTER noNullDirs BY bytes == 0;
  51. zerosgroup = GROUP zeros ALL;
  52. zerossuboptFiles = FOREACH zerosgroup GENERATE 'TOTAL FILES EQUAL TO 0 BYTES: ', COUNT(zeros.bytes);
  53.  
  54.  
  55.  
  56. --Files over 128mb
  57. bigs = FILTER noNullDirs BY bytes >= 128000000;
  58. bigsgroup = GROUP bigs ALL;
  59. bigssuboptFiles = FOREACH bigsgroup GENERATE 'TOTAL FILES OVER 1MB: ', COUNT(bigs.bytes);
  60.  
  61.  
  62. completeReport = UNION avgFileSize, totalParts, mergeordered, suboptFiles, micossuboptFiles, zerossuboptFiles, bigssuboptFiles;
  63.  
  64. store completeReport into 'reports/out/$REPORT';
  65.  
  66.  
  67. /*
  68.  
  69. TYPE // PARTITION COUNT MIN AVG MAX SUM
  70. COMPLETE VIEW 41030 45752 16841738.95 4390874709
  71. TOTAL FILES UNDER 128MB: 39454
  72. TOTAL FILES UNDER 1MB: 34688
  73. TOTAL PARTITION COUNT: 3085
  74. TOTAL FILES OVER 1MB: 1576
  75. /hte/region=NA/country=USA/date_x=1970-01-01/ 656 47734 411722.3018 172352750 270089830
  76. /hte/region=NA/country=UNKNOWN/date_x=1970-01-01/ 591 46928 132484.8376 45530519 78298539
  77.  
  78. TOTAL FILES UNDER 1MB: 931
  79. TOTAL PARTITION COUNT: 1
  80. TOTAL FILES UNDER 128MB: 945
  81. TOTAL FILES OVER 1MB: 99
  82. TOTAL FILES EQUAL TO 0 BYTES: 926
  83. COMPLETE VIEW 1044 0 108098305.1427203065134099616858238 3364497810
  84.  
  85. */
Advertisement
Add Comment
Please, Sign In to add comment