#!/bin/bash
BASEDIR=$(cd `dirname $0`;pwd -P)

DAT_DIR=$BASEDIR/tpc-ds_test_data10G

#drop tables if they are existed
for i in $(ls $DAT_DIR/*.dat)
do
        filename=$(echo $i | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}')
        echo "start dropping table $filename"
       	#./drop_tables.sh $filename
	mclient -s "drop table $filename;"
	echo "end dropping table $filename"
done

#create tables
#./create_tables.sh
mclient /home/monetdb/v2.6.0/tools/tpcds.sql
#load data
for i in $(ls $DAT_DIR/*.dat)
do
	filename=$(echo $i | awk -F '/' '{print $NF}' | awk -F '.' '{print $1}')
	#./autoinsert.sh $filename
	echo "start loading data to table $filename"
	mclient -s "copy into $filename from '$DAT_DIR/$filename.dat' using delimiters '|' null as '';"
	echo "end loading data to table $filename"
done
