Permalink
Browse files

Added scan to layer2 and Table

  • Loading branch information...
1 parent 61b6fd7 commit 522e054866899d6acf8b08d5ae8ff3e447e81c6e @kopertop kopertop committed Jan 24, 2012
Showing with 79 additions and 6 deletions.
  1. +47 −1 boto/dynamodb/layer2.py
  2. +32 −5 boto/dynamodb/table.py
View
48 boto/dynamodb/layer2.py
@@ -472,5 +472,51 @@ def query(self, table, hash_key, range_key_condition=None,
return items
+ def scan(self, table, scan_filter=None,
+ attributes_to_get=None, limit=None,
+ count=False, exclusive_start_key=None):
+ """
+ Perform a scan of DynamoDB. This version is currently punting
+ and expecting you to provide a full and correct JSON body
+ which is passed as is to DynamoDB.
-
+ :type table: Table
+ :param table: The table to scan from
+
+ :type scan_filter: dict
+ :param scan_filter: A Python version of the
+ ScanFilter data structure.
+
+ :type attributes_to_get: list
+ :param attributes_to_get: A list of attribute names.
+ If supplied, only the specified attribute names will
+ be returned. Otherwise, all attributes will be returned.
+
+ :type limit: int
+ :param limit: The maximum number of items to return.
+
+ :type count: bool
+ :param count: If True, Amazon DynamoDB returns a total
+ number of items for the Scan operation, even if the
+ operation has no matching items for the assigned filter.
+
+ :type exclusive_start_key: list or tuple
+ :param exclusive_start_key: Primary key of the item from
+ which to continue an earlier query. This would be
+ provided as the LastEvaluatedKey in that query.
+ """
+ response = True
+ while response:
+ if response is True:
+ pass
+ elif response.has_key("LastEvaluatedKey"):
+ exclusive_start_key = response['LastEvaluatedKey']
+ else:
+ break
+
+ response = self.layer1.scan(table.name, scan_filter,
+ attributes_to_get,limit,
+ count, exclusive_start_key)
+ if response:
+ for item in response['Items']:
+ yield Item(table, attrs=item)
View
37 boto/dynamodb/table.py
@@ -270,11 +270,38 @@ def query(self, hash_key, range_key_condition=None,
return self.layer2.query(self, hash_key, range_key_condition,
attributes_to_get, consistent_read)
- def scan(self):
- pass
-
+ def scan(self, scan_filter=None,
+ attributes_to_get=None, limit=None,
+ count=False, exclusive_start_key=None):
+ """Scan through this table, this is a very long
+ and expensive operation, and should be avoided if
+ at all possible
+ :type table_name: str
+ :param table_name: The name of the table to scan.
-
-
+ :type scan_filter: dict
+ :param scan_filter: A Python version of the
+ ScanFilter data structure.
+ :type attributes_to_get: list
+ :param attributes_to_get: A list of attribute names.
+ If supplied, only the specified attribute names will
+ be returned. Otherwise, all attributes will be returned.
+
+ :type limit: int
+ :param limit: The maximum number of items to return.
+
+ :type count: bool
+ :param count: If True, Amazon DynamoDB returns a total
+ number of items for the Scan operation, even if the
+ operation has no matching items for the assigned filter.
+
+ :type exclusive_start_key: list or tuple
+ :param exclusive_start_key: Primary key of the item from
+ which to continue an earlier query. This would be
+ provided as the LastEvaluatedKey in that query.
+ """
+ return self.layer2.scan(self, scan_filter,
+ attributes_to_get, limit, count,
+ exclusive_start_key)

3 comments on commit 522e054

@gtaylor

Can you add that these functions are generators to the documentation? That'll be an important distinction to make.

@kopertop
the boto project member

that's just :rtype: generator right?

@gtaylor

Yep, that'll do it. Thanks in advance, that'll be sure to save a few people some confusion.

Please sign in to comment.