~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to storm/expr.py

  • Committer: James Henstridge
  • Date: 2009-10-21 10:11:50 UTC
  • mfrom: (329.2.2 storm.bug-242813)
  • Revision ID: james@jamesh.id.au-20091021101150-0jegr4v4r7oj7o1v
Nested set expressions are now flattened when safe.

Before hand, it was easy to hit Python's recursion limit when building 
large unions with ResultSet.union() (similar for intersect() and 
except()).  Now the set expression constructor will try to flatten such 
expressions, which leads to simpler expression compilation.
[r=jkakar,gabrielgrant] [f=242813]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1099
1099
        self.order_by = kwargs.get("order_by", Undef)
1100
1100
        self.limit = kwargs.get("limit", Undef)
1101
1101
        self.offset = kwargs.get("offset", Undef)
 
1102
        # If the first expression is of a compatible type, directly
 
1103
        # include its sub expressions.
 
1104
        if len(self.exprs) > 0:
 
1105
            first = self.exprs[0]
 
1106
            if (isinstance(first, self.__class__) and
 
1107
                first.all == self.all and
 
1108
                first.limit is Undef and
 
1109
                first.offset is Undef):
 
1110
                self.exprs = first.exprs + self.exprs[1:]
 
1111
 
1102
1112
 
1103
1113
@compile.when(SetExpr)
1104
1114
def compile_set_expr(compile, expr, state):