Commits

Anonymous committed 3031b2d

add support for esk, lek and limit in scan + update related doc. Still need to add tests

Comments (0)

Files changed (4)

 This section documents all user visible changes included between ddbmock
 versions 0.4.0 and versions 0.4.1
 
+Additions
+---------
+
+ - Add support for ``ExclusiveStartKey``, ``LastEvaluatedKey`` and ``Limit`` for ``Scan``
+
 Changes
 -------
 
  - Wrap all write operations in a table scope lock: each individual operation should be atomic
  - Addressed Thread safety issues
- - Add option to disable status update timers
+ - Add option to disable status update timers (#8)
+ - Fix BETWEEN bug (#7)
+
 
 =============
 ddbmock 0.4.0

ddbmock/database/table.py

         """
         #FIXME: naive implementation (too)
         #TODO:
-        # - reverse
         # - esk
-        # - limit
         # - size limit
-        # - last evaluated key
 
         size = ItemSize(0)
         scanned = 0
+        lek = None
         results = []
+        skip = start is not None
 
         for item in self.store:
-            size += item.get_size()
-            scanned += 1
+            # first, skip all items before start
+            if skip:
+                if start['HashKeyElement'] != item[self.hash_key.name]:
+                    continue
+                if self.range_key and start['RangeKeyElement'] == item[self.range_key.name]:
+                    continue
+                skip = False
+                continue
+
+            # match filters ?
             if item.match(scan_conditions):
                 results.append(item.filter(fields))
 
-        return Results(results, size, None, scanned)
+            # update stats
+            size += item.get_size()
+            scanned += 1
+
+            # quit ?
+            if scanned == limit:
+                lek = {
+                    u'HashKeyElement': hash_key,
+                    u'RangeKeyElement': item[rk_name],
+                }
+                break
+
+        return Results(results, size, lek, scanned)
 
     @classmethod
     def from_dict(cls, data):

ddbmock/operations/scan.py

         "Count": len(results.items),
         "ScannedCount": results.scanned,
         "ConsumedCapacityUnits": capacity,
-        #TODO: last evaluated key where applicable
     }
 
+    if results.last_key is not None:
+        ret['LastEvaluatedKey'] = results.last_key
+
     if not post[u'Count']:
         ret[u'Items'] = results.items
 

docs/pages/status.rst

 - ``PutItem`` DONE
 - ``DeleteItem`` DONE
 - ``UpdateItem`` ALMOST
-- ``BatchGetItem`` DONE*
-- ``BatchWriteItem`` DONE*
+- ``BatchGetItem`` DONE
+- ``BatchWriteItem`` DONE
 - ``Query`` DONE
-- ``Scan`` DONE*
+- ``Scan`` DONE
 
-There basically are no support for ``ExclusiveStartKey``, and their associated
-features at all in ddbmock. This affects all "*" operations. ``Query`` is the
-only exception.
+All "Bulk" actions will handle the whole batch in a single pass, unless instructed
+to otherwise through ``limit`` parameter. Beware that real dynamoDB will most
+likely split bigger one. If you rely on high level libraries such as Boto, don't
+worry about this.
 
 ``UpdateItem`` has a different behavior when the target item did not exist prior
 the update operation. In particular, the ``ADD`` operator will always behave as