map<text, object> Cassandra, is it possible - dictionary

I want to create a table with a map accepting string as key and any object as value (boolean, string, int, timestamp).
Is it possible ?
Thanks

Currently, no, keys and values in a map must be of a known CQL type. There is a request for "dynamic types", but nobody has worked on it so far.

Any object isn't possible. You can create user defined types but this type isn't dynamic: https://docs.datastax.com/en/cql/3.1/cql/cql_reference/cqlRefcreateType.html
You can parse your object as json and this json as string. You can insert this string in a text column.

There is no native support for dynamic types.
So you got two work arounds.
Handle it in your application logic.
Create map<text, blob> or map<text, text>
Create JSON or ByteBuffer in your application logic. JSON is better as it is language independent, but can consume more storage.
Create UDT with all the possible types and store it accordingly.
If you have very little variety, then you should choose 2nd option, else 1 should be better. Using 1st option you can store complex objects also.
Hope it helps!

Related

How to find out a type of attribute of DynamoDb table?

everyone!
I have the following situation: client sends attributes, which he wants to retrieve from table, for example "Id, Name, Price", and I should send them , having been mapped them before. The problem is, how to find out what are the types of given attribute? I want to know where the data of Price attribute is stored: val["Price"].N or val["Price"].S or somewhere else? Is there any way to find it out?
Thank you for any advice!!!
I am not familiar with the .net SDK specifically, but if you are looking for what data type each attribute is stored in DynamoDB, you could do the calls with the low level client in the SDK, as opposed to the DocumentClient. The low level client returns DynamoDB's native JSON format and will tell for each attribute if it is a string, number, map, etc.

Serialize and Deserialize JSON with different property names for different use cases

I have data stored in a database with short field names to save space. When I load these into my .NET Core app, I convert the data to its C# model. Then, when I pass this to the fronted I want to serialize the JSON to have full field names. So instead of "fN", "firstName".
I know I can use [JsonProperty(PropertyName = "SomeName")] to change serialization/deserialization. What I'm asking is whether there's a way to specify multiple property names for a single field, ideally with some additional "profile" variable so that when I serialize/deserialize from the DB I use the DB profile, and when sending to the client I use the other profile. This way I can either use the short or long names when convenient.
Thanks!

DynamoDBMapper batchLoad pass in parameters

There are two ways for DDBMapper to call batchLoad, differing in different pass-in parameters.
public Map<String,List<Object>> batchLoad(Iterable<? extends Object> itemsToGet)
public Map<String,List<Object>> batchLoad(Map<Class<?>,List<KeyPair>> itemsToGet)
I understand the second way, which makes more sense to me by specifying keyPair.
Then what about the first one? So basically just to pass in a list? Then whats the difference? The second one obviously looks more complicated
Imagine I have a User object with partition key userId and range key createdDate. I want to batch load 3 Users.
In the second option I have to create 3 key-pairs of userId and createdDate. In the first option I instantiate 3 User objects using userId and createdDate and put them in a List.
The first option might be more appropriate if I have logic in the User constructor. For example maybe createdDate cannot be more than 1 year ago. In this case creating User objects is an advantage as the constructor logic is executed. Alternatively I may have been passed the User object from some other part of the application, in which case creating key-pairs from them is just extra code I shouldn't need to write.
So basically there isn't much difference. I suspect some people will find the first option more pleasing since DynamoDBMapper is an object persistence solution, so it should support passing objects (not undefined key-pairs) around.

ASP.NET: Best way to determine type of object serialized to XML

I have a table in my SQL Server DB that holds auditing information for certain actions a user takes within my system. Things like who performed the action, when it was performed, and what action are all pieces of information that can easily span multiple actions. But depending on the action performed, there may be other information that I want to capture, that is specific to the action. To handle this, I elected to add an "XML Metadata" column to the table that holds serialized XML of different metadata objects that I've created. I created a metadata object for each of the actions that I'm interested in tracking extra for. So each object is responsible for tracking specific extra information (metadata) for it's action. The objects are serialized and written to my new column.
I have SystemAction objects that I use to store information from this table, and I've added a string field that holds the XML string from the DB. The problem is, when I'm reading this XML back from the SystemAction objects, I'm struggling with a way to generically translate it back into it's correct metadata object. Each metadata object is going to have different fields, and each object has it's own static method that takes an XML string and attempts to return the metadata object type. So I could say:
SomeActionMetadata mdObj = SomeActionMetadata.BuildFromXML(xmlStringFromDB);
But I really don't know of a way to say "Here's some XML that could translate to any number of different objects. Figure it out and give me the right object back."
Given my current implementation, I could always just assign a unique ID to each metadata object that is stored as a field in each object, then use a case statement to switch on that ID and use the appropriate class's static build method to build the right object. But I was hoping for something a little more automatic than that. What if I have a List of SystemAction objects and just want to loop through them and generate the correct metadata object type?
I was hoping someone might have run across something similar to this before, or could point me to an article or post that could help me out. Thanks very much.
As indicated by Subhash Dike in the comments below, there is a similar SO question here that was able to point me in the right direction.

Entity Framework - Mapping doesn't map for stored procedure?

I have a stored procedure that search a view using full text.
I'm trying to map the results to an existing Entity (Sales), where I mapped the column MivType to SaleType (as it makes more sense, and I want to keep db names away from my web site). The stored procedure is mapped to a Function Import, and I've defined its ReturnType to Sales.
This work well as long as the entity has the same property names as fields names.
Here's my problem: when I change the property's name, I get the following error after running the imported function:
The data reader is incompatible with the specified 'Model.Sale'. A member of the type, 'SaleType', does not have a corresponding column in the data reader with the same name.
I can fix this if I change the property 'SaleType' to 'MivType' on the entity, but why should I do that? Isn't that what the mapping is for?
This means I have to use the exact same names on the stored procedure and the entity, so in effect, the mapping is ignored (I have names like YzrName, MivYaad, etc, and I don't like it).
Is there a simple way around this? I don't want to use the db names on my application, and prefer not to change the stored procedure...
(I should mention I'm a beginner with the EF, so this can be a rookie mistake)
Thanks.
Well the entity designer doesnt work very well. I generally try to do everything in the XML. In the XML there are 3 parts. The Storage (a representation of the SQL Database). The Conceptual (a represention of your .Net Objects. and the Conceptual to Storage Mapping
It sounds like the error is in your Conceptual to Storage Mapping. You can keep the property name SalesType on the conceptual side but the mapping must map the the correct names on both the conceptual and storage side.
Refer to MSDN here are some articles
http://msdn.microsoft.com/en-us/library/cc716731.aspx

Resources