How to load a nested csv file in aerospike using a

2019-05-06 22:53发布

问题:

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

回答1:

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");