Skip to content
This repository
Browse code

Added scan to layer2 and Table

  • Loading branch information...
commit 522e054866899d6acf8b08d5ae8ff3e447e81c6e 1 parent 61b6fd7
Chris Moyer kopertop authored

Showing 2 changed files with 79 additions and 6 deletions. Show diff stats Hide diff stats

  1. +47 1 boto/dynamodb/layer2.py
  2. +32 5 boto/dynamodb/table.py
48 boto/dynamodb/layer2.py
@@ -472,5 +472,51 @@ def query(self, table, hash_key, range_key_condition=None,
472 472 return items
473 473
474 474
  475 + def scan(self, table, scan_filter=None,
  476 + attributes_to_get=None, limit=None,
  477 + count=False, exclusive_start_key=None):
  478 + """
  479 + Perform a scan of DynamoDB. This version is currently punting
  480 + and expecting you to provide a full and correct JSON body
  481 + which is passed as is to DynamoDB.
475 482
476   -
  483 + :type table: Table
  484 + :param table: The table to scan from
  485 +
  486 + :type scan_filter: dict
  487 + :param scan_filter: A Python version of the
  488 + ScanFilter data structure.
  489 +
  490 + :type attributes_to_get: list
  491 + :param attributes_to_get: A list of attribute names.
  492 + If supplied, only the specified attribute names will
  493 + be returned. Otherwise, all attributes will be returned.
  494 +
  495 + :type limit: int
  496 + :param limit: The maximum number of items to return.
  497 +
  498 + :type count: bool
  499 + :param count: If True, Amazon DynamoDB returns a total
  500 + number of items for the Scan operation, even if the
  501 + operation has no matching items for the assigned filter.
  502 +
  503 + :type exclusive_start_key: list or tuple
  504 + :param exclusive_start_key: Primary key of the item from
  505 + which to continue an earlier query. This would be
  506 + provided as the LastEvaluatedKey in that query.
  507 + """
  508 + response = True
  509 + while response:
  510 + if response is True:
  511 + pass
  512 + elif response.has_key("LastEvaluatedKey"):
  513 + exclusive_start_key = response['LastEvaluatedKey']
  514 + else:
  515 + break
  516 +
  517 + response = self.layer1.scan(table.name, scan_filter,
  518 + attributes_to_get,limit,
  519 + count, exclusive_start_key)
  520 + if response:
  521 + for item in response['Items']:
  522 + yield Item(table, attrs=item)
37 boto/dynamodb/table.py
@@ -270,11 +270,38 @@ def query(self, hash_key, range_key_condition=None,
270 270 return self.layer2.query(self, hash_key, range_key_condition,
271 271 attributes_to_get, consistent_read)
272 272
273   - def scan(self):
274   - pass
275   -
  273 + def scan(self, scan_filter=None,
  274 + attributes_to_get=None, limit=None,
  275 + count=False, exclusive_start_key=None):
  276 + """Scan through this table, this is a very long
  277 + and expensive operation, and should be avoided if
  278 + at all possible
276 279
  280 + :type table_name: str
  281 + :param table_name: The name of the table to scan.
277 282
278   -
279   -
  283 + :type scan_filter: dict
  284 + :param scan_filter: A Python version of the
  285 + ScanFilter data structure.
280 286
  287 + :type attributes_to_get: list
  288 + :param attributes_to_get: A list of attribute names.
  289 + If supplied, only the specified attribute names will
  290 + be returned. Otherwise, all attributes will be returned.
  291 +
  292 + :type limit: int
  293 + :param limit: The maximum number of items to return.
  294 +
  295 + :type count: bool
  296 + :param count: If True, Amazon DynamoDB returns a total
  297 + number of items for the Scan operation, even if the
  298 + operation has no matching items for the assigned filter.
  299 +
  300 + :type exclusive_start_key: list or tuple
  301 + :param exclusive_start_key: Primary key of the item from
  302 + which to continue an earlier query. This would be
  303 + provided as the LastEvaluatedKey in that query.
  304 + """
  305 + return self.layer2.scan(self, scan_filter,
  306 + attributes_to_get, limit, count,
  307 + exclusive_start_key)

3 comments on commit 522e054

Greg Taylor
Collaborator

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

Chris Moyer
Owner

that's just :rtype: generator right?

Greg Taylor
Collaborator

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

Please sign in to comment.
Something went wrong with that request. Please try again.