@@ -13,15 +13,20 @@ class Query:
13
13
cond_ops = ['=' , '>' , '<' , 'OP' ]
14
14
syms = ['SELECT' , 'WHERE' , 'AND' , 'COL' , 'TABLE' , 'CAPTION' , 'PAGE' , 'SECTION' , 'OP' , 'COND' , 'QUESTION' , 'AGG' , 'AGGOPS' , 'CONDOPS' ]
15
15
16
- def __init__ (self , sel_index , agg_index , conditions = tuple ()):
16
+ def __init__ (self , sel_index , agg_index , conditions = tuple (), ordered = False ):
17
17
self .sel_index = sel_index
18
18
self .agg_index = agg_index
19
19
self .conditions = list (conditions )
20
+ self .ordered = ordered
20
21
21
22
def __eq__ (self , other ):
22
23
if isinstance (other , self .__class__ ):
23
24
indices = self .sel_index == other .sel_index and self .agg_index == other .agg_index
24
- conds = [(col , op , cond .lower () if isinstance (cond , str ) else cond ) for col , op , cond in self .conditions ] == [(col , op , cond .lower () if isinstance (cond , str ) else cond ) for col , op , cond in other .conditions ]
25
+ if other .ordered :
26
+ conds = [(col , op , str (cond ).lower ()) for col , op , cond in self .conditions ] == [(col , op , str (cond ).lower ()) for col , op , cond in other .conditions ]
27
+ else :
28
+ conds = set ([(col , op , str (cond ).lower ()) for col , op , cond in self .conditions ]) == set ([(col , op , str (cond ).lower ()) for col , op , cond in other .conditions ])
29
+
25
30
return indices and conds
26
31
return NotImplemented
27
32
@@ -52,8 +57,8 @@ def lower(self):
52
57
return self .__class__ (self .sel_index , self .agg_index , conds )
53
58
54
59
@classmethod
55
- def from_dict (cls , d ):
56
- return cls (sel_index = d ['sel' ], agg_index = d ['agg' ], conditions = d ['conds' ])
60
+ def from_dict (cls , d , ordered = False ):
61
+ return cls (sel_index = d ['sel' ], agg_index = d ['agg' ], conditions = d ['conds' ], ordered = ordered )
57
62
58
63
@classmethod
59
64
def from_tokenized_dict (cls , d ):
0 commit comments