1

Is it possible to add constraint to a dynamodb query expression that states that a GSI should be not null?

Can somebody provide examples.

Is possible to construct a query like the one below?

new DynamoDBQueryExpression<XXX>()
            .withHashKeyValues(YYY).withKeyConditionExpression(GSI != NULL);

Note: Please let me know if this is possible in during query and not during filter time?

gman
  • 1,242
  • 2
  • 16
  • 29

2 Answers2

1

if you're like me and you landed on this page while finding the answer to the above question, here's the thread you need to see

How do you query for a non-existent (null) attribute in DynamoDB

0

The DynamoDB String attribute can't have NULL or empty string.

When you try to insert NULL, the API should throw the below exception:-

java.lang.IllegalArgumentException: Input value must not be null

When you try to insert empty string, the API should throw the below exception:-

com.amazonaws.AmazonServiceException: One or more parameter values were invalid: An AttributeValue may not contain an empty string

If you want to add additional filters on some attributes (i.e. attributes other than hash or range key), you can use the below syntax (i.e. withFilterExpression).

Not equals operator is "<>"

Map<String, AttributeValue> eav = new HashMap<String, AttributeValue>();
eav.put(":val1", new AttributeValue().withS("Some value"));

DynamoDBQueryExpression<XXX> queryExpression = new DynamoDBQueryExpression<XXX>();
    queryExpression.withHashKeyValues(hashKeyValues);       
    queryExpression.withFilterExpression("docType <> :val1").withExpressionAttributeValues(eav);
notionquest
  • 37,595
  • 6
  • 111
  • 105