5

I have converted JSON file to CSV format and now loading the CSV in Aerospike using aerospike loader. I can do this for simple structure but how to modify the contents of allDatatype.json to load the nested CSV file in Aerospike?

https://github.com/aerospike/aerospike-loader/tree/master/example

JSON FILE

{
"centers" : {
"ER" : {
"admin":{
"users" : {
  "emp1" : {
    "password" : "abcdefgh",
    "username" : "pankaj-roy"
  },
  "emp2" : {
    "password" : "12345678",
    "username" : "niketan-shah"
  }
}
}
}
}
}

CSV FILE

centers.ER.admin.users.emp2.username,centers.ER.admin.users.emp2.password, centers.ER.admin.users.emp1.username,centers.ER.admin.users.emp1.password
niketan-shah,12345678,pankaj-roy,abcdefgh
hmims
  • 539
  • 8
  • 28
  • 3
    If you want to preserve the structure of Json, why convert to nested CSV, and then load into Aerospike. Can you not serialize the whole JSON as bytes (using protobuf or something) and store it as a blob in Aerospike ? Aerospike's CSV loader, cannot handle nested CSV. It assumes that the CSV is tabular in nature. – sunil Sep 29 '15 at 09:26
  • 1
    if we store it as a blob in bin in aerospike..will i be able to query on the single bin containing the blob? – hmims Sep 29 '15 at 13:01
  • 2
    You will get the whole content back. You can select a single bin even if your record has multiple bins. You cannot query for sub components of a bin. Note that Aerospike is not a document store. – sunil Sep 30 '15 at 05:51
  • 1
    If i store it as a blob..then how will i be able to query on it? – hmims Sep 30 '15 at 08:36
  • Sunil..can u plz share your email id..so that i can contact u – hmims Sep 30 '15 at 08:37
  • 2
    You can use the regular get() call to get the bytes back, deserialize into your object and access the sub-fields in that object. BTW, If the object you have in Java is serializable, you need not have your own serializer. Aerospike's put/get API will use the java serialization/deserialization to get back your java object. – sunil Sep 30 '15 at 17:46

1 Answers1

3

My understanding which I must admit is limited as I have only just started looking into Aerospike is to forget that you want to store the whole object in one (which as suggested above in the comments, as this is more like a document store). Instead you need to think of it in the world of Key-Value terms. My understanding is that your json payload above should be stored in Aerospike like so

Bin=users
Set=creds
Key=(username, "pankaj-roy")
bin=(password, "abcdefgh")
bin=(role, "admin")`

then you can do something like this:

user_key = new Key("users", "creds", username);
user_records = client.get(null, user_key);
console.printf("username:   " + user_records.getValue("username") + "\n");
console.printf("password:   " + user_records.getValue("password") + "\n");
mmkd
  • 880
  • 1
  • 14
  • 26