dynamodb-toolbox/dynamodb-toolbox

Improve Scan response type based on Select option and projected attributes

Closed this issue · 0 comments

There are a lot of edge cases based on the presence of an index, wether it is local or global, and what attributes are projected.

Here's a recap of the scan Select JS Docs:

Possible values are ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES, COUNT and SPECIFIC_ATTRIBUTE.

By default (no index, no projection expression), Select value is ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES is not a valid Select option, and SPECIFIC_ATTRIBUTE can contain any attribute.

If a local Index is specified:

  • ALL_ATTRIBUTES is possible: DynamoDB will either get attributes from the index if all attributes are projected, either refetch them from the parent table.
  • ALL_PROJECTED_ATTRIBUTES becomes a valid Select option, that should impact the response Items type
  • SPECIFIC_ATTRIBUTE can contain any attribute (to confirm), but at a performance cost if attributes are not projected. It should also impact the response Items type.
  • COUNT is always a valid option

If a global Index is specified:

  • ALL_ATTRIBUTES is possible ONLY IF all attributes are projected. Otherwise, it should lead to an error (to confirm).
  • ALL_PROJECTED_ATTRIBUTES becomes a valid Select option, that should impact the response Items type
  • SPECIFIC_ATTRIBUTE MUST contain only projected attribute (to confirm)
  • COUNT is always a valid option

If a ProjectionExpression is specified:

  • ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES and COUNT are NOT valid Select option
  • SPECIFIC_ATTRIBUTES is the only valid option and is the default value. If an index is specified, we observe the same pattern as above (MUST be projected attribute if index is global, CAN be non-projected attribute if index is local, but at a performance cost).