#!/bin/bash
set -e

rm -rf ./logs/*
rm -rf ./test_sqls/*

thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Start qualification test: ${thisdate}"

echo "-------gen data --------"
cd ../v2.11.0rc2/tools/ 
mkdir -p /mnt/disk2/data
rm -rf /mnt/disk2/data/*.dat

./dsdgen  -scale 1 -dir /mnt/disk2/data

thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "gen data at: ${thisdate}"
cd ../../QUALIFICATION-test/

./upload_quan.sh 
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Uploading to HDFS at: ${thisdate}"

cd ddl
./doLoad.sh
cd ../
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Finish create tables at : ${thisdate}"

echo "------------ run 99 sqls one by one--------------"

for(( i=1; i<=99; i++ ))
do
echo "  running query$i ... "
cat config > ./test_sqls/query$i.sql
cat query$i.sql >> ./test_sqls/query$i.sql
# Run the sql
beeline -u jdbc:hive2://localhost:10000 --maxWidth=1000 -f ./test_sqls/query$i.sql  > ./logs/query$i.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Finish run query ${i} at : ${thisdate}"
echo "Finish run query ${i} at : ${thisdate}" >> ./logs/query$i.log
done

thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Finish run 99 queries at : ${thisdate}"

