Standard process of saving Key-Value Pairs to database - database

What is the standard process of saving Key-Value Pairs to database?
Will I include key-value pairs with empty values upon saving? If no, when updating a value, will I delete it on the database once I update it to an empty value?
I tried to save Key-Value pairs and I don't know if I'm doing the right thing by saving the ones that don't have empty values. And when I update existing Key-Value pairs from the database, I delete the ones that are empty since I don't save empty values.

Related

Django - check existence of multiple objects individually

There are objects of type A and B, some have relations to each other defined in the Model ABRelation. We wish to check the existence of many relations individually and create them if non-existent, delete the ones that should not exists anymore.
Thus there are two lists of ids, a_ids and b_ids, that need to match according to position. It could also be a list of tuples (id_a, id_b), whatever is state-of-the-art in django. Any pair of ids in that set must be created if non-existent. Furthermore existing relations on the database that are not contained in the given set must be deleted.
How to do this most efficiently by processing bulks and not individual objects?
We tried to check the existence using filter and queries but it will aggregate the results and return a single boolean that reflects if all objects exist or not.
result = ABRelation.objects.filter(
Q(a_id__in=a_ids) &
Q(b_id__in=b_ids)).exists()
How can this be done? Is there a straight forward way of doing it?

How to write customized metadata to index in Lucene?

I need to write some metadata to index in Lucene. These metadata describes the relationship between indexes, which helps me to do cross-index query.
The data structure of metadata is key-value pair. The key may be Integer or String. And the value is a list of Integer or String.
In the begining, I tried to extend the Codec. Obvously this key-value pair is not belongs to existing Formats. Then I turned into write this by adding a field. But it is not belongs to the index either and field is hard to change.
How to extends this metadata? Thank you.

What is the query to update a value in a list of maps in Apache Cassandra?

I have created a table in Cassandra with a column datatype list<Frozen map<text, text>>.
I'm trying to write a query to update a value in this list of maps by filtering the list by a key:value pair but couldn't find it. The only option I have is to extract the whole list using flask python API and filter and update the map key:value and update the whole list back into the table.
Is there any update query statement to update the exact map key:value in the list of maps in Cassandra??
Frozen collections are processed as one distinct value regardless of the number of items in the collection. This means that you cannot update the individual items in your map -- you can only overwrite the whole map collection.
For more info, see CQL frozen collections. Cheers!

What is the proper data structure for storing values with multiple keys?

I am new to nosql or document db. Please correct me if there is anything not clear. I am thinking about this question: What is the proper data structure for storing values with multiple keys?
An example can be probably a document with multiple tags, or a product with multiple alias. What could be an efficient way to store these pairs? If we use key-value store, is there a way to not duplicate value for each key?
For example, if we have a document with tags: "java", "algorithm", "data structure", are we going to keep one copy of the document for each tag?
It depends on the requests you need to make.
When using a KV store, you certainly will duplicate the tags: include them in the documents, to be able to display and document and the related tags; and create a list of document IDs for each tags, to allow you to get the list of documents for a given tag.
You have to ensure the consistency of data in your app: when you add a tag to a document, you add the document ID in the corresponding tag list.

What is the difference between data entries and data records?

I was looking through my lecture notes, and came across this slide. I am confused what a data entry vs a data record. I know the data record is the entire tuple, but I am unsure about the data entry.
Data records is a complete row of your database stored somewhere in the filesystem.
Data entries only stores the columns that you specified in the index. Data entries usually keep a pointer to the data record in the filesystem where the record resides
The data entry in this case is the record contained in the index: typically, it is a pair (value of the key, reference to the tuple), where the reference to a tuple can be either a TID, Tuple Identifier, or some other way of referring to a tuple.

Resources