Himanshi Sharma
Himanshi Sharma

Reputation: 21

Creating a new quad store with go(cayley)?

I'm new to go and I'm trying to create a Quad store using cayley/graph library(NewQuadStore()). I'm trying to do it on testdata.nq file which is a sample data that comes with cayley. Here is my code:

package main

import (
  "fmt"
  "github.com/google/cayley/graph"
  "log"
)

func main() {

var register graph.QuadStoreRegistration
graph.RegisterQuadStore("testdata", register)

store, err := graph.NewQuadStore("testdata", "data/testdata.nq", nil)
if err != nil {
    log.Fatalln(err)
}
defer store.Close()
store.Type()

iterator := store.NodesAllIterator()
for iterator.NextPath() {
    fmt.Println(store.NameOf(iterator.Result()))
}
}

It compiles with no error but generates a panic when I run it. It looks like this :-

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x47045e]

goroutine 1 [running]:
panic(0x5dbfa0, 0xc82000a120)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/google/cayley/graph.NewQuadStore(0x625c60, 0x8, 0x642500,   0x10, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/himanshi/dev/go/src/github.com/google/cayley/graph/quadstore.go:179 +0x23e
main.main()
/home/himanshi/dev/go/src/cayley/main.go:14 +0xcd

I tried to look inside the quadstore.go to look for the problem but I couldn't figure it out and I can't find anything on godoc as well. Please Help. Thank You!

Upvotes: 2

Views: 509

Answers (1)

user1431317
user1431317

Reputation: 3044

var register graph.QuadStoreRegistration

This creates a struct with zero values. register.NewFunc is nil. graph.NewQuadStore tries to call it.

You have to initialize register with some kind of NewFunc, e.g. https://github.com/google/cayley/blob/master/graph/mongo/quadstore.go#L37

Upvotes: 0

Related Questions