@@ -294,79 +294,3 @@ def min_timestamp(self):
294
294
def max_timestamp (self ):
295
295
return lib .tdb_max_timestamp (self ._db )
296
296
297
- def _parse_filter (self , filter_expr ):
298
- # filter_expr syntax in CNF:
299
- # CNF is a list of clauses. A clause is a list of terms. Each term
300
- # is an expression of the form FIELD OP VALUE, where FIELD is a field
301
- # name, VALUE is field value and OP is either 'equal' or 'notequal'.
302
- # Term is represented as dictionary {'field': F, 'value' : V, 'op' : O}
303
- # If op is omitted, it defaults to 'equal'
304
- #
305
- # Example:
306
- #
307
- # [
308
- # [{'field' : 'network', 'value' : 'Google', 'op' : 'notequal'},
309
- # {'field' : 'network', 'value' : 'Yahoo', 'op' : 'equal'},
310
- # {'field' : 'browser', 'value' : 'Chrome'}],
311
- # ['field' : 'is_valud', 'value' : '1'}
312
- # ]
313
- def item (field , value ):
314
- return lib .tdb_get_item (self ._db , field , value , c_uint64 (len (value )))
315
-
316
- def parse_clause (clause_expr ):
317
- clause = [0 ]
318
- for term in clause_expr :
319
- op = term .get ('op' , 'equal' )
320
- if op not in ('equal' , 'notequal' ):
321
- raise ValueError ('Invalid op: ' + op )
322
- try :
323
- field = self .field (term ['field' ])
324
- clause .extend ((0 if op == 'equal' else 1 ,
325
- item (field , term ['value' ])))
326
-
327
- except ValueError :
328
- always_true = (term ['value' ] == '' ) == (op == 'equal' )
329
- clause .extend ((1 if always_true else 0 , 0 ))
330
- clause [0 ] = len (clause ) - 1
331
- return clause
332
-
333
- q = []
334
- for clause in filter_expr :
335
- q .extend (parse_clause (clause ))
336
- return (c_uint64 * len (q ))(* q )
337
-
338
- def set_filter (self , filter_expr ):
339
- q = self ._parse_filter (filter_expr )
340
- if lib .tdb_set_filter (self ._db , q , len (q )):
341
- raise TrailDBError ("Setting filter failed (out of memory?)" )
342
-
343
- def get_filter (self ):
344
-
345
- def construct_clause (clause_arr ):
346
- clause = []
347
- for i in range (0 , len (clause_arr ), 2 ):
348
- is_negative = clause_arr [i ]
349
- item = clause_arr [i + 1 ]
350
- if item == 0 :
351
- clause .append (is_negative == 1 )
352
- else :
353
- field = item & 255
354
- field_str = self .fields [field ]
355
- val = item >> 8
356
- value_size = c_uint64 ()
357
- value = lib .tdb_get_value (self ._db , field , val , value_size )
358
- clause .append ({'op' : 'notequal' if is_negative else 'equal' ,
359
- 'field' : field_str ,
360
- 'value' : value [0 :value_size .value ]})
361
- return clause
362
-
363
- filter_len = c_uint64 (0 )
364
- filter_arr = lib .tdb_get_filter (self ._db , byref (filter_len ))
365
- q = []
366
- i = 0
367
- while i < filter_len .value :
368
- clause_len = filter_arr [i ]
369
- q .append (construct_clause (filter_arr [i + 1 :i + 1 + clause_len ]))
370
- i += 1 + clause_len
371
-
372
- return q
0 commit comments