Giter VIP home page Giter VIP logo

Comments (29)

khaf avatar khaf commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

Just released the latest changes. The following will now work:

err := lmap.Put(anyKey, anyValue)

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

Additionally, i cannot run json.Marshall on the values i get back from the value store

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

Can you provide a small snippet of code so that I can better understand the problem?

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

json: unsupported type: map[interface {}]interface {}

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

cannot use friendsMap (type map[string]interface {}) as type map[interface {}]interface {} in argument to lmap.PutMap

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

I'm writing to largeMap not normal key value and im using PutMap

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

Don't use PutMap(), use Put() if you need to put an arbitrary map.

lmap.Put(key, friendsMap)

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

the problem is it isnt accepting a map[string][interface{}] in PutMap()

from aerospike-client-go.

khaf avatar khaf commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

Value type '' not supported
Tried you suggestion and got that

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

removed

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

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.

supafoundation avatar supafoundation commented on June 13, 2024

ok thanks for the explanation khaf...going to close this now as an aerospike Golang implementation limitation

from aerospike-client-go.

supafoundation avatar supafoundation commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

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.

ktmighty14 avatar ktmighty14 commented on June 13, 2024

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.

khaf avatar khaf commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.