-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalyzeLogs.py
530 lines (507 loc) · 26.2 KB
/
analyzeLogs.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
from __future__ import division
import sys
import os
import time
import QueryExecution as QExec
from bitmap import BitMap
import CFCosineSim
import TupleIntent as ti
import ParseConfigFile as parseConfig
from ParseConfigFile import getConfig
import pickle
import argparse
from pandas import DataFrame
from openpyxl import load_workbook
import pandas as pd
def updateArrWithDictEntry(arr, evalOpsObjDict, epIndex, numOpQueryCountDict):
try:
arr.append(float(evalOpsObjDict[epIndex])/float(numOpQueryCountDict[epIndex]))
except:
arr.append("")
return
def updateArrWithCountEntry(arr, numOpQueryCountDict, key):
try:
arr.append(numOpQueryCountDict[key])
except:
arr.append(0.0)
return
def updateAggMetricWithDictEntry(avgMetric, evalOpsObjDict, epIndex):
try:
avgMetric += float(evalOpsObjDict[epIndex])
except:
avgMetric += 0.0
return avgMetric
def plotQueryTypeDistribution(evalOpsObj):
episodes = []
numSelectQueryType = []
numInsertQueryType = []
numUpdateQueryType = []
numDeleteQueryType = []
totalSelect = 0.0
totalInsert = 0.0
totalUpdate = 0.0
totalDelete = 0.0
for key in sorted(evalOpsObj.meanReciprocalRank.keys()):
episodes.append(key)
updateArrWithCountEntry(numSelectQueryType, evalOpsObj.numSelectQueryType, key)
updateArrWithCountEntry(numInsertQueryType, evalOpsObj.numInsertQueryType, key)
updateArrWithCountEntry(numUpdateQueryType, evalOpsObj.numUpdateQueryType, key)
updateArrWithCountEntry(numDeleteQueryType, evalOpsObj.numDeleteQueryType, key)
totalSelect = updateAggMetricWithDictEntry(totalSelect, evalOpsObj.numSelectQueryType, key)
totalInsert = updateAggMetricWithDictEntry(totalInsert, evalOpsObj.numInsertQueryType, key)
totalUpdate = updateAggMetricWithDictEntry(totalUpdate, evalOpsObj.numUpdateQueryType, key)
totalDelete = updateAggMetricWithDictEntry(totalDelete, evalOpsObj.numDeleteQueryType, key)
df = DataFrame(
{'episodes': episodes, '# SELECT': numSelectQueryType, '# INSERT': numInsertQueryType, '# UPDATE': numUpdateQueryType,
'# DELETE': numDeleteQueryType})
algoName = evalOpsObj.configDict['ALGORITHM']
if evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'True':
algoName = "NovelRNN"
elif evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'False':
algoName = "HistoricalRNN"
outputOpWiseQualityFileName = getConfig(evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/QTDist" + \
algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet1', index=False)
totalSelList = []
totalSelList.append(totalSelect)
totalInsList = []
totalInsList.append(totalInsert)
totalUpdList = []
totalUpdList.append(totalUpdate)
totalDelList = []
totalDelList.append(totalDelete)
df = DataFrame({'totalSEL': totalSelList, 'totalINS': totalInsList, 'totalUPD': totalUpdList, 'totalDEL': totalDelList})
outputOpWiseQualityFileName = getConfig(evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/TotalQT_" + \
algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet2', index=False)
return
def plotMeanReciprocalRank(evalOpsObj):
episodes = []
meanReciprocalRank = []
numEpQueries = []
avgMRR = 0.0
for key in sorted(evalOpsObj.meanReciprocalRank.keys()):
episodes.append(key)
updateArrWithCountEntry(numEpQueries, evalOpsObj.numEpQueries, key)
updateArrWithDictEntry(meanReciprocalRank, evalOpsObj.meanReciprocalRank, key, evalOpsObj.numEpQueries)
avgMRR = updateAggMetricWithDictEntry(avgMRR, evalOpsObj.meanReciprocalRank, key)
df = DataFrame(
{'episodes': episodes, 'meanReciprocalRank': meanReciprocalRank, 'numMRRQueries': numEpQueries})
algoName = evalOpsObj.configDict['ALGORITHM']
if evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'True':
algoName = "NovelRNN"
elif evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'False':
algoName = "HistoricalRNN"
outputOpWiseQualityFileName = getConfig(evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/Output_MRR_" + algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet1', index=False)
totalQueryCount = float(sum(numEpQueries))
if totalQueryCount > 0.0:
avgMRR = avgMRR / totalQueryCount
avgMRRList = []
avgMRRList.append(avgMRR)
totalQueryCountList = []
totalQueryCountList.append(totalQueryCount)
df = DataFrame({'avgMRR': avgMRRList, 'numMRRQueries': totalQueryCountList})
outputOpWiseQualityFileName = getConfig(evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/AggrOutput_MRR_" + algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet2', index=False)
return
def plotOp(evalOpsP, evalOpsR, evalOpsF, numOpQueryCountDict, evalOpsObj, opString):
episodes = []
resP = []
resR = []
resF = []
numEpQueries = []
avgResP = 0.0
avgResR = 0.0
avgResF = 0.0
for key in sorted(evalOpsObj.queryTypeP.keys()):
episodes.append(key)
updateArrWithCountEntry(numEpQueries, numOpQueryCountDict, key)
updateArrWithDictEntry(resP, evalOpsP, key, numOpQueryCountDict)
updateArrWithDictEntry(resR, evalOpsR, key, numOpQueryCountDict)
updateArrWithDictEntry(resF, evalOpsF, key, numOpQueryCountDict)
avgResP = updateAggMetricWithDictEntry(avgResP, evalOpsP, key)
avgResR = updateAggMetricWithDictEntry(avgResR, evalOpsR, key)
avgResF = updateAggMetricWithDictEntry(avgResF, evalOpsF, key)
headerP = evalOpsObj.configDict['ALGORITHM']+"(P)"
headerR = evalOpsObj.configDict['ALGORITHM']+"(R)"
headerF = evalOpsObj.configDict['ALGORITHM'] + "(F)"
headerQ = 'num'+opString+'Queries'
df = DataFrame(
{'episodes': episodes, headerP: resP, headerR: resR, headerF: resF, headerQ:numEpQueries})
algoName = evalOpsObj.configDict['ALGORITHM']
if evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'True':
algoName = "NovelRNN"
elif evalOpsObj.configDict['ALGORITHM'] == 'RNN' and evalOpsObj.configDict['RNN_PREDICT_NOVEL_QUERIES'] == 'False':
algoName = "HistoricalRNN"
outputOpWiseQualityFileName = getConfig(evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/Output_" + opString + "_" + \
algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet1', index=False)
totalQueryCount = float(sum(numEpQueries))
if totalQueryCount > 0.0:
avgResP = avgResP / totalQueryCount
avgResR = avgResR / totalQueryCount
avgResF = avgResF / totalQueryCount
avgResPList = []
avgResPList.append(avgResP)
avgResRList = []
avgResRList.append(avgResR)
avgResFList = []
avgResFList.append(avgResF)
totalQueryCountList = []
totalQueryCountList.append(totalQueryCount)
df = DataFrame({headerP: avgResPList, headerR: avgResRList, headerF: avgResFList, headerQ: totalQueryCountList})
outputOpWiseQualityFileName = getConfig(
evalOpsObj.configDict['OUTPUT_DIR']) + "/OpWiseExcel/AggrOutput_" + opString + "_" + algoName
df.to_excel(outputOpWiseQualityFileName + ".xlsx", sheet_name='sheet1', index=False)
return
def plotEvalMetricsOpWise(evalOpsObj):
plotQueryTypeDistribution(evalOpsObj)
plotMeanReciprocalRank(evalOpsObj)
plotOp(evalOpsObj.queryTypeP, evalOpsObj.queryTypeR, evalOpsObj.queryTypeF, evalOpsObj.numQueryTypeQueries, evalOpsObj, "QUERYTYPE")
plotOp(evalOpsObj.tablesP, evalOpsObj.tablesR, evalOpsObj.tablesF, evalOpsObj.numTablesQueries, evalOpsObj, "TABLES")
plotOp(evalOpsObj.projColsP, evalOpsObj.projColsR, evalOpsObj.projColsF, evalOpsObj.numProjColsQueries, evalOpsObj,
"PROJ")
plotOp(evalOpsObj.avgColsP, evalOpsObj.avgColsR, evalOpsObj.avgColsF, evalOpsObj.numAvgColsQueries, evalOpsObj,
"AVG")
plotOp(evalOpsObj.minColsP, evalOpsObj.minColsR, evalOpsObj.minColsF, evalOpsObj.numMinColsQueries, evalOpsObj,
"MIN")
plotOp(evalOpsObj.maxColsP, evalOpsObj.maxColsR, evalOpsObj.maxColsF, evalOpsObj.numMaxColsQueries, evalOpsObj,
"MAX")
plotOp(evalOpsObj.sumColsP, evalOpsObj.sumColsR, evalOpsObj.sumColsF, evalOpsObj.numSumColsQueries, evalOpsObj,
"SUM")
plotOp(evalOpsObj.countColsP, evalOpsObj.countColsR, evalOpsObj.countColsF, evalOpsObj.numCountColsQueries, evalOpsObj,
"COUNT")
plotOp(evalOpsObj.selColsP, evalOpsObj.selColsR, evalOpsObj.selColsF, evalOpsObj.numSelColsQueries, evalOpsObj,
"SEL")
plotOp(evalOpsObj.condSelColsP, evalOpsObj.condSelColsR, evalOpsObj.condSelColsF, evalOpsObj.numCondSelColsQueries, evalOpsObj,
"CONDSEL")
plotOp(evalOpsObj.groupByColsP, evalOpsObj.groupByColsR, evalOpsObj.groupByColsF, evalOpsObj.numGroupByColsQueries, evalOpsObj,
"GROUPBY")
plotOp(evalOpsObj.orderByColsP, evalOpsObj.orderByColsR, evalOpsObj.orderByColsF, evalOpsObj.numOrderByColsQueries, evalOpsObj,
"ORDERBY")
plotOp(evalOpsObj.havingColsP, evalOpsObj.havingColsR, evalOpsObj.havingColsF, evalOpsObj.numHavingColsQueries, evalOpsObj,
"HAVING")
plotOp(evalOpsObj.limitP, evalOpsObj.limitR, evalOpsObj.limitF, evalOpsObj.numLimitColsQueries, evalOpsObj,
"LIMIT")
plotOp(evalOpsObj.joinPredsP, evalOpsObj.joinPredsR, evalOpsObj.joinPredsF, evalOpsObj.numJoinPredsColsQueries, evalOpsObj,
"JOIN")
plotOp(evalOpsObj.condJoinPredsP, evalOpsObj.condJoinPredsR, evalOpsObj.condJoinPredsF, evalOpsObj.numCondJoinPredsColsQueries,
evalOpsObj,
"CONDJOIN")
return
class evalOps:
def __init__(self, configFileName, logFile):
self.configFileName = configFileName
self.configDict = parseConfig.parseConfigFile(configFileName)
self.logFile = logFile
self.curEpisode = 0
self.numSelectQueryType = {}
self.numInsertQueryType = {}
self.numUpdateQueryType = {}
self.numDeleteQueryType = {}
self.numEpQueries = {}
self.curQueryIndex = -1
self.meanReciprocalRank = {}
self.episode = {}
self.queryTypeP = {}
self.queryTypeR = {}
self.queryTypeF = {}
self.numQueryTypeQueries = {}
self.tablesP = {}
self.tablesR = {}
self.tablesF = {}
self.numTablesQueries = {}
self.projColsP = {}
self.projColsR = {}
self.projColsF = {}
self.numProjColsQueries = {}
self.avgColsP = {}
self.avgColsR = {}
self.avgColsF = {}
self.numAvgColsQueries = {}
self.minColsP = {}
self.minColsR = {}
self.minColsF = {}
self.numMinColsQueries = {}
self.maxColsP = {}
self.maxColsR = {}
self.maxColsF = {}
self.numMaxColsQueries = {}
self.sumColsP = {}
self.sumColsR = {}
self.sumColsF = {}
self.numSumColsQueries = {}
self.countColsP = {}
self.countColsR = {}
self.countColsF = {}
self.numCountColsQueries = {}
self.selColsP = {}
self.selColsR = {}
self.selColsF = {}
self.numSelColsQueries = {}
self.condSelColsP = {}
self.condSelColsR = {}
self.condSelColsF = {}
self.numCondSelColsQueries = {}
self.groupByColsP = {}
self.groupByColsR = {}
self.groupByColsF = {}
self.numGroupByColsQueries = {}
self.orderByColsP = {}
self.orderByColsR = {}
self.orderByColsF = {}
self.numOrderByColsQueries = {}
self.havingColsP = {}
self.havingColsR = {}
self.havingColsF = {}
self.numHavingColsQueries = {}
self.limitP = {}
self.limitR = {}
self.limitF = {}
self.numLimitColsQueries = {}
self.joinPredsP = {}
self.joinPredsR = {}
self.joinPredsF = {}
self.numJoinPredsColsQueries = {}
self.condJoinPredsP = {}
self.condJoinPredsR = {}
self.condJoinPredsF = {}
self.numCondJoinPredsColsQueries = {}
class nextActualOps:
def __init__(self):
self.queryType = None
self.tables = None
self.projCols = None
self.avgCols = None
self.minCols = None
self.maxCols = None
self.sumCols = None
self.countCols = None
self.selCols = None
self.groupByCols = None
self.orderByCols = None
self.havingCols = None
self.limit = None
self.joinPreds = None
def parseLineAddOp(line, actualOrPredObj):
if line.startswith("Query Type"):
actualOrPredObj.queryType = line.strip().split(": ")[1]
elif line.startswith("Limit"):
actualOrPredObj.limit = line.strip().split(": ")[1]
elif line.startswith("Tables"):
actualOrPredObj.tables = eval(line.strip().split(": ")[1])
elif line.startswith("Projected"):
actualOrPredObj.projCols = eval(line.strip().split(": ")[1])
elif line.startswith("AVG"):
actualOrPredObj.avgCols = eval(line.strip().split(": ")[1])
elif line.startswith("MIN"):
actualOrPredObj.minCols = eval(line.strip().split(": ")[1])
elif line.startswith("MAX"):
actualOrPredObj.maxCols = eval(line.strip().split(": ")[1])
elif line.startswith("SUM"):
actualOrPredObj.sumCols = eval(line.strip().split(": ")[1])
elif line.startswith("COUNT"):
actualOrPredObj.countCols = eval(line.strip().split(": ")[1])
elif line.startswith("SEL"):
actualOrPredObj.selCols = eval(line.strip().split(": ")[1])
elif line.startswith("GROUP"):
actualOrPredObj.groupByCols = eval(line.strip().split(": ")[1])
elif line.startswith("ORDER"):
actualOrPredObj.orderByCols = eval(line.strip().split(": ")[1])
elif line.startswith("HAVING"):
actualOrPredObj.havingCols = eval(line.strip().split(": ")[1])
elif line.startswith("JOIN"):
actualOrPredObj.joinPreds = eval(line.strip().split(": ")[1])
return
def updateMetricDict(metricDict, key, val):
if key not in metricDict:
metricDict[key] = val
else:
metricDict[key] = float(metricDict[key]+val)
return
def computeOpF1(predOpList, actualOpList):
if predOpList is None and actualOpList is not None:
return (0.0, 0.0, 0.0)
elif predOpList is not None and actualOpList is not None:
TP = len(set(predOpList).intersection(set(actualOpList)))
FP = len(set(predOpList) - set(actualOpList))
FN = len(set(actualOpList) - set(predOpList))
P = float(TP)/float(TP+FP)
R = float(TP)/float(TP+FN)
if P == 0.0 or R == 0.0:
F = 0.0
else:
F = 2*P*R / float(P+R)
return (P, R, F)
else:
return (None, None, None)
def updateOpMetrics(P, R, F, evalOpsP, evalOpsR, evalOpsF, evalOpsQueryCountDict, evalOpsObj):
if P is not None and R is not None and F is not None:
if evalOpsObj.curEpisode not in evalOpsQueryCountDict:
evalOpsQueryCountDict[evalOpsObj.curEpisode] = 1
else:
evalOpsQueryCountDict[evalOpsObj.curEpisode] += 1
updateMetricDict(evalOpsP, evalOpsObj.curEpisode, P)
updateMetricDict(evalOpsR, evalOpsObj.curEpisode, R)
updateMetricDict(evalOpsF, evalOpsObj.curEpisode, F)
return
def computeRelevantJoinPreds(accTables, predictedOrActualJoinPreds):
if predictedOrActualJoinPreds is None:
return None
relJoinPreds = []
for joinPred in predictedOrActualJoinPreds:
leftTable = joinPred.split(",")[0].split(".")[0]
rightTable = joinPred.split(",")[1].split(".")[0]
if leftTable in accTables and rightTable in accTables:
relJoinPreds.append(joinPred)
if len(relJoinPreds) == 0:
return None
return relJoinPreds
def computeRelevantSelCols(accTables, predOrActualCols):
if predOrActualCols is None:
return None
relCols = []
for col in predOrActualCols:
tableName = col.split(".")[0]
if tableName in accTables:
relCols.append(col)
if len(relCols) == 0:
return None
return relCols
def compUpdateOpMetrics(predOpList, actualOpList, evalOpsP, evalOpsR, evalOpsF, evalOpsQueryCountDict, evalOpsObj):
(P,R,F) = computeOpF1(predOpList, actualOpList)
updateOpMetrics(P, R, F, evalOpsP, evalOpsR, evalOpsF, evalOpsQueryCountDict, evalOpsObj)
return
def compUpdateCondSelMetrics(predOpsObj, nextActualOpsObj, evalOpsObj):
try:
if evalOpsObj.tablesF[evalOpsObj.curEpisode] == 1.0 and evalOpsObj.curEpisode in evalOpsObj.selColsP \
and evalOpsObj.curEpisode in evalOpsObj.selColsR and evalOpsObj.curEpisode in evalOpsObj.selColsF:
updateOpMetrics(evalOpsObj.selColsP[evalOpsObj.curEpisode], evalOpsObj.selColsR[evalOpsObj.curEpisode],
evalOpsObj.selColsF[evalOpsObj.curEpisode], evalOpsObj.condSelColsP, evalOpsObj.condSelColsR,
evalOpsObj.condSelColsF, evalOpsObj.numCondSelColsQueries, evalOpsObj)
elif evalOpsObj.tablesF[evalOpsObj.curEpisode] > 0.0 and evalOpsObj.curEpisode in evalOpsObj.selColsP \
and evalOpsObj.curEpisode in evalOpsObj.selColsR and evalOpsObj.curEpisode in evalOpsObj.selColsF: # partial overlap of tables
accTables = list(set(predOpsObj.tables).intersection(set(nextActualOpsObj.tables)))
if len(accTables) > 0:
relPredCols = computeRelevantSelCols(accTables, predOpsObj.selCols)
relActualCols = computeRelevantSelCols(accTables, nextActualOpsObj.selCols)
compUpdateOpMetrics(relPredCols, relActualCols, evalOpsObj.condSelColsP, evalOpsObj.condSelColsR,
evalOpsObj.condSelColsF, evalOpsObj.numCondSelColsQueries, evalOpsObj)
except:
pass
return
def compUpdateCondJoinMetrics(predOpsObj, nextActualOpsObj, evalOpsObj):
try:
if evalOpsObj.tablesF[evalOpsObj.curEpisode] == 1.0 and evalOpsObj.curEpisode in evalOpsObj.joinPredsP \
and evalOpsObj.curEpisode in evalOpsObj.joinPredsR and evalOpsObj.curEpisode in evalOpsObj.joinPredsF:
updateOpMetrics(evalOpsObj.joinPredsP[evalOpsObj.curEpisode], evalOpsObj.joinPredsR[evalOpsObj.curEpisode],
evalOpsObj.joinPredsF[evalOpsObj.curEpisode], evalOpsObj.condJoinPredsP, evalOpsObj.condJoinPredsR,
evalOpsObj.condJoinPredsF, evalOpsObj.numCondJoinPredsColsQueries, evalOpsObj)
elif evalOpsObj.tablesF[evalOpsObj.curEpisode] > 0.0 and evalOpsObj.curEpisode in evalOpsObj.joinPredsP \
and evalOpsObj.curEpisode in evalOpsObj.joinPredsR and evalOpsObj.curEpisode in evalOpsObj.joinPredsF: # partial overlap of tables
accTables = list(set(predOpsObj.tables).intersection(set(nextActualOpsObj.tables)))
if len(accTables) > 0:
relPredictedJoinPreds = computeRelevantJoinPreds(accTables, predOpsObj.joinPreds)
relActualJoinPreds = computeRelevantJoinPreds(accTables, nextActualOpsObj.joinPreds)
compUpdateOpMetrics(relPredictedJoinPreds, relActualJoinPreds, evalOpsObj.condJoinPredsP, evalOpsObj.condJoinPredsR,
evalOpsObj.condJoinPredsF, evalOpsObj.numCondJoinPredsQueries, evalOpsObj)
except:
pass
return
def computeF1(evalOpsObj, predOpsObj, nextActualOpsObj):
if nextActualOpsObj.queryType == "select":
updateMetricDict(evalOpsObj.numSelectQueryType, evalOpsObj.curEpisode, 1.0)
elif nextActualOpsObj.queryType == "insert":
updateMetricDict(evalOpsObj.numInsertQueryType, evalOpsObj.curEpisode, 1.0)
elif nextActualOpsObj.queryType == "update":
updateMetricDict(evalOpsObj.numUpdateQueryType, evalOpsObj.curEpisode, 1.0)
elif nextActualOpsObj.queryType == "delete":
updateMetricDict(evalOpsObj.numDeleteQueryType, evalOpsObj.curEpisode, 1.0)
if predOpsObj.queryType == nextActualOpsObj.queryType:
updateOpMetrics(1.0, 1.0, 1.0, evalOpsObj.queryTypeP, evalOpsObj.queryTypeR,
evalOpsObj.queryTypeF, evalOpsObj.numQueryTypeQueries, evalOpsObj)
elif predOpsObj.queryType != nextActualOpsObj.queryType:
updateOpMetrics(0.0, 0.0, 0.0, evalOpsObj.queryTypeP, evalOpsObj.queryTypeR,
evalOpsObj.queryTypeF, evalOpsObj.numQueryTypeQueries, evalOpsObj)
if nextActualOpsObj.limit is not None:
if predOpsObj.limit == nextActualOpsObj.limit:
updateOpMetrics(1.0, 1.0, 1.0, evalOpsObj.limitP, evalOpsObj.limitR,
evalOpsObj.limitF, evalOpsObj.numLimitColsQueries, evalOpsObj)
else:
updateOpMetrics(0.0, 0.0, 0.0, evalOpsObj.limitP, evalOpsObj.limitR,
evalOpsObj.limitF, evalOpsObj.numLimitColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.tables, nextActualOpsObj.tables, evalOpsObj.tablesP,
evalOpsObj.tablesR, evalOpsObj.tablesF, evalOpsObj.numTablesQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.projCols, nextActualOpsObj.projCols, evalOpsObj.projColsP,
evalOpsObj.projColsR, evalOpsObj.projColsF, evalOpsObj.numProjColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.avgCols, nextActualOpsObj.avgCols, evalOpsObj.avgColsP,
evalOpsObj.avgColsR, evalOpsObj.avgColsF, evalOpsObj.numAvgColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.minCols, nextActualOpsObj.minCols, evalOpsObj.minColsP,
evalOpsObj.minColsR, evalOpsObj.minColsF, evalOpsObj.numMinColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.maxCols, nextActualOpsObj.maxCols, evalOpsObj.maxColsP,
evalOpsObj.maxColsR, evalOpsObj.maxColsF, evalOpsObj.numMaxColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.sumCols, nextActualOpsObj.sumCols, evalOpsObj.sumColsP,
evalOpsObj.sumColsR, evalOpsObj.sumColsF, evalOpsObj.numSumColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.countCols, nextActualOpsObj.countCols, evalOpsObj.countColsP,
evalOpsObj.countColsR, evalOpsObj.countColsF, evalOpsObj.numCountColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.selCols, nextActualOpsObj.selCols, evalOpsObj.selColsP,
evalOpsObj.selColsR, evalOpsObj.selColsF, evalOpsObj.numSelColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.groupByCols, nextActualOpsObj.groupByCols, evalOpsObj.groupByColsP,
evalOpsObj.groupByColsR, evalOpsObj.groupByColsF, evalOpsObj.numGroupByColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.orderByCols, nextActualOpsObj.orderByCols, evalOpsObj.orderByColsP,
evalOpsObj.orderByColsR, evalOpsObj.orderByColsF, evalOpsObj.numOrderByColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.havingCols, nextActualOpsObj.havingCols, evalOpsObj.havingColsP,
evalOpsObj.havingColsR, evalOpsObj.havingColsF, evalOpsObj.numHavingColsQueries, evalOpsObj)
compUpdateOpMetrics(predOpsObj.joinPreds, nextActualOpsObj.joinPreds, evalOpsObj.joinPredsP,
evalOpsObj.joinPredsR, evalOpsObj.joinPredsF, evalOpsObj.numJoinPredsColsQueries, evalOpsObj)
compUpdateCondSelMetrics(predOpsObj, nextActualOpsObj, evalOpsObj)
compUpdateCondJoinMetrics(predOpsObj, nextActualOpsObj, evalOpsObj)
return
def createEvalMetricsOpWise(evalOpsObj):
prevEpisode = -1
rank = float("-inf")
nextActualOpsObj = None
predOpsObj = None
with open(evalOpsObj.logFile) as f:
for line in f:
if line.startswith("#Episodes"):
evalOpsObj.curEpisode = int(line.strip().split(";")[0].split(":")[1])
numTokens = len(line.strip().split(";"))
rank = int(line.strip().split(";")[numTokens-3].split(":")[1])
if rank == -1: # this can happen when all predicted queries are equally bad
rank = 0
assert rank >= 0 and rank < int(evalOpsObj.configDict['TOP_K'])
MRR = float(1.0) / float(rank+1)
if evalOpsObj.curEpisode != prevEpisode:
evalOpsObj.numEpQueries[evalOpsObj.curEpisode] = 1
assert evalOpsObj.curEpisode not in evalOpsObj.meanReciprocalRank
evalOpsObj.meanReciprocalRank[evalOpsObj.curEpisode] = MRR
else:
evalOpsObj.numEpQueries[evalOpsObj.curEpisode] += 1
evalOpsObj.meanReciprocalRank[evalOpsObj.curEpisode] = (evalOpsObj.meanReciprocalRank[evalOpsObj.curEpisode] + MRR)
elif line.startswith("Actual SQL"):
evalOpsObj.curQueryIndex = -100
nextActualOpsObj = nextActualOps()
elif line.startswith("Predicted SQL Ops"):
substrTokens = line.strip().split(":")[0].split(" ")
evalOpsObj.curQueryIndex = int(substrTokens[len(substrTokens)-1])
if evalOpsObj.curQueryIndex == rank:
predOpsObj = nextActualOps()
elif line.startswith("---") and predOpsObj is not None and evalOpsObj is not None:
computeF1(evalOpsObj, predOpsObj, nextActualOpsObj)
elif evalOpsObj.curQueryIndex == -100:
parseLineAddOp(line, nextActualOpsObj)
elif evalOpsObj.curQueryIndex == rank:
parseLineAddOp(line, predOpsObj)
prevEpisode = evalOpsObj.curEpisode
return evalOpsObj
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-config", help="config file to parse", type=str, required=True)
parser.add_argument("-log", help="log filename to analyze", type=str, required=True)
#parser.add_argument("-lineNum", help="line Number to analyze", type=int, required=True)
args = parser.parse_args()
evalOpsObj = evalOps(args.config, args.log)
evalOpsObj = createEvalMetricsOpWise(evalOpsObj)
plotEvalMetricsOpWise(evalOpsObj)