#!/bin/bash
set -e

# create text tables
beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_text_tables.sql       > ../logs/create_text.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created all text table at: ${thisdate}"
echo "created all text table at: ${thisdate}" >> ../logs/create_text.log

# load data to holodesk tables for test
beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_wr.sql       > ../logs/create_wr.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created web_returns at: ${thisdate}"
echo "created web_returns at: ${thisdate}" >> ../logs/create_wr.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_cs.sql     > ../logs/create_cs.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created catalog_sales at: ${thisdate}"
echo "created catalog_sales at: ${thisdate}" >> ../logs/create_cs.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_ss.sql       > ../logs/create_ss.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created store_sales at: ${thisdate}"
echo "created store_sales at: ${thisdate}" >> ../logs/create_ss.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_ws.sql         > ../logs/create_ws.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created web_sales at: ${thisdate}"
echo "created web_sales at: ${thisdate}" >> ../logs/create_ws.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_inv.sql         > ../logs/create_inv.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created inventory at: ${thisdate}"
echo "created inventory at: ${thisdate}" >> ../logs/create_inv.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_sr.sql     > ../logs/create_sr.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created store_returns at: ${thisdate}"
echo "created store_returns at: ${thisdate}" >> ../logs/create_sr.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_cr.sql   > ../logs/create_cr.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created catalog_returns at: ${thisdate}"
echo "created catalog_returns at: ${thisdate}" >> ../logs/create_cr.log

beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f  create_small_tables.sql      > ../logs/create_small_tables.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "created small_tables at: ${thisdate}"
echo "created small_tables at: ${thisdate}" >> ../logs/create_small_tables.log

# collect statistics 
./collect_statistics.sh > ../logs/staticstics.log 2>&1
thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "collected statistics at: ${thisdate}"
echo "collected statistics at: ${thisdate}" >> ../logs/staticstics.log

# collect row count for each table
beeline -u jdbc:hive2://localhost:10000  --maxWidth=1000 -f count_table_Qual.sql >../logs/row_count_qual.log 2>&1

thisdate=`date +%m-%d-%H:%M:%S.%2N`
echo "collected row count at: ${thisdate}"
echo "collected row count at: ${thisdate}" >> ../logs/row_count_qual.log
