Reputation: 6749
I want to fetch a DynamoDB table which is attached to a Query
of an AppSync schema for getting only the null or empty values of an attribute which has a Global Secondary Index (GSI).
I tried the followings but could not get a result:
Throws [Invalid operator used in KeyConditionExpression: OR] :
"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
"expression" : "attribute_not_exists(myAttr) or myAttr = :null",
"expressionValues" : {
":null" : { "NULL" : null }
}
}
Throws [Invalid operator used in KeyConditionExpression: attribute_not_exists] :
"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
"expression" : "myAttr = :null",
"expressionValues" : {
":null" : { "NULL" : null }
}
}
Throws [One or more parameter values were invalid: Condition parameter type does not match schema type] :
"operation" : "Query",
"index" : "myAttrIndex",
"query" : {
"expression" : "myAttr = :null",
"expressionValues" : {
":null" : { "NULL" : null }
}
}
How to write a query documents filtering out non null values of a string attribute?
Upvotes: 1
Views: 1680
Reputation: 6178
By default, Global Secondary Indices are sparse.
For any item in a table, DynamoDB will only write a corresponding entry to a global secondary index if the index key value is present in the item. For global secondary indexes, this is the index partition key and its sort key (if present). If the index key value(s) do not appear in every table item, the index is said to be sparse.
If you need myAttr
attribute null values to be included in the GSI table, you could set a dummy value (e.g "NULL") and then query on that value. Note that all the table items will now be included in the GSI table, which will increase your cost.
For more details: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general-sparse-indexes.html
Upvotes: 1