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

已提問 1 年前檢視次數 1146 次
1 個回答
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
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南