server/mssteps.py
changeset 341 0a426be2f3a2
parent 257 4c7d3af7e94d
child 448 ce91d0f23ed2
--- a/server/mssteps.py	Wed Jan 07 14:55:16 2009 +0100
+++ b/server/mssteps.py	Wed Jan 07 14:57:03 2009 +0100
@@ -264,6 +264,22 @@
         return (self.__class__.__name__, self.limit, self.offset)
 
 
+class IntersectStep(UnionStep):
+    """return intersection of results of child in-memory steps (e.g. OneFetchStep / AggrStep)"""
+        
+    def execute(self):
+        """execute this step"""
+        result = set()
+        for step in self.children:
+            result &= frozenset(step.execute())
+        result = list(result)
+        if self.offset:
+            result = result[offset:]
+        if self.limit:
+            result = result[:limit]
+        return result
+
+
 class UnionFetchStep(Step):
     """union results of child steps using temporary tables (e.g. FetchStep)"""
 
@@ -272,4 +288,4 @@
         self.execute_children()
 
 
-__all__ = ('FetchStep', 'AggrStep', 'UnionStep', 'UnionFetchStep')
+__all__ = ('FetchStep', 'AggrStep', 'UnionStep', 'UnionFetchStep', 'IntersectStep')