-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcreate_db.sh
More file actions
executable file
·44 lines (36 loc) · 789 Bytes
/
create_db.sh
File metadata and controls
executable file
·44 lines (36 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
TABLES=$@
db="TPC-H.db"
if [ -z "$TABLES" ]; then
echo "Error! No table specified." >&2
echo "Usage: $0 [TABLE_NAME] [TABLE_NAME]..." >&2
exit 1
fi
rm -f "$db"
echo "Creating the database structure..." >&2
sqlite3 "$db" < sqlite-ddl.sql
RET_CODE=0
for table in $TABLES; do
echo "Importing table '$table'..." >&2
data_file="tpch-dbgen/$table.tbl"
if [ ! -e "$data_file" ]; then
echo "'$data_file' does’nt exist. Skipping..." >&2
RET_CODE=1
continue
fi
fifo=$(mktemp -u)
mkfifo $fifo
sed -e 's/|$//' < "$data_file" > "$fifo" &
(
echo ".mode csv";
echo ".separator |";
echo -n ".import $fifo ";
echo $table | tr a-z A-Z;
) | sqlite3 "$db"
rm $fifo
if [ $? != 0 ]; then
echo "Import failed." >&2
RET_CODE=1
fi
done
exit $RET_CODE