-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_sql.py
32 lines (30 loc) · 1.07 KB
/
generate_sql.py
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
import numpy as np
import psycopg2
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('--partnum', default=5, type=int)
parser.add_argument('--keepnum', default=5000, type=int)
args = parser.parse_args()
current_path = os.getcwd()
conn = psycopg2.connect(database='geotweet', port='5433', user='anonymous')
conn.autocommit = True
cursor = conn.cursor()
partition_num = args.partnum
keep_num = args.keepnum
cursor.execute("drop table if exists geotweet_settrie_{};".format(partition_num, keep_num))
conn.commit()
sql = ""
sql += "create table geotweet_settrie_{}(".format(partition_num, keep_num)
sql += "createtime integer,"
sql += "lat double precision,"
sql += "lon double precision,"
sql += "country character varying,"
for i in range(partition_num):
sql += "tags{} integer,".format(i)
sql += "tags_lfword integer);"
cursor.execute(sql)
conn.commit()
sql = "copy geotweet_settrie_{} from \'{}/color_partition_{}/geotweet_approx_clique.csv\' DELIMITER \',\' HEADER CSV;".format(partition_num, current_path, partition_num)
cursor.execute(sql)
conn.commit()