-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
289 lines (207 loc) · 8.42 KB
/
Copy pathtest.py
File metadata and controls
289 lines (207 loc) · 8.42 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
from datetime import datetime
from tabulate import tabulate
from decimal import Decimal
from colorama import Fore ,Style
from cassandra.cluster import Cluster
from cassandra.query import dict_factory
import distutils
import time
from distutils import util
def main():
#f = open("fdccontextids.txt", "w")
#for i in range(1,10001):
#f.write(str(i)+"\n")
#f.close()
cluster = Cluster(['rio.pdf.com'],port=9042)
session = cluster.connect()
session.execute("USE fdc_treateddata_cass;")
'''
f = open("fdccontextids.txt", "w")
rows = session.execute(' SELECT DISTINCT fdccontextid FROM treateddata LIMIT 10000;')
for row in rows:
f.write(str(row.fdccontextid)+"\n")
'''
f = open("fdccontextids.txt", "r")
content = f.read().splitlines()
query = 'select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid in ('
for fdc in content:
if fdc == content[-1]:
query += fdc +');'
else:
query += fdc + ','
time_1 = time.time()
pStatement = session.prepare(query)
rows = session.execute(pStatement)
# time to execute the query : 0.010839223861694336 seconds : without print
# time to execute the query : 250.32061100006104 seconds : with all row
# time to execute the query : 41.78741955757141 seconds :with jsut fdccontextid
#time.sleep(2)
for row in rows:
print(row.fdccontextid)
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
#print(content)
#print(f.readline())
#for x in f:
#print(x)
'''
query = 'select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid in ('
for fdc in content:
if fdc == content[-1]:
query += fdc +');'
else:
query += fdc + ','
print(type(content[0]))
ps = session.prepare('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid=?')
time1 = time.time()
for fdc in content:
future = session.execute_async(ps.bind([int(fdc)]))
try:
rows = future.result()
for row in rows:
print(row.fdccontextid)
except Exception:
print("error")
# '84.81679034233093 s' : with print
# '1.075 s' : without print
print((time.time())- time1)
'''
'''
try:
rows = future.result()
for row in rows:
print(row.fdccontextid)
except Exception:
print("error")
'''
'''
#print(query)
cluster = Cluster(['rio.pdf.com'],port=9042)
session = cluster.connect()
session.execute("USE fdc_treateddata_cass;")
pStatement = session.prepare(query)
time_1 = time.time()
rows = session.execute(pStatement)
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
print(tabulate(rows,tablefmt='pretty',headers='keys',showindex=True))
'''
'''
fdcs = ['589169','626069','638424','555165','579506','529509','553643','586462','403248','528165']
cluster = Cluster(['rio.pdf.com'],port=9042)
session = cluster.connect()
session.execute("USE fdc_treateddata_cass;")
time_1 = time.time()
for fdc in fdcs:
rows = session.execute('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid='+fdc+' ;')
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
print('---------------------------------')
time_3 = time.time()
rows = session.execute('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid in (589169,626069,638424,555165,579506) ;')
rows = session.execute('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid in (529509,553643,586462,403248,528165) ;')
time_4 = time.time()
time_interval2 = time_4 - time_3
print(Fore.RED+"time to execute the query : "+ str(time_interval2) +" seconds"+Style.RESET_ALL)
'''
#print(tabulate(rows,tablefmt='pretty',headers='keys',showindex=True))
"""
print(bool_value)
types1 = {'1':'text' , '2':'int' , '3':'date','4':'boolean','5':'UUID'}
types=types1.items()
#print(types1)
cluster = Cluster(['rio.pdf.com'],port=9042)
session = cluster.connect()
session.execute("USE test;")
session.row_factory = dict_factory
rows = session.execute("SELECT column_name, type FROM system_schema.columns WHERE keyspace_name = 'test' AND table_name = 'person';")
#print(tabulate(rows,tablefmt='pretty',headers='keys',showindex=True))
fields = {}
for row in rows:
print (row)
value = input("Insert the value of "+row['column_name']+"\n")
if row['type'] == 'int':
try:
val = int(value)
except ValueError:
print("That's not an int!")
elif row['type'] == 'date':
try:
datetime.datetime.strptime(value, '%Y-%m-%d')
except ValueError:
raise ValueError("Incorrect data format, should be YYYY-MM-DD")
fields[row['column_name']] = value
print(fields)
'''
YesNO = input("Do you want to view tables in keyspace[Y/N]?")
if YesNO == 'Y':
print("yes")
else:
pass
keyspace= 'test'
name ='person'
types1 = {'1':'text' , '2':'int' , '3':'date','4':'boolean','5':'UUID'}
types=types1.items()
fields = {}
Cname = input("Column Name : ")
while str(Cname) != 'e':
#and Cname != '':
if Cname != '':
print(tabulate(types, tablefmt='grid',colalign=("center",),stralign="center"))
type = input(Fore.CYAN+"Type number : "+Style.RESET_ALL)
if (type == '1' or type == '2' or type == '3' or type == '4' or type == '5'):
fields[Cname] = types1[type]
else:
print(Fore.RED+"Invalid Type"+Style.RESET_ALL)
continue
else :
print(Fore.RED+"Press 'e' to exit or try again ... "+Style.RESET_ALL)
Cname = input("Column Name : ")
pri_key = input(" what is the primary key? ")
statement1='CREATE TABLE IF NOT EXISTS '+keyspace+'.'+name+' '+' '
for key,value in fields.items():
if key == pri_key:
statement1 += key + ' '+ value + ' PRIMARY KEY'
else:
statement1 += key + ' '+ value
if value == list(fields.values())[-1]:
statement1 += ' ; '
else:
statement1 += ' , '
print(statement1)
a = 5
b = 10
count = 0
while count < a or count < b:
print(f"count: {count}, a: {a}, b: {b}")
count += 1
#type=[{"0","text"},{"1":"int"},{"2","bool"}]
types1 = {'1':'text' , '2':'int' , '3':'date','4':'boolean'}
types=types1.items()
print(tabulate(types, tablefmt='grid',colalign=("center",),stralign="center"))
fields = {}
Cname = input("Column Name : ")
while str(Cname) != 'e' : #and Cname != '':
if Cname != '':
print(tabulate(types, tablefmt='grid',colalign=("center",),stralign="center"))
type = input(Fore.CYAN+"Type number : "+Style.RESET_ALL)
if (type == '1' or type == '2' or type == '3' or type == '4'):
fields[Cname] = types1[type]
else:
print(Fore.RED+"Invalid Type"+Style.RESET_ALL)
continue
else :
print(Fore.RED+"Press 'e' to exit or try again ... "+Style.RESET_ALL)
Cname = input("Column Name : ")
print(fields)
'''
# print("hellow")
#a=[["name","id","gender"],['yousef','1','male'],['marah','2','female'],['adam','3','male']]
#print(tabulate(a,headers='firstrow',tablefmt='pretty',showindex=True,))
#value='marah'
# print("you entered {value} >> ")
"""
if __name__ == "__main__": main()