Database Reference
In-Depth Information
Scanning tables
A scan operation evaluates each and every item in the table. Usually, it retrieves every item
(with all the attributes along with all the items) of the table. This is the reason why the scan
operation is not preferred. It is always recommended that you use query whenever possible.
However, it is possible for us to retrieve only specific attributes using the Attrib-
utesToGet parameter, similar to the way we saw with query. Additionally, we can filter
the number of items retrieved by the scan using the scan filter condition. For instance, if we
assume that there are 100 items available in the table, and if the scan filter filters out 10
items using strong consistent read (which consumes a maximum of 1 KB capacity units per
item), can you tell how many capacity units were eaten up by this scan operation? If you
think it consumes 100 capacity units, then you're in the right boat, because the capacity unit
is not a measure of how many items (hoping that every item is less than 1 KB in size) are
returned, it is the measure of how many items were evaluated or scanned. So even if all the
items were filtered out by the scan operation, or all items passed through the scan opera-
tion, it consumes the same number of capacity units.
First of all, we see how a simple scan looks:
ScanRequest scanRequest = new ScanRequest()
.withTableName( "Tbl_Book" );
ScanResult result = client .scan(scanRequest);
The previous code is the minimum parameter required to perform a scan operation on a
table. First, we need to create an instance of the
com.amazonaws.services.dynamodbv2.model.ScanRequest (or latest)
class, and then to that instance, we need to add a few mandatory configuration details, such
as table name, and optional details, such as index name, scan filter, and so on (which we
will discuss later).
Once the ScanRequest instance is configured, we can invoke the scan method available
with DynamoDBClient (just as we invoked the createTable method to create a
table) enclosing the ScanRequest instance. The scan operation will return an instance of
com.amazonaws.services.dynamodbv2.model.ScanResult .
The scan request gives the result as pages, each with 1 MB of data. This is called pagina-
tion. In order to retrieve the next 1 MB of data, we need to execute the scan request again.
This is where the exclusive start key is useful. The ScanResult class has a method
Search WWH ::




Custom Search