Comments (29)
You should not try to assert a string
into Value
. Just create a new value to pass into the function:
lmap.Put(NewValue(key), something)
I'll make it an interface on next release so that you won't have to do even this.
from aerospike-client-go.
Just released the latest changes. The following will now work:
err := lmap.Put(anyKey, anyValue)
from aerospike-client-go.
Thank you...additionally, im trying to insert a Key, value where value is a JSON into lmap.PutMap . It seems to only want to accept map[interface{}]interface{}] and hence wont accept json as a value.
from aerospike-client-go.
PutMap()
is a convenience method for when you have a map[interface{}]interface{}
.
If you have a map of different type, you can easily use Put()
, and pass the map as the value
:
err := lmap.Put(anyKey, yourMapOfArbitraryTypes)
The map will be converted for you automatically.
from aerospike-client-go.
Hi, i'd like to use PutMap if possible as it will enable me to do a one time batch write instead of having to loop through the operation whenever possible.
Please advise and thank you for the quick reply
from aerospike-client-go.
Additionally, i cannot run json.Marshall on the values i get back from the value store
from aerospike-client-go.
Can you provide a small snippet of code so that I can better understand the problem?
from aerospike-client-go.
by storing this as map[interface {}]interface {}, my scan result is map[keyValue1:[2 Name1] keyValue2=:[2 Name2] keyValue3:[2 Name3] keyValue4:[2 Name4 ] keyValue5:[2 Name5]]
Im trying to display this as a JSON file. Im having using Json.Marshall as it is of map[interface {}]interface {} type....I will try a struct and get back to you shortly....in the mean time if you can offer a solution it would be awesome. Thanks
from aerospike-client-go.
json: unsupported type: map[interface {}]interface {}
from aerospike-client-go.
json.Marshal()
returns a byte array ([]byte
), which you can directly Put()
in a normal bin
, then retrieve it and Unmarshal()
it anytime needed into a struct
.
In your use case, you don't need LargeMap.
b, err := json.Marshal(yourStruct) //handle error
// save the marshalled data in a bin called json
err = client.PutBins(wpolicy, yourKey, NewBin("json", b))
// read the `json` bin back from the db
rec, err = client.Get(policy, yourKey)
// unmarshal into the struct
b = rec.Bins["json"].([]byte)
err = json.Unmarshal(b, &yourStruct)
from aerospike-client-go.
cannot use friendsMap (type map[string]interface {}) as type map[interface {}]interface {} in argument to lmap.PutMap
from aerospike-client-go.
I'm writing to largeMap not normal key value and im using PutMap
from aerospike-client-go.
Don't use PutMap()
, use Put()
if you need to put an arbitrary map.
lmap.Put(key, friendsMap)
from aerospike-client-go.
Thanks khaf, i want to store the values in a large map. And I want to do it in a batch.
from aerospike-client-go.
the problem is it isnt accepting a map[string][interface{}] in PutMap()
from aerospike-client-go.
You are not listening. If you pass it to the lmap.Put()
, it will convert it for you automatically to a proper internal value, and save it in a batch. Please try it and see.
from aerospike-client-go.
but that will make it store under the same key no? i want the format map[key1:[2 Name1] key2=:[2 Name2] key3:[2 Name3] key4:[2 Name4 ] key5:[2 Name5]]
not map[key1:[2 Name1][2 Name3][2 Name4 ]] etc for example
from aerospike-client-go.
Value type '' not supported
Tried you suggestion and got that
from aerospike-client-go.
In order to implement what i want i will have to do a for loop for lamp.Put() but thats not what i want
from aerospike-client-go.
Ah, I see. Sorry for the confusion.
Then you have to convert your map into a map[interface{}]interface{} and then pass it to the map.
Make a utility function like this:
func convMap(theMap map[string]interface{}) map[interface{}]interface{} {
res := make(map[interface{}]interface{}, len(theMap))
for k, v := range theMap {
res[k] = v
}
return res
}
Then use it in your code:
lmap.PutMap(convMap(friendsMap))
from aerospike-client-go.
removed
from aerospike-client-go.
I have no problem converting it to a map[interface{}]interface{}. The problem I have is converting the map[interface{}]interface{} to a JSON format
from aerospike-client-go.
But it looks like there is no compromise and I will have to use a for loop to convert it to a JSON format...in other words i cant store it as a map[string]interface{} right?
Sorry if i didnt make myself clearer....that was my main intention coz if i can store it that way, i can obtain it that way and display it ....no need to use for loops
from aerospike-client-go.
The types are preserved on multiple stages of conversion, but the API needs to stay generic to support all use cases. As a result, while data types are preserved in transport and storage, you still have to deal with them in the end.
Unfortunately lacking generics, Go doesn't yield to a better solution that I can see.
from aerospike-client-go.
ok thanks for the explanation khaf...going to close this now as an aerospike Golang implementation limitation
from aerospike-client-go.
Perhaps the scan result should return a map[string/int]interface{} instead of map[interface{}]interface{} as it is a key value store anyway.
from aerospike-client-go.
Keys can be of any type, and as a result the library should support the generic use case.
I'll try to find a way to support your use case properly. No promises though :)
from aerospike-client-go.
I'm kinda having the same problem, i cant write a collection of geojson data.
are there any ways??!??
package main
import(
"encoding/json"
"fmt"
"github.com/aerospike/aerospike-client-go/go.geojson"
"github.com/onsi/ginkgo"
"log"
"github.com/onsi/gomega"
_ "strings"
as "github.com/aerospike/aerospike-client-go"
shared "github.com/aerospike/aerospike-client-go/examples/shared"
)
type itemdata [][]geojson.FeatureCollection
func main() {
runRecord_Entry(shared.Client)
log.Println("\t \t Application ran successfully GrandMaster")
}
func runRecord_Entry(client *as.Client) {
// define a client to connect to
client, err := as.NewClient("127.0.0.1",3000)
PanicOnError(err)
ginkgo.It("To load the data", func() {
// The Data
var points itemdata
json.Unmarshal([]byte{
`{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry" : {
"type" : "Point",
"coordinates": [13.009318762,80.003157854]
},
"properties" : {
"name" :"Work shop",
"demand":"49589",
"capacity":"4231"
}
},
{
"type": "Feature",
"geometry" : {
"type" : "Point",
"coordinates": [13.00961276, 80.003422154]
},
"properties" : {
"name" :"main block",
"demand":"247859",
"capacity":"2974"
}
},
{
"type": "Feature",
"geometry" : {
"type" : "Point",
"coordinates": [13.009318762,80.003157854]
},
"properties" : {
"name" :"Work shop",
"demand":"49589",
"capacity":"4231"
}
},
{
"type": "Feature",
"geometry" : {
"type" : "Point",
"coordinates": [13.00961276, 80.003422154]
},
"properties" : {
"name" :"main block",
"demand":"247859",
"capacity":"2974"
}
}
]
}`}, &points)
// define some bins
count := 0
for i, ptsb := range points {
key, _ := as.NewKey("test", "testset", i)
bin := as.NewBin("vada", as.NewGeoJSONValue(ptsb))
err := client.PutBins(shared.WritePolicy, key, bin)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
shared.PanicOnError(err)
gomega.Expect(count).To(gomega.Equal(4))
}
// queries only work on indices
client.DropIndex(shared.WritePolicy, "test", "testset", "my_geo_inex_hu")
client.CreateIndex(shared.WritePolicy, "test", "testset","ma_geo_index","gjsn","as.GEO2DSPHERE")
})
fmt.Println("\t \t \t \t The records are wriiten !!")
}
func runOptimal_Location(client *as.Client){}
func PanicOnError(err error){
if err != nil{
panic(err)
}
}
from aerospike-client-go.
Your question is unrelated to this issue. Please file a new issue so that I can answer it there.
from aerospike-client-go.
Related Issues (20)
- panic: unaligned 64-bit atomic operation in Cluster.tend (on 32bit) HOT 4
- Is there a way to get items in list for a PK? HOT 2
- BatchGet with secondary index HOT 3
- command execution timed out in go-client when Docker container is restarted HOT 2
- Is there any way to mock client for UT? HOT 3
- Why is ClientPolicy.Timeout used to create new connections during reads instead of basePolicy.connectTimeout HOT 11
- Type consts are hidden in `internal/particle_type` HOT 7
- How to get show distribution time_to_live HOT 1
- invalid go.mod on master HOT 2
- Could you clarify timeouts for the Query? HOT 10
- [6.14.0] Proto registration conflict caused by `kv.proto` HOT 13
- Support more integer sizes in the Expressions API. HOT 1
- Getting record keys when using QueryObjects
- Is it possible to index and filter keys in map?
- 6.4 upgrade from 5.7 HOT 3
- Massive amount of memory occupied by `newPartitionStatus` and `newNodePartitions` HOT 5
- How to use aerospike.GetObject with a [][]byte value HOT 2
- Not retry when receive error: Partition not available (code 11) HOT 2
- Export BatchWrite, Expressions and Operation fields HOT 2
- Scan Partition/Pagination HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aerospike-client-go.