tpcds-setup.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. function usage {
  3. echo "Usage: tpcds-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. BOLD=`tput bold`
  14. NORMAL=`tput sgr0`
  15. if [ ! -f tpcds-gen/target/tpcds-gen-1.0-SNAPSHOT.jar ]; then
  16. echo "Please build the data generator with ./tpcds-build.sh first"
  17. exit 1
  18. fi
  19. which hive > /dev/null 2>&1
  20. if [ $? -ne 0 ]; then
  21. echo "Script must be run where Hive is installed"
  22. exit 1
  23. fi
  24. # Tables in the TPC-DS schema.
  25. DIMS="date_dim time_dim item customer customer_demographics household_demographics customer_address store promotion warehouse ship_mode reason income_band call_center web_page catalog_page web_site"
  26. FACTS="store_sales store_returns web_sales web_returns catalog_sales catalog_returns inventory"
  27. # Get the parameters.
  28. SCALE=$1
  29. DIR=$2
  30. BUCKETS=13
  31. RETURN_BUCKETS=13
  32. if [ "X$DEBUG_SCRIPT" != "X" ]; then
  33. set -x
  34. fi
  35. # Sanity checking.
  36. if [ X"$SCALE" = "X" ]; then
  37. usage
  38. fi
  39. if [ X"$DIR" = "X" ]; then
  40. DIR=/tmp/tpcds-generate
  41. fi
  42. if [ $SCALE -eq 1 ]; then
  43. echo "Scale factor must be greater than 1"
  44. exit 1
  45. fi
  46. # Do the actual data load.
  47. hdfs dfs -mkdir -p ${DIR}
  48. hdfs dfs -ls ${DIR}/${SCALE} > /dev/null
  49. if [ $? -ne 0 ]; then
  50. echo "${BOLD}Generating data at scale factor $SCALE.${NORMAL}"
  51. (cd tpcds-gen; hadoop jar target/*.jar -d ${DIR}/${SCALE}/ -s ${SCALE})
  52. fi
  53. hdfs dfs -ls ${DIR}/${SCALE} > /dev/null
  54. if [ $? -ne 0 ]; then
  55. echo "${BOLD}Data generation failed, exiting.${NORMAL}"
  56. exit 1
  57. fi
  58. echo "${BOLD}TPC-DS text data generation complete.${NORMAL}"
  59. # Create the text/flat tables as external tables. These will be later be converted to ORCFile.
  60. echo "${BOLD}Loading text data into external tables.${NORMAL}"
  61. runcommand "hive -i settings/load-flat.sql -f ddl-tpcds/text/alltables.sql -d DB=tpcds_text_${SCALE} -d LOCATION=${DIR}/${SCALE}"
  62. # Create the partitioned and bucketed tables.
  63. i=1
  64. total=24
  65. DATABASE=tpcds_bin_partitioned_orc_${SCALE}
  66. for t in ${FACTS}
  67. do
  68. echo "${BOLD}Optimizing table $t ($i/$total).${NORMAL}"
  69. COMMAND="hive -i settings/load-partitioned.sql -f ddl-tpcds/bin_partitioned/${t}.sql \
  70. -d DB=tpcds_bin_partitioned_orc_${SCALE} \
  71. -d SOURCE=tpcds_text_${SCALE} -d BUCKETS=${BUCKETS} \
  72. -d RETURN_BUCKETS=${RETURN_BUCKETS} -d FILE=orc"
  73. runcommand "$COMMAND"
  74. if [ $? -ne 0 ]; then
  75. echo "Command failed, try 'export DEBUG_SCRIPT=ON' and re-running"
  76. exit 1
  77. fi
  78. i=`expr $i + 1`
  79. done
  80. # Populate the smaller tables.
  81. for t in ${DIMS}
  82. do
  83. echo "${BOLD}Optimizing table $t ($i/$total).${NORMAL}"
  84. COMMAND="hive -i settings/load-partitioned.sql -f ddl-tpcds/bin_partitioned/${t}.sql \
  85. -d DB=tpcds_bin_partitioned_orc_${SCALE} -d SOURCE=tpcds_text_${SCALE} \
  86. -d FILE=orc"
  87. runcommand "$COMMAND"
  88. if [ $? -ne 0 ]; then
  89. echo "Command failed, try 'export DEBUG_SCRIPT=ON' and re-running"
  90. exit 1
  91. fi
  92. i=`expr $i + 1`
  93. done
  94. echo "${BOLD}Data loaded into database ${DATABASE}.${NORMAL}"