DynamoDB filter condition and Limit - amazon-web-services

Can anyone help me to understand what is the best approach to handle condition filtering and Limit
I'm using dynanmodb to store some products and I want to use pagination with them.
Because some of the products are enabled I got to filter based on a field.
no problem until there.
When I use Limit, if I want to Limit the data to be returned the Limit will be applied after the query makes the filtering.
Here is the deal :
All the time the query will return the data and Limit based on the last item to top first one, and I get the Key to make the pagination to the top.
If I would like to retrieve from the top to the bottom I Will set Scan Index Forward = true, and do the same as the other query.
But I would like to get random products and do the pagination because I don't I apply something like that, all the time the same products from the first one to the bottom or unlike. but what about the products in the middle etc?
I'm using a simple schema :
PK: PRODS
SK: ITEM#RamdomID
thanks a lot, I appreciate any helpful comment.

Related

Show items with no data when filtering by field

Is there a way of filtering using a field but still keep showing items which don't have a value?
I have prepared a quick dummy test:
On the left, when i filter by "indicator name" by 'This' and 'that' values, countries with no data on either categories disappear. On the right, when it's not filtered, we see other countries even if they have no data. My problem is that I actually have a hundred indicators, that is why i need to filter that.
'Show items without data' has been already marked.
Is there a way around the filter to show all countries?
Model looks like this:
The work-around is to create a Measure and adding "+0".

DynamoDB GSI data modelling for an articles app

I want to create an articles application using serverless (AWS Lambda + DynamoDB + S3 for hosting the FE).
I have some questions regarding the "1 table approach".
The actions I want to follow:
Get latest (6) articles sorted by date
Get an article by id
Get the prev/next article relative to the article opened (based on creation date)
Get related articles by tags
Get comments by article
I have created an initial spreadsheet for the information:
The first problem I have is that for action nr. 1, I cannot get all the articles based on date, I've added the SK for articles as a date, but because the PK has separate articles, each with its id: article-1, article-2.. and so on, I don't know how to fetch all the articles only by SK.
I then tried creating a LSI , but then I noticed that the LSI needs to have the PK the same as the table, so I can select based on LSI type = 'ARTICLE', but I still cannot selected them ordered by date (entities_sort value)
I know AWS says its good for PK to be unique, but then how do you group the data in this case?
I've created a GSI
This helps me get articles by type(GSI2PK)='ARTICLE' sorted by entities_sort (GSI2SK), but isn't there a better way of achieving this? Having your articles as a PK in a table, but somehow still being able to get them sorted by date?
Having GSI1PK, GSI1SK this way - I can get all the comments for an article using reverse lookup, so thats good.
But I still also don't know how to implement number 3. Get the prev/next article relative to the article opened (based on creation date): getting an article by id, check its creation date(entities_sort), then somehow get the next article before and after based on that creation date (entities_sort), is there a function in DynamoDB that can do this for me?
In my approach I try to query/process as few items as possible so I don't want to use filter functions, rather partition my information.
My question is, how should I achieve 1 and 3? And isn't creating 2 GSI's for such few actions overkill?
What is the pattern to have articles on a PK, unique with ids, but still being able to get them sorted by creation date?
Thank you
So what I've ended up doing is:
My access patterns in detail are:
Get any Article by Id (for edit/delete)
Get any Comment by Id (for edit/delete)
Get any Tag by Id (for edit/delete)
Get all Articles ordered by date
Get all the Tags of an Article
Get all comments for an article, sorted by date
Get all Articles that have a specific tag, ordered by date (because I want to show only the last 3 ones)
This is the way I've implemented my model, and I can get all the informations needed.
Also, all my data is partitioned and the queries are really efficient, I always get exactly what I need and the ScannedDocuments value is always the number or returned objects.
The Global Secondary Index helps me query by Article Id and I get, all the comments and tags of that Article.
I've solved the many-to-many between Tags and Articles by a new record in the end:
tag_id, article_date, arct_id, tag_id
So, if I want all articles that have a specific tag sorted by date I can query the PK of the table and sort by SK. If I want to get a single Tag (for edit/delete) I can use the GSI by: article_id, tag_id .. and I get the relation between them.
For getting all Articles sorted by date, i query PK: ARTICLE and an option condition if I want to get only the ones after a date or not I can condition the SK.
For all the comments and tags of an Article I can use the GSI with : article_link_pk: article_id and I get all comments and tags. If I want only comments I can say article_link_pk: article_id and article_link_sk: begins_with(article_link_sk, '2020') in this way I get only comments, without tags.
The data model in NoSQL Developer looks like this:
The GSI reverse lookup looks like this:
It's been a journey, but I feel like I finally got a grasp on how to do data modelling in DynamoDB

Django - Where IN with multiple columns/fields

I have a query that needs to fetch from a table that meets two columns requirements exactly. So if I have users table with columns, age and score.
SELECT * FROM users where (age, score) IN ((5,6), (9,12), (22,44)..);
In my web app, I am getting these pairs from an ajax request, and the number could be quite big. How do I construct a query for this in Django?
I am working on Postgres database
One solution I come up with, would be to use django.db.models.Q object and construct exactly same query as you've written:
ques = Q(age=5) & Q(score=6) | Q(age=9) & Q(score=12) ...
User.objects.filter(ques)
This would return the desired queryset, but, I'd be concerned about the size of the iteration performance of the received values (using ajax).
On the other hand, I don't recall better solution for now. If something comes up, would update the answer. Hope, this helps.

PowerApps: Filter by user no delegation

Need some help with PowerApps - I am trying to filter the gallery where the Person column (ROMEmail) equals the logged in user.
This code is working, but the blue circle of death comes up - whilst in test at the moment, i dont have over 500 records, but will do within a month of trialling this
Any ideas on how to workaround this? Using a collection or variable perhaps? I haven't really used these yet so a detailed resolution would be greatly appreciated.
SortByColumns(Filter('Reviews', StartsWith(LocationName, TextSearchBox1.Text),ROMEmail.Email = User().Email), "Modified", If(SortDescending1, Descending, Ascending))
A collection would be your best choice.
To add a collection in your app replace the code where you grab your data by something like this:
ClearCollect(localData,'Reviews')
This collects all the data in a locally collection. The ClearCollect replaces all your data by the new ones.
After this you can sort and filter directly on your collection. For example in a gallery. Using your code it would look like this:
SortByColumns(Filter(localData, StartsWith(LocationName, TextSearchBox1.Text),ROMEmail.Email = User().Email), "Modified", If(SortDescending1, Descending, Ascending))

DynamoDBMapper queryPage working with non sort key as filter parameter

From the dynamoDBMapper docs
Querypage:
Queries a table or secondary index and returns a single page of
matching results. As with the query method, you must specify a
partition key value and a query filter that is applied on the sort key
attribute. However, queryPage will only return the first "page" of
data - that is, the amount of data that will fit within 1 MB.
I've applied query filter on a attribute which is not a sort key. But everything works. How is this possible?
I think that particular statement is misleading in the documentation. You can apply query-filter/filter-expression on any non-key attributes, but you cannot apply filter expression on key attributes :
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#FilteringResults
You can send your feedback ("Feedback" button at the bottom of the doc page) to Amazon. I think they're pretty responsive for the feedbacks they receive.