tpch-setup.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. function usage {
  3. echo "Usage: tpch-setup.sh scale_factor [temp_directory]"
  4. exit 1
  5. }
  6. function runcommand {
  7. if [ "X$DEBUG_SCRIPT" != "X" ]; then
  8. $1
  9. else
  10. $1 2>/dev/null
  11. fi
  12. }
  13. if [ ! -f tpch-gen/target/tpch-gen-1.0-SNAPSHOT.jar ]; then
  14. echo "Please build the data generator with ./tpch-build.sh first"
  15. exit 1
  16. fi
  17. which hive > /dev/null 2>&1
  18. if [ $? -ne 0 ]; then
  19. echo "Script must be run where Hive is installed"
  20. exit 1
  21. fi
  22. # Tables in the TPC-H schema.
  23. TABLES="part partsupp supplier customer orders lineitem nation region"
  24. # Get the parameters.
  25. SCALE=$1
  26. DIR=$2
  27. BUCKETS=13
  28. if [ "X$DEBUG_SCRIPT" != "X" ]; then
  29. set -x
  30. fi
  31. # Sanity checking.
  32. if [ X"$SCALE" = "X" ]; then
  33. usage
  34. fi
  35. if [ X"$DIR" = "X" ]; then
  36. DIR=/tmp/tpch-generate
  37. fi
  38. if [ $SCALE -eq 1 ]; then
  39. echo "Scale factor must be greater than 1"
  40. exit 1
  41. fi
  42. # Do the actual data load.
  43. hdfs dfs -mkdir -p ${DIR}
  44. hdfs dfs -ls ${DIR}/${SCALE} > /dev/null
  45. if [ $? -ne 0 ]; then
  46. echo "Generating data at scale factor $SCALE."
  47. (cd tpch-gen; hadoop jar target/*.jar -d ${DIR}/${SCALE}/ -s ${SCALE})
  48. fi
  49. hdfs dfs -ls ${DIR}/${SCALE} > /dev/null
  50. if [ $? -ne 0 ]; then
  51. echo "Data generation failed, exiting."
  52. exit 1
  53. fi
  54. echo "TPC-H text data generation complete."
  55. # Create the text/flat tables as external tables. These will be later be converted to ORCFile.
  56. echo "Loading text data into external tables."
  57. runcommand "hive -i settings/load-flat.sql -f ddl-tpch/bin_flat/alltables.sql -d DB=tpch_text_${SCALE} -d LOCATION=${DIR}/${SCALE}"
  58. # Create the optimized tables.
  59. i=1
  60. total=8
  61. DATABASE=tpch_bin_partitioned_orc_${SCALE}
  62. for t in ${TABLES}
  63. do
  64. echo "Optimizing table $t ($i/$total)."
  65. COMMAND="hive -i settings/load-flat.sql -f ddl-tpch/bin_flat/${t}.sql \
  66. -d DB=tpch_bin_flat_orc_${SCALE} \
  67. -d SOURCE=tpch_text_${SCALE} -d BUCKETS=${BUCKETS} \
  68. -d FILE=orc"
  69. runcommand "$COMMAND"
  70. if [ $? -ne 0 ]; then
  71. echo "Command failed, try 'export DEBUG_SCRIPT=ON' and re-running"
  72. exit 1
  73. fi
  74. i=`expr $i + 1`
  75. done
  76. echo "Data loaded into database ${DATABASE}."