-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeSchema.sh
executable file
·71 lines (61 loc) · 2.08 KB
/
makeSchema.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# 1. colltect samples from CSV
# 2. sniff/guess content-types
# 3. generate SQL-Statements
# 4. threaded exec
mkdir -p schemas
echo -n "" > cmds.list
echo -n "" > pumps.list
headz=$(cat database/tableNames.txt)
for _file in $(ls tables/*.csv | sed 's/^tables\///'); do
OUT="schemas/${_file}.sql"
IN="tables/${_file}"
if test -f "$OUT"; then
echo -n "" #echo "skipped: $IN"
else
res=$(eval "head -n 1 $IN | sed 's/,*$//g' | sed 's/\"//g'")
table=$(eval "grep \"###${res}\" database/tableNames.txt")
tableName=$(eval "echo \"$table\" | head -n1 | sed 's/##.*//g' ") # subtr before###
echo $IN
if [ "$tableName" == "" ]; then
echo "no table for file: $IN $res ${tableName}"
now=$(date +%s)
tableName="none_${now}"
fi
# CMD="\"xsv sample 100000 ${IN} | csvsql --dialect mysql --snifflimit 100000 -z 9261072 --tables $tableName > schemas/${tableName}.sql"\"
# csvsql --overwrite --snifflimit 1000 -z 9261072 --tables BANK --db mysql+mysqlconnector://user:pass@localhost:3306/cb --insert tables/table_1-166.csv
CMD=$(cat <<EOF
"xsv sample 100000 ${IN} | csvsql --dialect mysql --snifflimit 100000 -z 9261072 --tables $tableName > schemas/${tableName}.sql"
EOF
)
TRANS=$(cat <<EOF
"cp ${IN} trans/${tableName}.csv"
EOF
)
PUMP=$(cat <<EOF
"echo ${tableName} ; csvsql --overwrite --tables ${tableName} --db mysql+mysqlconnector://user:pass@localhost:3306/cb --insert ${IN}"
EOF
)
echo $TRANS >> trans.list
echo $CMD >> cmds.list
echo $PUMP >> pumps.list
#echo $tableName
#echo $cmd >> cmds.list
ret=$?
if [ $ret -eq 0 ]; then
echo -n ""
else
echo "\tTerror!! $ret $res"
#rm $OUT
exit
fi
fi
done;
#find schemas -empty -iname "*.sql" -exec rm {} \;
#find schemas -empty -iname "*.sql"
# for file in $(ls schemas/*.sql); do
# sed -i 's/`ID` DECIMAL(38, 0) NOT NULL,/`ID` BIGINT NOT NULL AUTO_INCREMENT,/g' schemas/$file;
# sed -i 's///g' schemas/file;
# done
echo "cat cmds.list | xargs -I{} -n 1 -P 6 ./exec_eval.sh {}"
echo "cat pumps.list | xargs -I{} -n 1 -P 6 ./exec_eval.sh {}"