Cassandra - data modelling help needed - cassandra

I try to design social network ( kind of ) application.
I have a User, he has Follower(s), and there is a Timeline.
My timeline table look like:
user_id
second_party_user_id
created
other_fields
So, when 'second_party_user' posts any new content, I get all people who follow him, and insert into their Timeline second_party_user's post.
When user comes to see timeline, I do a simple request to his timeline by user_id.
The problem is that I need to get ordered items. And if I want to get ordered by created, I need to put it as a second clustering column, not a third one.
At the same time, if I put it as a second clustering column, ie:
user_id
created
second_party_user_id
other_fields
then I would have a problem when one user unfollows second_party_user, ie how can I delete by (user_id, second_party_user_id).
Any help will be highly appreciated!
Thank you in advance.

To handle those features you can use two tables, one for get the timeline ordered and another one to handle the elimination in both tables.
//order timeline by created date
user_id(pk)
created(ck)
second_party_user_id
other_fields
//with this table you can get created to delete in the first one and
//delete this table with (user_id,second_party_user_id)
user_id(ck)
second_party_user_id (ck)
created
other_fields

Related

Get NetSuite transaction data based on item filter for journals with null ITEM_ID?

How do I get transaction data based on an item filter for journals with null ITEM_ID? I'm a database guy not a finance guy and my finance people can pull a report from NetSuite that shows each transaction with posting period, filtered by item. I'm unable to do the same because the Transaction_Lines table has null ITEM_ID's for the entries I'm looking for, presumably because they are journal entries. This particular ITEM_ID is not in the Transaction_Lines table at all so I'm assuming that's because it's always handled by journal entries. Any help would be appreciated.
It appears that you're referring to the NetSuite.com Data Source querying via ODBC. If this is correct, I believe that you're looking for the "Posting_account_activity_pe" table, which should contain all journal transactions, whether or not they have an Item_ID associated with them:
More details can be found on the Connect Browser:
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2020_1/odbc/record/posting_account_activity_pe.html
The answer ended up being to point to the Revenue_Plans, Revenue_Plan_Lines, and Revenue_Elements table but I had to be careful to join to the posting period rather than the planned period. Then I could do two select queries, one for journals and one for all other income types.

Is it possible to compare 2 different sheets on Excel, update data then insert into a new table all the changes that were made?

Right now, I have a running list of all my data for the all my products. The list will show an ID that identifies the product and then show the status of that product and the date of that status. Every week I get more data on the same product_ID but I am wondering if there is a way to use VBA to update another table to show only one product ID and the most recent status for that? If possible I would then want to insert information into a third table (sheet) that keeps track of the changes made
I am new to using this program and would like to see if this is viable before trying to mess around with it. I hope I explained everything correctly.
Thanks!

Filtering From 2 different tables in DAX

I am having a little trouble figuring out how to properly filter from the one side through a many relationship and back through to another one sided table.
The issue is that a Customer can have multiple accounts which can have multiple Customers.
In the attached image I am trying to filter from a Center# through the All Customer level and then add a filter on the List table to get the correct open accounts.
So the example would be I am looking for all Customers that are associated with Center A and are attached to an account type A.
The inactive one to many relationship from All Cust -> All Accts is what needs to be active instead of the All Cust -> Open table.
I am currently using:
CALCULATE([Cust Enrolls],CROSSFILTER('All Cust'[All Customer Number],'Open'[Primary Customer Number],Both))
to be able to filter for the account type, but that table's customer is just the single primary customer.
Any ideas on how I should either rework the model or how to create the correct measure?
Model
I would recommend re-working your Data Model so that you have a clear 1-M for each dimension table to your fact tables. This will save you a tremendous amount of time and headaches now and in the future by structuring your data properly.

How to perform NOT CONTAINS in CASSANDRA?

I am working on creating cassandra tables to support various queries my application makes. So far it's great, except I'm having a problem with one particular case:
We have a tinder-like interface where a user can vote "up" or "down" on a photo. I would like to dynamically serve the top 5 photos per query, sorted according to a custom "score", which excludes photos that a user has already voted on.
The pool of photos and the votes per photo are potentially > 10,000 each.
I was thinking of creating a table with a column of "votes: set" containing user ids, but it doesn't help because you can't query by NOT CONTAINS.
Is there a way to perform this query efficiently in Cassandra?

Cassandra - join two tables and save result to new table

I am working on a self-bi application where users can upload their own datasets which are stored in Cassandra tables that are created dynamically. The data is extracted from files that the user can upload. So, each dataset is written into its own Cassandra table modeled based on column headers in the uploaded file while indexing the dimensions.
Once the data is uploaded, the users are allowed to build reports, analyze, etc., from within the application. I need a way to allow users to merge/join data from two or more datasets/tables based on matching keys and write the result into a new Cassandra table. Once a dataset/table is created, it will stay immutable and data is only read from it.
user table 1
username
email
employee id
user table 2
employee id
manager
I need to merge data in user table 1 and user table 2 on matching employee id and write to new table that is created dynamically.
new table
username
email
employee id
manager
What would be the best way to do this?
The only option that you have is to do the join in your application code. There are just few details to suggest a proper solution.
Please add details about table keys, usage patterns... in general, in cassandra you model from usage point of view, i.e. starting with queries that you'll execute on data.
In order to merge 2 tables on this pattern, you have to do it into application, creating the third table (target table ) and fill it with data from both tables. You have to make sure that you read the data in pages to not OOM, it really depends on size of the data.
Another alternative is to build the joins into Spark, but maybe is too over-engineering in your case.
You can have merge table with primary key of user so that merged data goes in one row and that should be unique since it is one time action.
Than when user clicks you can go through one table in batches with fetch size (for java you can check query options but that is a way to have a fixed window which will be loaded and when reached move to next fetch size of elements). Lets say you have fetch size of 1000 items, iterate over them from one table and find matches in second table, and after 1000 is reached place batch of 1000 inserts to new table.
If that is time consuming you can as suggested use some other tool like Apache Spark or Spring Batch and do that in background informing user that it will take place.

Resources