runSuite.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use File::Basename;
  5. # PROTOTYPES
  6. sub dieWithUsage(;$);
  7. # GLOBALS
  8. my $SCRIPT_NAME = basename( __FILE__ );
  9. my $SCRIPT_PATH = dirname( __FILE__ );
  10. # MAIN
  11. dieWithUsage("one or more parameters not defined") unless @ARGV >= 1;
  12. my $suite = shift;
  13. my $scale = shift || 2;
  14. dieWithUsage("suite name required") unless $suite eq "tpcds" or $suite eq "tpch";
  15. chdir $SCRIPT_PATH;
  16. if( $suite eq 'tpcds' ) {
  17. chdir "sample-queries-tpcds";
  18. } else {
  19. chdir 'sample-queries-tpch';
  20. } # end if
  21. my @queries = glob '*.sql';
  22. my $db = {
  23. 'tpcds' => "tpcds_bin_partitioned_orc_$scale",
  24. 'tpch' => "tpch_flat_orc_$scale"
  25. };
  26. print "filename,status,time,rows\n";
  27. for my $query ( @queries ) {
  28. my $logname = "$query.log";
  29. my $cmd="echo 'use $db->{${suite}}; source $query;' | hive -i testbench.settings 2>&1 | tee $query.log";
  30. # my $cmd="cat $query.log";
  31. #print $cmd ; exit;
  32. my $hiveStart = time();
  33. my @hiveoutput=`$cmd`;
  34. die "${SCRIPT_NAME}:: ERROR: hive command unexpectedly exited \$? = '$?', \$! = '$!'" if $?;
  35. my $hiveEnd = time();
  36. my $hiveTime = $hiveEnd - $hiveStart;
  37. foreach my $line ( @hiveoutput ) {
  38. if( $line =~ /Time taken:\s+([\d\.]+)\s+seconds,\s+Fetched:\s+(\d+)\s+row/ ) {
  39. print "$query,success,$hiveTime,$2\n";
  40. } elsif(
  41. $line =~ /^FAILED: /
  42. # || /Task failed!/
  43. ) {
  44. print "$query,failed,$hiveTime\n";
  45. } # end if
  46. } # end while
  47. } # end for
  48. sub dieWithUsage(;$) {
  49. my $err = shift || '';
  50. if( $err ne '' ) {
  51. chomp $err;
  52. $err = "ERROR: $err\n\n";
  53. } # end if
  54. print STDERR <<USAGE;
  55. ${err}Usage:
  56. perl ${SCRIPT_NAME} [tpcds|tpch] [scale]
  57. Description:
  58. This script runs the sample queries and outputs a CSV file of the time it took each query to run. Also, all hive output is kept as a log file named 'queryXX.sql.log' for each query file of the form 'queryXX.sql'. Defaults to scale of 2.
  59. USAGE
  60. exit 1;
  61. }