-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprep_query_template.py
1896 lines (1723 loc) · 51.1 KB
/
prep_query_template.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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from prep_cardinality import get_raw_table_size, get_maps, ori_cardest
import pandas as pd
import numpy as np
import copy
import os
np.random.seed(2023)
available_it_for_mi = ['genres'] * 13 + ['budget'] * 2 + ['release dates'] * 20 + ['countries'] * 10
available_it_for_pi = ['mini biography'] * 3 + ['trivia'] * 2 + ['height'] * 1
available_it_for_miidx = ['top 250 rank'] * 2 + ['bottom 10 rank'] * 2 + ['rating'] * 16 + ['votes'] * 11
cct_for_cc_subject_id = ["IN ('cast', 'crew')"] * 4 + ["= 'cast'"] * 12 + ["!= 'complete+verified'"] * 2
cct_for_cc_status_id = ["= 'complete'"] * 3 + ["LIKE '%complete%'"] * 7 + [" = 'complete+verified'"] * 9
def gen_sql_by_template(query_id, K, db_name=None):
np.random.seed(2024)
if db_name == 'dsb': # simply use dsb's q gen
sql_list = []
folder_path = f'/winhomes/hx68/robust-vcm/query/dsb/query{query_id}_spj'
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
with open(file_path, "r") as sql_file:
sql_list.append(sql_file.read())
return sql_list, None
elif db_name == 'stats':
local_selections = pd.read_csv('lsc/stats/LSC-Stats.csv')
condition_dict = {'b': [], 'c': [], 'u': [], 'ph': [], 'p': [], 'pl': [], 'v': []}
else:
local_selections = pd.read_csv('lsc/job/local-sel-condition-saved.csv')
# ['Table', 'Condition', 'Frequency']
condition_dict = {'k': [], 't': [], 'cn': [], 'n': [], 'mc': [], 'mi': [], 'it_pi': [], 'it_mi': [], 'it_miidx': [], 'an': [], 'lt': [], 'pi': [], 'ci':[], 'mi_idx':[], 'kt':[], 'ct':[], 'rt':[], 'cct':[], 'chn':[]}
local_selections_grouped = local_selections.groupby('Table')
frequency_dict = copy.deepcopy(condition_dict)
for table in condition_dict.keys():
for _, row in local_selections_grouped.get_group(table).iterrows():
if row['Condition'] == '1=1':
continue
condition_dict[table].append(row['Condition'])
frequency_dict[table].append(int(row['Frequency']))
# condition_dict[table].extend([row['Condition']] * int(row['Frequency']))
sampled_literals = []
query_to_local_selection_dict = {
'33a': ['cn', 'it_miidx', 'it_miidx', 'kt', 'kt', 'lt', 'mi_idx', 't'],
'32a': ['k'],
'31a': ['ci', 'cn', 'it_mi', 'it_miidx', 'k', 'mi', 'n'],
'30a': ['cct', 'cct', 'ci', 'it_mi', 'it_miidx', 'k', 'mi', 'n', 't'],
'29a': ['cct', 'cct', 'chn', 'ci', 'cn', 'it_mi', 'it_pi', 'k', 'mi', 'n', 'rt', 't'],
'28a': ['cct', 'cct', 'cn', 'it_mi', 'it_miidx', 'k', 'kt', 'mc', 'mi', 'mi_idx', 't'],
'27a': ['cct', 'cct', 'cn', 'ct', 'k', 'lt', 'mc', 'mi', 't'],
'26a': ['cct', 'cct', 'chn', 'it_miidx', 'k', 'kt', 'mi_idx', 't'],
'25a': ['ci', 'it_mi', 'it_miidx', 'k', 'mi', 'n'],
'24a': ['ci', 'cn', 'it_mi', 'k', 'mi', 'n', 'rt', 't'],
'23a': ['cct', 'cn', 'it_mi', 'kt', 'mi', 't'],
'22a': ['cn', 'it_mi', 'it_miidx', 'k', 'kt', 'mc', 'mi', 'mi_idx', 't'],
'21a': ['cn', 'ct', 'k', 'lt', 'mc', 'mi', 't'],
'20a': ['cct', 'cct', 'chn', 'k', 'kt', 't'],
'19a': ['ci', 'cn', 'it_mi', 'mc', 'mi', 'n', 'rt', 't'],
'18a': ['ci', 'it_mi', 'it_miidx', 'n'],
'17a': ['cn', 'k', 'n'],
'16a': ['cn', 'k', 't'],
'15a': ['cn', 'it_mi', 'mc', 'mi', 't'],
'14a': ['it_mi', 'it_miidx', 'k', 'kt', 'mi', 'mi_idx', 't'],
'13a': ['cn', 'ct', 'it_miidx', 'it_mi', 'kt'],
'12a': ['cn', 'ct', 'it_mi', 'it_miidx', 'mi', 'mi_idx', 't'],
'11a': ['cn', 'ct', 'k', 'lt', 'mc', 't'],
'10a': ['ci', 'cn', 'rt', 't'],
'9a': ['ci', 'cn', 'mc', 'n', 'rt', 't'],
'8a': ['ci', 'cn', 'mc', 'n', 'rt'],
'7a': ['an', 'it_pi', 'lt', 'n', 'pi', 't'],
'6a': ['k', 'n', 't'],
'5a': ['ct', 'mc', 'mi', 't'],
'4a': ['it_miidx', 'k', 'mi_idx', 't'],
'3a': ['k', 'mi', 't'],
'2a': ['cn', 'k'],
'1a': ['ct', 'it_miidx', 'mc']}
if db_name == 'stats':
query_to_local_selection_dict = {
'18a': ['c', 'p', 'v'],
'20g': ['c', 'p', 'v', 'u'],
'20a': ['c', 'p', 'v', 'u'],
'20c': ['p', 'u'],
'20f': ['p', 'u'],
'21b': ['v', 'p', 'b', 'u'],
'25a': ['c', 'ph', 'b'],
'25b': ['c', 'ph', 'b'],
'28e': ['ph', 'p', 'u', 'b'],
'30a': ['c', 'p', 'pl', 'ph', 'v'],
'31a': ['p', 'ph', 'v', 'u'],
'34e': ['c', 'p', 'u'],
'37b': ['u', 'v', 'b'],
'38a': ['p', 'ph', 'v', 'b', 'u'],
'38b': ['p', 'pl', 'ph', 'v', 'u'],
'39d': ['c', 'p', 'pl', 'v', 'u'],
'43b': ['c', 'ph', 'v'],
'45a': ['c', 'p', 'pl', 'v', 'b'],
'45d': ['c', 'p', 'pl', 'v', 'b'],
'40d': ['c', 'p', 'pl', 'ph', 'u'],
'40f': ['c', 'p', 'pl', 'ph', 'u'],
}
for i, table in enumerate(query_to_local_selection_dict[query_id]):
total_frequency = sum(frequency_dict[table])
probabilities = [freq / total_frequency for freq in frequency_dict[table]]
sampled_literals.append(np.random.choice(condition_dict[table], p=probabilities, size=K*2))
sampled_literals = np.transpose(sampled_literals).tolist()
# Should avoid same conditions, # of parameter will change
sampled_literals = [i for i in sampled_literals if len(set(i)) == len(i)][:K]
if db_name == 'stats':
if query_id == '18a':
sql_list = [change_query_18a_stats(i) for i in sampled_literals]
if query_id == '20g':
sql_list = [change_query_20g_stats(i) for i in sampled_literals]
if query_id == '20a':
sql_list = [change_query_20a_stats(i) for i in sampled_literals]
if query_id == '20c':
sql_list = [change_query_20c_stats(i) for i in sampled_literals]
if query_id == '20f':
sql_list = [change_query_20f_stats(i) for i in sampled_literals]
if query_id == '21b':
sql_list = [change_query_21b_stats(i) for i in sampled_literals]
if query_id == '25a':
sql_list = [change_query_25a_stats(i) for i in sampled_literals]
if query_id == '25b':
sql_list = [change_query_25a_stats(i) for i in sampled_literals]
if query_id == '28e':
sql_list = [change_query_28e_stats(i) for i in sampled_literals]
if query_id == '30a':
sql_list = [change_query_30a_stats(i) for i in sampled_literals]
if query_id == '31a':
sql_list = [change_query_31a_stats(i) for i in sampled_literals]
if query_id == '34e':
sql_list = [change_query_34e_stats(i) for i in sampled_literals]
if query_id == '37b':
sql_list = [change_query_37b_stats(i) for i in sampled_literals]
if query_id == '38a':
sql_list = [change_query_38a_stats(i) for i in sampled_literals]
if query_id == '38b':
sql_list = [change_query_38b_stats(i) for i in sampled_literals]
if query_id == '39d':
sql_list = [change_query_39d_stats(i) for i in sampled_literals]
if query_id == '43b':
sql_list = [change_query_43b_stats(i) for i in sampled_literals]
if query_id == '45a':
sql_list = [change_query_45a_stats(i) for i in sampled_literals]
if query_id == '45d':
sql_list = [change_query_45a_stats(i) for i in sampled_literals]
if query_id == '40d':
sql_list = [change_query_40d_stats(i) for i in sampled_literals]
if query_id == '40f':
sql_list = [change_query_40f_stats(i) for i in sampled_literals]
return sql_list, sampled_literals
if query_id == '1a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_1a(i) for i in sampled_literals]
if query_id == '2a':
sql_list = [change_query_2a(i) for i in sampled_literals]
if query_id == '3a':
sql_list = [change_query_3a(i) for i in sampled_literals]
if query_id == '4a':
for i in sampled_literals:
i[0] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_4a(i) for i in sampled_literals]
if query_id == '5a':
sql_list = [change_query_5a(i) for i in sampled_literals]
if query_id == '6a':
sql_list = [change_query_6a(i) for i in sampled_literals]
if query_id == '7a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_pi)
sql_list = [change_query_7a(i) for i in sampled_literals]
if query_id == '8a':
sql_list = [change_query_8a(i) for i in sampled_literals]
if query_id == '9a':
sql_list = [change_query_9a(i) for i in sampled_literals]
if query_id == '10a':
sql_list = [change_query_10a(i) for i in sampled_literals]
if query_id == '11a':
sql_list = [change_query_11a(i) for i in sampled_literals]
if query_id == '12a':
for i in sampled_literals:
i[2] = np.random.choice(available_it_for_mi)
sql_list = [change_query_12a(i) for i in sampled_literals]
if query_id == '13a':
# Should avoid
for i in sampled_literals:
i[3] = np.random.choice(available_it_for_mi)
sql_list = [change_query_13a(i) for i in sampled_literals]
if query_id == '14a':
for i in sampled_literals:
i[0] = np.random.choice(available_it_for_mi)
i[1] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_14a(i) for i in sampled_literals]
if query_id == '15a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_mi)
sql_list = [change_query_15a(i) for i in sampled_literals]
if query_id == '16a':
sql_list = [change_query_16a(i) for i in sampled_literals]
if query_id == '17a':
sql_list = [change_query_17a(i) for i in sampled_literals]
if query_id == '18a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_mi)
i[2] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_18a(i) for i in sampled_literals]
if query_id == '19a':
for i in sampled_literals:
i[2] = np.random.choice(available_it_for_mi)
sql_list = [change_query_19a(i) for i in sampled_literals]
if query_id == '20a':
sql_list = [change_query_20a(i) for i in sampled_literals]
if query_id == '21a':
sql_list = [change_query_21a(i) for i in sampled_literals]
if query_id == '22a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_mi)
i[2] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_22a(i) for i in sampled_literals]
if query_id == '23a':
for i in sampled_literals:
i[2] = np.random.choice(available_it_for_mi)
sql_list = [change_query_23a(i) for i in sampled_literals]
if query_id == '24a':
for i in sampled_literals:
i[2] = np.random.choice(available_it_for_mi)
sql_list = [change_query_24a(i) for i in sampled_literals]
if query_id == '25a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_mi)
i[2] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_25a(i) for i in sampled_literals]
if query_id == '26a':
for i in sampled_literals:
i[3] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_26a(i) for i in sampled_literals]
if query_id == '27a':
for i in sampled_literals:
i[0] = np.random.choice(cct_for_cc_subject_id)
i[1] = np.random.choice(cct_for_cc_status_id)
sql_list = [change_query_27a(i) for i in sampled_literals]
if query_id == '28a':
for i in sampled_literals:
i[0] = np.random.choice(cct_for_cc_subject_id)
i[1] = np.random.choice(cct_for_cc_status_id)
i[3] = np.random.choice(available_it_for_mi)
i[4] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_28a(i) for i in sampled_literals]
if query_id == '29a':
for i in sampled_literals:
i[0] = np.random.choice(cct_for_cc_subject_id)
i[1] = np.random.choice(cct_for_cc_status_id)
i[5] = np.random.choice(available_it_for_mi)
i[6] = np.random.choice(available_it_for_pi)
sql_list = [change_query_29a(i) for i in sampled_literals]
if query_id == '30a':
for i in sampled_literals:
i[0] = np.random.choice(cct_for_cc_subject_id)
i[1] = np.random.choice(cct_for_cc_status_id)
i[3] = np.random.choice(available_it_for_mi)
i[4] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_30a(i) for i in sampled_literals]
# print(sampled_literals)
if query_id == '31a':
for i in sampled_literals:
i[2] = np.random.choice(available_it_for_mi)
i[3] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_31a(i) for i in sampled_literals]
if query_id == '32a':
sql_list = [change_query_32a(i) for i in sampled_literals]
if query_id == '33a':
for i in sampled_literals:
i[1] = np.random.choice(available_it_for_miidx)
sql_list = [change_query_33a(i) for i in sampled_literals]
return sql_list, sampled_literals
def change_query_18a_stats(literals):
sql = f'''SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
votes as v
WHERE p.Id = c.PostId
AND c.PostId = pl.PostId
AND pl.PostId = v.PostId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]};'''
return sql
# 20g
def change_query_20g_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
votes as v,
users as u
WHERE u.Id = p.OwnerUserId
AND p.Id = v.PostId
AND p.Id = c.PostId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]};'''
return sql
def change_query_20a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
votes as v,
users as u
WHERE u.Id = c.UserId
AND u.Id = p.OwnerUserId
AND u.Id = v.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]};'''
return sql
# 20c
def change_query_20c_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
votes as v,
users as u
WHERE u.Id = p.OwnerUserId
AND u.Id = c.UserId
AND u.Id = v.UserId
AND {literals[0]}
AND {literals[1]}
;'''
return sql
def change_query_20f_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
votes as v,
users as u
WHERE u.Id = p.OwnerUserId
AND p.Id = v.PostId
AND p.Id = c.PostId
AND {literals[0]}
AND {literals[1]}
;'''
return sql
def change_query_21b_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM votes as v,
posts as p,
badges as b,
users as u
WHERE p.Id = v.PostId
AND u.Id = p.OwnerUserId
AND u.Id = b.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]};
'''
return sql
# 25a / 25b
def change_query_25a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
postHistory as ph,
badges as b,
users as u
WHERE u.Id = c.UserId
AND u.Id = ph.UserId
AND u.Id = b.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]};
'''
return sql
def change_query_28e_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM postHistory as ph,
posts as p,
users as u,
badges as b
WHERE b.UserId = u.Id
AND p.OwnerUserId = u.Id
AND ph.UserId = u.Id
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]};
'''
return sql
def change_query_30a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
postHistory as ph,
votes as v
WHERE p.Id = c.PostId
AND p.Id = pl.PostId
AND p.Id = ph.PostId
AND p.Id = v.PostId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_31a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postHistory as ph,
votes as v,
users as u
WHERE u.Id = c.UserId
AND c.UserId = p.OwnerUserId
AND p.OwnerUserId = ph.UserId
AND ph.UserId = v.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]};
'''
return sql
def change_query_34e_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postHistory as ph,
badges as b,
users as u
WHERE u.Id = ph.UserId
AND u.Id = b.UserId
AND u.Id = p.OwnerUserId
AND u.Id = c.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]};
'''
return sql
def change_query_37b_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM tags as t,
posts as p,
users as u,
votes as v,
badges as b
WHERE p.Id = t.ExcerptPostId
AND u.Id = v.UserId
AND u.Id = b.UserId
AND u.Id = p.OwnerUserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]};
'''
return sql
def change_query_38b_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM posts as p,
postLinks as pl,
postHistory as ph,
votes as v,
badges as b,
users as u
WHERE p.Id = pl.RelatedPostId
AND u.Id = p.OwnerUserId
AND u.Id = b.UserId
AND u.Id = ph.UserId
AND u.Id = v.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_39d_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
votes as v,
badges as b,
users as u
WHERE p.Id = c.PostId
AND p.Id = pl.RelatedPostId
AND p.Id = v.PostId
AND u.Id = p.OwnerUserId
AND u.Id = b.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_43b_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
postHistory as ph,
votes as v,
posts as p
WHERE ph.PostId = p.Id
AND c.PostId = p.Id
AND v.PostId = p.Id
AND {literals[0]}
AND {literals[1]}
AND {literals[2]};
'''
return sql
def change_query_45a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
postHistory as ph,
votes as v,
badges as b,
users as u
WHERE p.Id = pl.RelatedPostId
AND b.UserId = u.Id
AND c.UserId = u.Id
AND p.Id = v.PostId
AND p.Id = c.PostId
AND p.Id = ph.PostId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_40d_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
postHistory as ph,
votes as v,
users as u
WHERE p.Id = pl.PostId
AND p.Id = ph.PostId
AND p.Id = c.PostId
AND u.Id = c.UserId
AND u.Id = v.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_40f_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM comments as c,
posts as p,
postLinks as pl,
postHistory as ph,
votes as v,
users as u
WHERE u.Id = p.OwnerUserId
AND p.Id = v.PostId
AND p.Id = c.PostId
AND p.Id = pl.PostId
AND p.Id = ph.PostId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_38a_stats(literals):
sql = f'''
SELECT COUNT(*)
FROM posts as p,
postLinks as pl,
postHistory as ph,
votes as v,
badges as b,
users as u
WHERE p.Id = pl.RelatedPostId
AND u.Id = p.OwnerUserId
AND u.Id = b.UserId
AND u.Id = ph.UserId
AND u.Id = v.UserId
AND {literals[0]}
AND {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]};
'''
return sql
def change_query_a_stats(literals):
sql = f'''
'''
return sql
def change_query_33a(literals):
sql = f'''
SELECT MIN(cn1.name) AS first_company,
MIN(cn2.name) AS second_company,
MIN(mi_idx1.info) AS first_rating,
MIN(mi_idx2.info) AS second_rating,
MIN(t1.title) AS first_movie,
MIN(t2.title) AS second_movie
FROM company_name AS cn1,
company_name AS cn2,
info_type AS it1,
info_type AS it2,
kind_type AS kt1,
kind_type AS kt2,
link_type AS lt,
movie_companies AS mc1,
movie_companies AS mc2,
movie_info_idx AS mi_idx1,
movie_info_idx AS mi_idx2,
movie_link AS ml,
title AS t1,
title AS t2
WHERE {literals[0].replace('cn', 'cn1')}
AND it1.info = '{literals[1]}'
AND it2.info = '{literals[1]}'
AND {literals[3].replace('kt', 'kt1')}
AND {literals[3].replace('kt', 'kt1')}
AND {literals[5]}
AND {literals[6].replace('mi_idx', 'mi_idx2')}
AND {literals[7].replace('t.', 't2.')}
AND lt.id = ml.link_type_id
AND t1.id = ml.movie_id
AND t2.id = ml.linked_movie_id
AND it1.id = mi_idx1.info_type_id
AND t1.id = mi_idx1.movie_id
AND kt1.id = t1.kind_id
AND cn1.id = mc1.company_id
AND t1.id = mc1.movie_id
AND ml.movie_id = mi_idx1.movie_id
AND ml.movie_id = mc1.movie_id
AND mi_idx1.movie_id = mc1.movie_id
AND it2.id = mi_idx2.info_type_id
AND t2.id = mi_idx2.movie_id
AND kt2.id = t2.kind_id
AND cn2.id = mc2.company_id
AND t2.id = mc2.movie_id
AND ml.linked_movie_id = mi_idx2.movie_id
AND ml.linked_movie_id = mc2.movie_id
AND mi_idx2.movie_id = mc2.movie_id;
'''
return sql
def change_query_32a(literals):
sql = f'''
SELECT MIN(lt.link) AS link_type,
MIN(t1.title) AS first_movie,
MIN(t2.title) AS second_movie
FROM keyword AS k,
link_type AS lt,
movie_keyword AS mk,
movie_link AS ml,
title AS t1,
title AS t2
WHERE {literals[0]}
AND mk.keyword_id = k.id
AND t1.id = mk.movie_id
AND ml.movie_id = t1.id
AND ml.linked_movie_id = t2.id
AND lt.id = ml.link_type_id
AND mk.movie_id = t1.id;
'''
return sql
def change_query_31a(literals):
sql = f'''
SELECT MIN(mi.info) AS movie_budget,
MIN(mi_idx.info) AS movie_votes,
MIN(n.name) AS writer,
MIN(t.title) AS violent_liongate_movie
FROM cast_info AS ci,
company_name AS cn,
info_type AS it1,
info_type AS it2,
keyword AS k,
movie_companies AS mc,
movie_info AS mi,
movie_info_idx AS mi_idx,
movie_keyword AS mk,
name AS n,
title AS t
WHERE {literals[0]}
AND {literals[1]}
AND it1.info = '{literals[2]}'
AND it2.info = '{literals[3]}'
AND {literals[4]}
AND {literals[5]}
AND {literals[6]}
AND t.id = mi.movie_id
AND t.id = mi_idx.movie_id
AND t.id = ci.movie_id
AND t.id = mk.movie_id
AND t.id = mc.movie_id
AND ci.movie_id = mi.movie_id
AND ci.movie_id = mi_idx.movie_id
AND ci.movie_id = mk.movie_id
AND ci.movie_id = mc.movie_id
AND mi.movie_id = mi_idx.movie_id
AND mi.movie_id = mk.movie_id
AND mi.movie_id = mc.movie_id
AND mi_idx.movie_id = mk.movie_id
AND mi_idx.movie_id = mc.movie_id
AND mk.movie_id = mc.movie_id
AND n.id = ci.person_id
AND it1.id = mi.info_type_id
AND it2.id = mi_idx.info_type_id
AND k.id = mk.keyword_id
AND cn.id = mc.company_id;
'''
return sql
def change_query_30a(literals):
sql = f'''
SELECT MIN(mi.info) AS movie_budget,
MIN(mi_idx.info) AS movie_votes,
MIN(n.name) AS writer,
MIN(t.title) AS complete_violent_movie
FROM complete_cast AS cc,
comp_cast_type AS cct1,
comp_cast_type AS cct2,
cast_info AS ci,
info_type AS it1,
info_type AS it2,
keyword AS k,
movie_info AS mi,
movie_info_idx AS mi_idx,
movie_keyword AS mk,
name AS n,
title AS t
WHERE cct1.kind {literals[0]}
AND cct2.kind {literals[1]}
AND {literals[2]}
AND it1.info = '{literals[3]}'
AND it2.info = '{literals[4]}'
AND {literals[5]}
AND {literals[6]}
AND {literals[7]}
AND {literals[8]}
AND t.id = mi.movie_id
AND t.id = mi_idx.movie_id
AND t.id = ci.movie_id
AND t.id = mk.movie_id
AND t.id = cc.movie_id
AND ci.movie_id = mi.movie_id
AND ci.movie_id = mi_idx.movie_id
AND ci.movie_id = mk.movie_id
AND ci.movie_id = cc.movie_id
AND mi.movie_id = mi_idx.movie_id
AND mi.movie_id = mk.movie_id
AND mi.movie_id = cc.movie_id
AND mi_idx.movie_id = mk.movie_id
AND mi_idx.movie_id = cc.movie_id
AND mk.movie_id = cc.movie_id
AND n.id = ci.person_id
AND it1.id = mi.info_type_id
AND it2.id = mi_idx.info_type_id
AND k.id = mk.keyword_id
AND cct1.id = cc.subject_id
AND cct2.id = cc.status_id;
'''
return sql
def change_query_29a(literals):
sql = f'''
SELECT MIN(chn.name) AS voiced_char,
MIN(n.name) AS voicing_actress,
MIN(t.title) AS voiced_animation
FROM aka_name AS an,
complete_cast AS cc,
comp_cast_type AS cct1,
comp_cast_type AS cct2,
char_name AS chn,
cast_info AS ci,
company_name AS cn,
info_type AS it,
info_type AS it3,
keyword AS k,
movie_companies AS mc,
movie_info AS mi,
movie_keyword AS mk,
name AS n,
person_info AS pi,
role_type AS rt,
title AS t
WHERE cct1.kind {literals[0]}
AND cct2.kind {literals[1]}
AND {literals[2]}
AND {literals[3]}
AND {literals[4]}
AND it.info = '{literals[5]}'
AND it3.info = '{literals[6]}'
AND {literals[7]}
AND {literals[8]}
AND {literals[9]}
AND {literals[10]}
AND {literals[11]}
AND t.id = mi.movie_id
AND t.id = mc.movie_id
AND t.id = ci.movie_id
AND t.id = mk.movie_id
AND t.id = cc.movie_id
AND mc.movie_id = ci.movie_id
AND mc.movie_id = mi.movie_id
AND mc.movie_id = mk.movie_id
AND mc.movie_id = cc.movie_id
AND mi.movie_id = ci.movie_id
AND mi.movie_id = mk.movie_id
AND mi.movie_id = cc.movie_id
AND ci.movie_id = mk.movie_id
AND ci.movie_id = cc.movie_id
AND mk.movie_id = cc.movie_id
AND cn.id = mc.company_id
AND it.id = mi.info_type_id
AND n.id = ci.person_id
AND rt.id = ci.role_id
AND n.id = an.person_id
AND ci.person_id = an.person_id
AND chn.id = ci.person_role_id
AND n.id = pi.person_id
AND ci.person_id = pi.person_id
AND it3.id = pi.info_type_id
AND k.id = mk.keyword_id
AND cct1.id = cc.subject_id
AND cct2.id = cc.status_id;
'''
return sql
def change_query_28a(literals):
sql = f'''
SELECT MIN(cn.name) AS movie_company,
MIN(mi_idx.info) AS rating,
MIN(t.title) AS complete_euro_dark_movie
FROM complete_cast AS cc,
comp_cast_type AS cct1,
comp_cast_type AS cct2,
company_name AS cn,
company_type AS ct,
info_type AS it1,
info_type AS it2,
keyword AS k,
kind_type AS kt,
movie_companies AS mc,
movie_info AS mi,
movie_info_idx AS mi_idx,
movie_keyword AS mk,
title AS t
WHERE cct1.kind {literals[0]}
AND cct2.kind {literals[1]}
AND {literals[2]}
AND it1.info = '{literals[3]}'
AND it2.info = '{literals[4]}'
AND {literals[5]}
AND {literals[6]}
AND {literals[7]}
AND {literals[8]}
AND {literals[9]}
AND {literals[10]}
AND kt.id = t.kind_id
AND t.id = mi.movie_id
AND t.id = mk.movie_id
AND t.id = mi_idx.movie_id
AND t.id = mc.movie_id
AND t.id = cc.movie_id
AND mk.movie_id = mi.movie_id
AND mk.movie_id = mi_idx.movie_id
AND mk.movie_id = mc.movie_id
AND mk.movie_id = cc.movie_id
AND mi.movie_id = mi_idx.movie_id
AND mi.movie_id = mc.movie_id
AND mi.movie_id = cc.movie_id
AND mc.movie_id = mi_idx.movie_id
AND mc.movie_id = cc.movie_id
AND mi_idx.movie_id = cc.movie_id