In Stitch’s Amazon DynamoDB integration, projection expressions serve as a method for selecting individual fields for replication. This is equivalent to column selection in other integrations.
By specifying a projection expression, you can replicate only the data you need for each table in your DynamoDB integration.
In this guide, we’ll cover:
Feature availability
The following table indicates the availability of Stitch’s DynamoDB projection expression feature for each version of the DynamoDB integration.
Integration version | Availability |
v1 | Supported |
What are projection expressions?
In DynamoDB, the default for queries is to return all fields in matching tables. A projection expression is used to specify or restrict the data returned in query results. By specifying a projection expression, you can specify the fields you want to return or exclude.
For example: Not specifying a expression in Stitch is similar to SELECT *
in SQL. If you wanted to only return a subset of fields, you’d specify them in the SELECT
clause:
SELECT name,
is_active
FROM customers
The DynamoDB integration supports the use of expression attributes in projection expressions. For more information, refer to DynamoDB’s documentation
Projection expression requirements for Stitch
Projection expressions are compatible with any of Stitch’s Replication Methods, including Log-based Incremental.
Projection expressions must adhere to the following:
-
Include the table’s hash/partition key (Primary Key). If you’re unsure which field is the partition key for a table, sign into your Amazon Web Services (AWS) account and look at the Table Details section for the table. The field in the Primary partition key field is the table’s Primary Key.
-
Cannot include conditional (condition) expressions. Stitch’s DynamoDB integration doesn’t currently support using conditions in projection expressions.
Projection expressions that don’t meet the above criteria will result in errors during extraction.
Defining a projection expression in Stitch
Adding a new projection expression
When you set a table to replicate in Stitch, you can define a projection expression for the table in the Table Settings page.
- In the DynamoDB integration, click the Tables to Replicate tab.
- Navigate to the desired table.
-
Click the checkbox to the left of the table to set it to replicate. This will also open the Table Details page:
- Click the View Table Settings button.
- On the Table Settings page, scroll down to the Fields to Replicate section.
-
Enter the projection expression you want the table to use in the Projection expression field:
-
Click Update Settings to save your changes.
- If your projection expression requires expression attributes, enter them in the Expression Attributes field.
Stitch will use the table’s projection expression during the next scheduled replication job, even if a job is currently in progress.
Modifying an existing projection expression
To modify an existing projection expression, follow the steps in the previous section, modifying the expression as needed. When finished, click Update Settings to save your changes.
Stitch will use the table’s projection expression during the next scheduled replication job, even if a job is currently in progress.
Note: Modifying a projection expression won’t trigger a full re-replication of a table. If the table uses a type of incremental replication, you’ll need to manually reset the table to backfill the values for any new fields.
Example projection expressions
In this section, we’ll look at some example projection expressions and their SQL equivalents.
Example table data
The examples use data from a table named customers
, which uses the name
field as a Primary Key. This table contains the following records:
name [pk] (string) | is_active (boolean) | details (object) | acquaintances (array) | comment (string) |
Finn |
true |
age: 15, type: human |
|
Also known as Finn the Human |
Jake |
true |
age: 6, type: dog |
|
Magical dog |
Bubblegum |
false |
age: 16, type: princess |
|
Rules over the Candy Kingdom |
Lady |
true |
age: 50, type: unicorn |
|
|
Ice King |
false |
age: 900, type: king |
|
Return only specified fields
Return only the specified fields (name
, is_active
) in the customers
table. If including multiple fields, separate them with a comma.
Projection query |
|
||||||||||||
SQL |
|
||||||||||||
Results |
|
Return specified fields in a map element
Using dot notation, return specified fields in a map element. This is formatted as <map_element_name>.<field>
.
In this example, the expression would return the top-level name
field and age
and type
fields from the details
map.
Refer to DynamoDB’s documentation for more examples of dot notation for map elements.
Projection query |
|
||||||||||||
SQL |
In destinations - like Snowflake - that also use dot notation to query nested data, the query might look like this:
|
||||||||||||
Results |
|
Return specified fields in a list element
To access an element in a list, use the dereference operator ([n]
), where n
is the number of the element in the list. This is formatted as <list_element_name>[n]
.
In this example, the expression would return the top-level name
field and second element from the acquaintances
list.
Refer to DynamoDB’s documentation for more examples of accessing fields in lists.
Projection query |
|
||||||||||||
Results |
|
Return a field using an expression attribute
Use an expression attribute to reference a field when the field name cannot be used in a projection expression. In this example, comment
is a reserved word and cannot be used in a query. You can define an expression attribute name, starting with a #
, that will be used as a placeholder for the field name.
Refer to DynamoDB’s documentation for more examples of expression attributes.
Projection query |
|
||||||||||||||||||
Expression attributes |
|
||||||||||||||||||
Results |
|
Error troubleshooting
If a table’s projection expression doesn’t meet Stitch’s requirements, a critical error will arise during Extraction. Extractions will not be successful until the issue is resolved.
Refer to the Database integration extraction error reference for DynamoDB extraction errors and help resolving them.
Resources
Related | Troubleshooting |
Questions? Feedback?
Did this article help? If you have questions or feedback, feel free to submit a pull request with your suggestions, open an issue on GitHub, or reach out to us.