|
@@ -642,7 +642,7 @@ is not a reference : '%s' field '%s'" % (bref_leo, bref_fname))
|
642
|
642
|
#@return a list of pymongo filters ( dict {FIELD:{OPERATOR:VALUE}} )
|
643
|
643
|
def __process_filters(self,target, filters, relational_filters):
|
644
|
644
|
# Simple filters lodel2 -> pymongo converting
|
645
|
|
- res = self.__filters2mongo(filters)
|
|
645
|
+ res = self.__filters2mongo(filters, target)
|
646
|
646
|
rfilters = self.__prepare_relational_filters(target, relational_filters)
|
647
|
647
|
#Now that everything is well organized, begin to forge subquerie
|
648
|
648
|
#filters
|
|
@@ -706,7 +706,7 @@ is not a reference : '%s' field '%s'" % (bref_leo, bref_fname))
|
706
|
706
|
#warnings in some case (2 different values for a same op
|
707
|
707
|
#on a same field on a same collection)
|
708
|
708
|
mongofilters = cls.__op_value_listconv(
|
709
|
|
- rfilters[fname][leobject][rfield])
|
|
709
|
+ rfilters[fname][leobject][rfield], target.field(fname))
|
710
|
710
|
rfilters[fname][leobject][rfield] = mongofilters
|
711
|
711
|
|
712
|
712
|
##@brief Generate a tree from relational_filters
|
|
@@ -759,13 +759,13 @@ is not a reference : '%s' field '%s'" % (bref_leo, bref_fname))
|
759
|
759
|
#@param filters list : list of lodel filters
|
760
|
760
|
#@return dict representing pymongo conditions
|
761
|
761
|
@classmethod
|
762
|
|
- def __filters2mongo(cls, filters):
|
|
762
|
+ def __filters2mongo(cls, filters, target):
|
763
|
763
|
res = dict()
|
764
|
764
|
eq_fieldname = [] #Stores field with equal comparison OP
|
765
|
765
|
for fieldname, op, value in filters:
|
766
|
766
|
oop = op
|
767
|
767
|
ovalue = value
|
768
|
|
- op, value = cls.__op_value_conv(op, value)
|
|
768
|
+ op, value = cls.__op_value_conv(op, value, target.field(fieldname))
|
769
|
769
|
if op == '=':
|
770
|
770
|
eq_fieldname.append(fieldname)
|
771
|
771
|
if fieldname in res:
|
|
@@ -798,7 +798,7 @@ by an equality filter")
|
798
|
798
|
#@param value mixed : the value
|
799
|
799
|
#@return a tuple(mongo_op, mongo_value)
|
800
|
800
|
@classmethod
|
801
|
|
- def __op_value_conv(cls, op, value):
|
|
801
|
+ def __op_value_conv(cls, op, value, dhdl):
|
802
|
802
|
if op not in cls.lodel2mongo_op_map:
|
803
|
803
|
msg = "Invalid operator '%s' found" % op
|
804
|
804
|
raise MongoDbDataSourceError(msg)
|
|
@@ -806,10 +806,12 @@ by an equality filter")
|
806
|
806
|
mongoval = value
|
807
|
807
|
#Converting lodel2 wildcarded string into a case insensitive
|
808
|
808
|
#mongodb re
|
809
|
|
- logger.info((op,value))
|
810
|
809
|
if mongop in cls.mongo_op_re:
|
811
|
810
|
if value.startswith('(') and value.endswith(')') and ',' in value:
|
812
|
|
- mongoval = [ item for item in mongoval[1:-1].split(',') ]
|
|
811
|
+ if (dhdl.cast_type is not None):
|
|
812
|
+ mongoval = [ dhdl.cast_type(item) for item in mongoval[1:-1].split(',') ]
|
|
813
|
+ else:
|
|
814
|
+ mongoval = [ item for item in mongoval[1:-1].split(',') ]
|
813
|
815
|
elif mongop == 'like':
|
814
|
816
|
#unescaping \
|
815
|
817
|
mongoval = value.replace('\\\\','\\')
|
|
@@ -821,16 +823,15 @@ by an equality filter")
|
821
|
823
|
#Replacing every other unescaped wildcard char
|
822
|
824
|
mongoval = cls.wildcard_re.sub('.*', mongoval)
|
823
|
825
|
mongoval = {'$regex': mongoval, '$options': 'i'}
|
824
|
|
-
|
825
|
826
|
return (op, mongoval)
|
826
|
827
|
|
827
|
828
|
##@brief Convert a list of tuple(OP, VALUE) into a pymongo filter dict
|
828
|
829
|
#@return a dict with mongo op as key and value as value...
|
829
|
830
|
@classmethod
|
830
|
|
- def __op_value_listconv(cls, op_value_list):
|
|
831
|
+ def __op_value_listconv(cls, op_value_list, dhdl):
|
831
|
832
|
result = dict()
|
832
|
833
|
for op, value in op_value_list:
|
833
|
|
- mongop, mongoval = cls.__op_value_conv(op, value)
|
|
834
|
+ mongop, mongoval = cls.__op_value_conv(op, value, dhdl)
|
834
|
835
|
if mongop in result:
|
835
|
836
|
warnings.warn("Duplicated value given for a single \
|
836
|
837
|
field/operator couple in a query. We will keep only the first one")
|