PageRenderTime 29ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/testutils/compute_stats

#
#! | 36 lines | 33 code | 3 blank | 0 comment | 0 complexity | ddbc4146ca76bb4285a5f753325961ba MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. if [ "$1" = '' ]; then
  2. echo "Usage: compute_stats '<table_name>(<comma separated column list>)'"
  3. exit 1
  4. fi
  5. d=`mktemp -d compute_stats_XXXX`
  6. echo -n "Removing hive temp tables from previous runs if any..."
  7. test=`/mnt/vol/hive/stable/cluster/bin/hadoop dfs -ls compute_stats_test 2>>$d/err`
  8. if [ "$test" != '' ]; then
  9. /mnt/vol/hive/stable/cluster/bin/hadoop dfs -rmr compute_stats_test >>$d/err 2>&1
  10. /mnt/vol/hive/stable/cluster/bin/hadoop dfs -rmr /Trash/Current/compute_stats_test >> $d/err 2>&1
  11. fi
  12. echo "Done"
  13. echo -n "Project out columns to test table using hive..."
  14. /mnt/vol/hive/stable/cluster/bin/hadoop jar /mnt/vol/hive/stable/lib/hive/fb_hive.jar com.facebook.hive.streaming.HiveStreaming -select $1 -sample 1/1024 -output compute_stats_test -numReduceTasks 0 >> $d/err 2>&1
  15. echo "Done"
  16. test=`/mnt/vol/hive/stable/cluster/bin/hadoop dfs -ls compute_stats_test 2>>$d/err`
  17. if [ "$test" != '' ]; then
  18. echo -n "Generate single local file out of hdfs table..."
  19. /mnt/vol/hive/stable/cluster/bin/hadoop dfs -cat /user/`whoami`/compute_stats_test/* 2>>$d/err | gzip > $d/sample.gz
  20. echo "Done"
  21. n=`zcat $d/sample.gz | head -1 | tr ',' '\n' | wc -l`
  22. echo "Generate stats for each of the projected columns..."
  23. for ((i=1;i<=$n;i+=1)); do
  24. echo " column $i"
  25. zcat $d/sample.gz | cut -f$i -d',' | sort | uniq -c > $d/$i.stats;
  26. count=`cat $d/$i.stats | wc -l`;
  27. echo $i $count >> $d/overall.stats;
  28. done
  29. echo "Done"
  30. echo "Stats in $d"
  31. else
  32. echo "Error extracting columns from table!";
  33. fi