DynamoDB PartiQL: query on map key

0

Hello,

Could you please correct the following query so that to work in DynamoDB PartiQL ?

For the table "PicturesTagging" with item structure:

{
  "PictureS3BucketKeyPK": {
    "S": "pics-repository#pics#samsung_M#2021#2021.01.06_jumbo_craciun#20210102_120050.jpg"
  },
  "TagsTool": {
    "S": "aws_rekognition_worker_labels_no_params"
  },
  "Tags": {
    "M": {
      "personal:data:content:labels:dominant_category": {
        "S": "Buildings and Architecture"
      },
      "personal:data:content:labels:dominant_label": {
        "S": "Building"
      }
    }
  }
}

I need to get those items that contains a certain key fragment:

SELECT PictureS3BucketKeyPK, Tags
FROM PicturesTagging 
where begins_with("Tags", 'personal:data:content:labels:')

The query runs succesfully, but it returns no items, while the table has a lot like those.

Thank you,
Mihai ADAM

asked a year ago1092 views
1 Answer
0

Hi

In your Table the Tags attribute is a Map with two attributes personal:data:content:labels:dominant_category and personal:data:content:labels:dominant_label, in your query it looks like you are trying to query on the attribute name, that is not possible you need to query on the values.

A query to fetch all items that has the personal:data:content:labels:dominant_label attribute with a value that starts with Building would look like this:

SELECT PictureS3BucketKeyPK, Tags
FROM PicturesTagging 
where begins_with("Tags"."personal:data:content:labels:dominant_label", 'Building')

Hope it helps.

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions