Bug while using go client

query
go
geo
index
#1
package main

import (

	"encoding/json"
	"fmt"
	"github.com/onsi/ginkgo"
	"github.com/aerospike/aerospike-client-go/go.geojson"
	//"github.com/go.geojson"

	"log"
	//"github.com/onsi/gomega"
	_ "strings"

	as "github.com/aerospike/aerospike-client-go"
	shared "github.com/aerospike/aerospike-client-go/examples/shared"
)

type FeatureCollection struct {
	Type        string                 `json:"type"`
	BoundingBox []float64              `json:"bbox,omitempty"`
	Features    []geojson.Feature             `json:"features"`
	CRS         map[string]interface{} `json:"crs,omitempty"` // Coordinate Reference System Objects are not currently supported
}
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 = []byte(
			`{
			"type": "FeatureCollection",
			"features": [
{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "workshop block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.0031977891922,
          13.009204355763806
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Admin Block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00428140163422,
          13.009601587261502
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Library Block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00554740428925,
          13.008833257342415
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Indoor Auditorium"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00563859939575,
          13.008341943085197
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Ladies Hostel"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.0055742263794,
          13.007286136813835
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Boys hostel"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00336945056915,
          13.007312270686677
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Aero Block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00275254249573,
          13.007824494038537
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Academic Block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00228986144066,
          13.007977376823781
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Architecture Block"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00160992145538,
          13.008315809320848
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "PG canteen"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00238507986069,
          13.008471305178167
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "REC Ground"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.004603266716,
          13.008477838615416
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Lab workshop 1"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00295639038086,
          13.007918575763695
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Lab Workshop 2"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.003165602684,
          13.007944709569898
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Tech Lounge"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00505924224852,
          13.009591133809183
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Automobile workshop"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00178158283234,
          13.007918575763695
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Gents Hostel"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00434041023254,
          13.007270456488804
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Vehicle parking"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.0009474158287,
          13.012447523262285
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Airplane Stand"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00307440757751,
          13.009559773449608
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Transport Office"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00551521778107,
          13.009298436965507
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name": "Hut Cafe"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00363498926163,
          13.007965616612875
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00384420156479,
          13.007265229713582
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "name":"Aeronautical Workshop"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          80.00099837779999,
          13.007994363794108
        ]
      }
    }
  ]
}s`)

	var ptsb interface{}
	err :=json.Unmarshal(points, &ptsb)
	PanicOnError(err)

	m :=ptsb.(map[string]interface{})

	// define some bins
	//count:=0
	for kevlar, vandetta := range m {

		key1, err := as.NewKey("test", "valkyrie", kevlar)
		bin1 := as.NewBin("barek", as.NewGeoJSONValue(vandetta.(string)))

		err = client.PutBins(shared.WritePolicy, key1, bin1)
		shared.PanicOnError(err)
			//stm := as.NewStatement("test","testset")
			//recordset, err := client.Query(nil, stm)
		//gomega.Expect(err).ToNot(gomega.HaveOccurred())
		shared.PanicOnError(err)

		record, err :=client.Get(nil,key1)
		fmt.Println(record)
		shared.PanicOnError(err)
			//count :=0
			//for res := range recordset.Results(){
			//	gomega.Expect(res.Err).ToNot(gomega.HaveOccurred())
			//	client.PutBins(shared.WritePolicy, key, bin)
			//count++
			//}
			//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)
	}
}

The above code gives the following output

     go run kaiyaash.go
2019/04/01 00:17:16 hosts:		127.0.0.1
2019/04/01 00:17:16 port:		3000
2019/04/01 00:17:16 namespace:		test
2019/04/01 00:17:16 set:		testset
	 	 	 	 The records are wriiten !!
2019/04/01 00:17:16 	 	 Application ran successfully GrandMaster

The testset i mentioned in the code was never created and this data was neither entered in any set, I dint pop an error message to. The data gets written while using individual geojson data for which i dont create this interface !

Thanks in advance

#2

As I responded to your other question, you need to do it this way:

package main

import (
	"log"

	as "github.com/aerospike/aerospike-client-go"
)

func main() {
	// define a client to connect to
	client, err := as.NewClient("vmu1804", 3000)
	PanicOnError(err)

	// The Data
	bins := []as.BinMap{
		{
			"name":     "Work shop",
			"demand":   "49589",
			"capacity": "4231",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.009318762,80.003157854]}`),
		},
		{
			"name":     "main block",
			"demand":   "247859",
			"capacity": "2974",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.00961276, 80.003422154]}`),
		},
		{
			"name":     "Work shop",
			"demand":   "49589",
			"capacity": "4231",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.009318762,80.003157854]}`),
		},
		{
			"name":     "main block",
			"demand":   "247859",
			"capacity": "2974",
			"coord":    as.GeoJSONValue(`{"type" : "Point", "coordinates": [13.00961276, 80.003422154]}`),
		},
	}

	// write the records to the database
	for i, b := range bins {
		// define some bins
		key, _ := as.NewKey("test", "testset", i)
		err = client.Put(nil, key, b)
		PanicOnError(err)
	}

	log.Println("The records are written !!")

	// queries only work on indices; you should create the index only once
	// The index is created on the namespace, set and bin that should be indexed.
	client.CreateIndex(nil, "test", "testset", "ma_geo_index", "coord", as.GEO2DSPHERE)

	stm := as.NewStatement("test", "testset")
	// there are multiple different types of filters. You can find the list in the docs.
	stm.SetFilter(as.NewGeoWithinRadiusFilter("coord", float64(13.009318762), float64(80.003157854), float64(50000)))
	recordset, err := client.Query(nil, stm)
	PanicOnError(err)

	count := 0
	for res := range recordset.Results() {
		PanicOnError(res.Err)
		log.Println(res.Record.Bins)
		count++
	}

	// 1 region should be found
	log.Println("Records found: ", count)

	log.Println("Application ran successfully GrandMaster")
}

func PanicOnError(err error) {
	if err != nil {
		log.Fatalln(err)
	}
}
1 Like
#3

Thanks a lot Khosrow !!