#!/bin/bash
# The only one parameter is the stream ID
set -e
# start date
startdate=`date +%m-%d-%H:%M:%S.%2N`
echo "Stream $1 start date: ${startdate}"  
echo "Stream $1 start date: ${startdate}"  > ./logs/stream_$1.log

# Add config options to test sql.
cat config > ./test_sqls/query_$1.sql
cat ./SQLs/query_$1.sql >> ./test_sqls/query_$1.sql

# Distinct the output tables/files for different stream
sed -i "s|STREAMID|$1|g"  ./test_sqls/query_$1.sql

# Run the sql one by one
beeline -u jdbc:hive2://localhost:10000 --maxWidth=1000 -f ./test_sqls/query_$1.sql  >> ./logs/stream_$1.log 2>&1

# end date
enddate=`date +%m-%d-%H:%M:%S.%2N`
echo "Stream $1 end date: ${enddate}"  
echo "Stream $1 end date: ${enddate}"   >> ./logs/stream_$1.log

