By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I achieve the result of doing beginsWith on 2 different attributes in a single query?

0

i need to do beginsWith on the account and folder hierarchy paths. Example: accountHierarchyPath: account1#account2#account3 pageHierarchyPath: folder1#folder2#folder3

i would like to do beginsWith account1 and beginsWith folder1#folder2 and I only know these 2 values, but the ownerHierarchyPath also has account2 and account3 which I don't know.

how would i get all folders under folder2, owned by account1 since i cannot do beginsWith on 2 different attributes?

asked 15 days ago20 views
1 Answer
0

To achieve the result of doing beginsWith on two different attributes in a single query, you can use a composite attribute approach in Amazon SimpleDB or create a composite key in Amazon DynamoDB. Here's how you can accomplish this:

  1. Create a composite attribute: Combine the accountHierarchyPath and pageHierarchyPath into a single attribute. For example, you could create a new attribute called "hierarchyPath" that concatenates both paths:

hierarchyPath = accountHierarchyPath + "#" + pageHierarchyPath

So, for your example, it would look like: hierarchyPath: account1#account2#account3#folder1#folder2#folder3

  1. Query using the composite attribute: Now you can perform a single beginsWith query on this composite attribute. Your query would look something like this:

select * from myDomain where hierarchyPath beginswith 'account1#' and hierarchyPath like '%#folder1#folder2#%'

This query will return all items where the accountHierarchyPath starts with "account1" and the pageHierarchyPath includes "folder1#folder2" at any position.

By using this composite attribute approach, you can effectively perform a beginsWith operation on both attributes in a single query. This method is more efficient than using multiple predicates and allows you to search for patterns across both hierarchies simultaneously.

Remember to use appropriate separators (like '#') when combining variable-length fields to ensure accurate querying. Also, make sure to update the composite attribute whenever either of the original attributes changes to keep the data consistent.
Sources
Tuning Your Queries Using Composite Attributes - Amazon SimpleDB

profile picture
answered 15 days 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