Revision a847494c

b/pithos/backends/lib/sqlalchemy/node.py
35 35
from sqlalchemy import Table, Integer, BigInteger, DECIMAL, Column, String, MetaData, ForeignKey
36 36
from sqlalchemy.types import Text
37 37
from sqlalchemy.schema import Index, Sequence
38
from sqlalchemy.sql import func, and_, or_, not_, null, select, bindparam, text
38
from sqlalchemy.sql import func, and_, or_, not_, null, select, bindparam, text, exists
39 39
from sqlalchemy.ext.compiler import compiles
40 40
from sqlalchemy.engine.reflection import Inspector
41 41

  
......
819 819
            start = strprevling(prefix)
820 820
        nextling = strnextling(prefix)
821 821
        
822
        a = self.attributes.alias('a')
823 822
        v = self.versions.alias('v')
824 823
        n = self.nodes.alias('n')
825 824
        s = select([n.c.path, v.c.serial]).distinct()
......
830 829
        s = s.where(v.c.cluster != except_cluster)
831 830
        s = s.where(v.c.node.in_(select([self.nodes.c.node],
832 831
            self.nodes.c.parent == parent)))
833
        if domain and filterq:
834
            s = s.where(a.c.serial == v.c.serial)
835
            s = s.where(a.c.domain == domain)
836 832
        
837 833
        s = s.where(n.c.node == v.c.node)
838 834
        s = s.where(and_(n.c.path > bindparam('start'), n.c.path < nextling))
......
844 840
            s = s.where(or_(*conj))
845 841
        
846 842
        if domain and filterq:
843
            a = self.attributes.alias('a')
847 844
            included, excluded, opers = parse_filters(filterq)
848 845
            if included:
849
                s = s.where(a.c.key.in_(x for x in included))
846
                subs = select([1])
847
                subs = subs.where(a.c.serial == v.c.serial)
848
                subs = subs.where(a.c.domain == domain)
849
                subs = subs.where(or_(*[a.c.key.op('=')(x) for x in included]))
850
                print '---', str(subs)
851
                s = s.where(exists(subs))
850 852
            if excluded:
851
                s = s.where(not_(a.c.key.in_(x for x in excluded)))
853
                subs = select([1])
854
                subs = subs.where(a.c.serial == v.c.serial)
855
                subs = subs.where(a.c.domain == domain)
856
                subs = subs.where(or_(*[a.c.key.op('=')(x) for x in excluded]))
857
                print '---', str(subs)
858
                s = s.where(not_(exists(subs)))
852 859
            if opers:
853
                for k, o, v in opers:
854
                    s = s.where(or_(a.c.key == k and a.c.value.op(o)(v)))
860
                subs = select([1])
861
                subs = subs.where(a.c.serial == v.c.serial)
862
                subs = subs.where(a.c.domain == domain)
863
                subs = subs.where(and_(*[a.c.key == k and a.c.value.op(o)(v) for k, o, v in opers]))
864
                print '---', str(subs)
865
                s = s.where(exists(subs))
855 866
        
856 867
        s = s.order_by(n.c.path)
857 868
        
b/pithos/lib/filter.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
import re
35
import operator
35

  
36 36

  
37 37
_regexfilter = re.compile('(!?)\s*(\S+?)\s*(?:(=|!=|<=|>=|<|>)\s*(\S*?)\s*)?$', re.UNICODE)
38 38

  
39
OPERATORS = {'=':operator.eq,
40
             '!=':operator.ne,
41
             '<=':operator.le,
42
             '>=':operator.ge,
43
             '<':operator.lt,
44
             '>':operator.gt
45
}
46 39

  
47 40
def parse_filters(terms):
48 41
    included = []

Also available in: Unified diff