Merge pull request #28 from kortschak/destutter
Destutter labels and files
This commit is contained in:
commit
dc65ebce9e
74 changed files with 4945 additions and 4929 deletions
14
.travis.yml
14
.travis.yml
|
|
@ -4,3 +4,17 @@ install:
|
||||||
- go get github.com/jacobsa/ogletest
|
- go get github.com/jacobsa/ogletest
|
||||||
- go get github.com/jacobsa/oglematchers
|
- go get github.com/jacobsa/oglematchers
|
||||||
- go get github.com/smartystreets/goconvey
|
- go get github.com/smartystreets/goconvey
|
||||||
|
- go get github.com/badgerodon/peg
|
||||||
|
- go get github.com/barakmich/glog
|
||||||
|
- go get github.com/julienschmidt/httprouter
|
||||||
|
- go get github.com/petar/GoLLRB/llrb
|
||||||
|
- go get github.com/robertkrimen/otto
|
||||||
|
- go get github.com/russross/blackfriday
|
||||||
|
- go get github.com/stretchrcom/testify/mock
|
||||||
|
- go get github.com/syndtr/goleveldb/leveldb
|
||||||
|
- go get github.com/syndtr/goleveldb/leveldb/cache
|
||||||
|
- go get github.com/syndtr/goleveldb/leveldb/iterator
|
||||||
|
- go get github.com/syndtr/goleveldb/leveldb/opt
|
||||||
|
- go get github.com/syndtr/goleveldb/leveldb/util
|
||||||
|
- go get labix.org/v2/mgo
|
||||||
|
- go get labix.org/v2/mgo/bson
|
||||||
|
|
|
||||||
1
AUTHORS
1
AUTHORS
|
|
@ -9,3 +9,4 @@
|
||||||
# Please keep the list sorted.
|
# Please keep the list sorted.
|
||||||
|
|
||||||
Google Inc.
|
Google Inc.
|
||||||
|
Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au>
|
||||||
|
|
|
||||||
|
|
@ -12,3 +12,4 @@
|
||||||
# Please keep the list sorted.
|
# Please keep the list sorted.
|
||||||
|
|
||||||
Barak Michener <barakmich@google.com> <barak@cayley.io> <me@barakmich.com>
|
Barak Michener <barakmich@google.com> <barak@cayley.io> <me@barakmich.com>
|
||||||
|
Robert Daniel Kortschak <dan.kortschak@adelaide.edu.au>
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ Cayley is an open-source graph inspired by the graph database behind [Freebase](
|
||||||
|
|
||||||
Its goal is to be a part of the developer's toolbox where [Linked Data](http://linkeddata.org/) and graph-shaped data (semantic webs, social networks, etc) in general are concerned.
|
Its goal is to be a part of the developer's toolbox where [Linked Data](http://linkeddata.org/) and graph-shaped data (semantic webs, social networks, etc) in general are concerned.
|
||||||
|
|
||||||
|
[](https://travis-ci.org/google/cayley)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
glog.SetToStderr(true)
|
glog.SetToStderr(true)
|
||||||
cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
|
cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
glog.Errorln(cfg)
|
glog.Errorln(cfg)
|
||||||
LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
|
LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
|
||||||
http.SetupRoutes(ts, cfg)
|
http.SetupRoutes(ts, cfg)
|
||||||
|
|
|
||||||
14
cayley.go
14
cayley.go
|
|
@ -69,18 +69,18 @@ func main() {
|
||||||
}
|
}
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "init":
|
case "init":
|
||||||
db.CayleyInit(cfg, *tripleFile)
|
db.Init(cfg, *tripleFile)
|
||||||
case "load":
|
case "load":
|
||||||
ts = db.OpenTSFromConfig(cfg)
|
ts = db.Open(cfg)
|
||||||
db.CayleyLoad(ts, cfg, *tripleFile, false)
|
db.Load(ts, cfg, *tripleFile, false)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
case "repl":
|
case "repl":
|
||||||
ts = db.OpenTSFromConfig(cfg)
|
ts = db.Open(cfg)
|
||||||
db.CayleyRepl(ts, *queryLanguage, cfg)
|
db.Repl(ts, *queryLanguage, cfg)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
case "http":
|
case "http":
|
||||||
ts = db.OpenTSFromConfig(cfg)
|
ts = db.Open(cfg)
|
||||||
http.CayleyHTTP(ts, cfg)
|
http.Serve(ts, cfg)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
default:
|
default:
|
||||||
fmt.Println("No command", cmd)
|
fmt.Println("No command", cmd)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/barakmich/glog"
|
"github.com/barakmich/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CayleyConfig struct {
|
type Config struct {
|
||||||
DatabaseType string `json:"database"`
|
DatabaseType string `json:"database"`
|
||||||
DatabasePath string `json:"db_path"`
|
DatabasePath string `json:"db_path"`
|
||||||
DatabaseOptions map[string]interface{} `json:"db_options"`
|
DatabaseOptions map[string]interface{} `json:"db_options"`
|
||||||
|
|
@ -41,8 +41,8 @@ var port = flag.String("port", "64210", "Port to listen on.")
|
||||||
var readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.")
|
var readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.")
|
||||||
var gremlinTimeout = flag.Int("gremlin_timeout", 30, "Number of seconds until an individual query times out.")
|
var gremlinTimeout = flag.Int("gremlin_timeout", 30, "Number of seconds until an individual query times out.")
|
||||||
|
|
||||||
func ParseConfigFromFile(filename string) *CayleyConfig {
|
func ParseConfigFromFile(filename string) *Config {
|
||||||
config := &CayleyConfig{}
|
config := &Config{}
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ func ParseConfigFromFile(filename string) *CayleyConfig {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfigFromFlagsAndFile(fileFlag string) *CayleyConfig {
|
func ParseConfigFromFlagsAndFile(fileFlag string) *Config {
|
||||||
// Find the file...
|
// Find the file...
|
||||||
var trueFilename string
|
var trueFilename string
|
||||||
if fileFlag != "" {
|
if fileFlag != "" {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool {
|
func Init(cfg *config.Config, triplePath string) bool {
|
||||||
created := false
|
created := false
|
||||||
dbpath := cfg.DatabasePath
|
dbpath := cfg.DatabasePath
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
|
|
@ -32,8 +32,8 @@ func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if created && triplePath != "" {
|
if created && triplePath != "" {
|
||||||
ts := OpenTSFromConfig(cfg)
|
ts := Open(cfg)
|
||||||
CayleyLoad(ts, cfg, triplePath, true)
|
Load(ts, cfg, triplePath, true)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
}
|
}
|
||||||
return created
|
return created
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@ import (
|
||||||
"github.com/google/cayley/nquads"
|
"github.com/google/cayley/nquads"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) {
|
func Load(ts graph.TripleStore, cfg *config.Config, triplePath string, firstTime bool) {
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
if firstTime {
|
if firstTime {
|
||||||
loadMongo(ts.(*mongo.MongoTripleStore), triplePath)
|
loadMongo(ts.(*mongo.TripleStore), triplePath)
|
||||||
} else {
|
} else {
|
||||||
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath strin
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMongo(ts *mongo.MongoTripleStore, path string) {
|
func loadMongo(ts *mongo.TripleStore, path string) {
|
||||||
tChan := make(chan *graph.Triple)
|
tChan := make(chan *graph.Triple)
|
||||||
go ReadTriplesFromFile(tChan, path)
|
go ReadTriplesFromFile(tChan, path)
|
||||||
ts.BulkLoad(tChan)
|
ts.BulkLoad(tChan)
|
||||||
|
|
|
||||||
10
db/open.go
10
db/open.go
|
|
@ -24,16 +24,16 @@ import (
|
||||||
"github.com/google/cayley/graph/mongo"
|
"github.com/google/cayley/graph/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore {
|
func Open(cfg *config.Config) graph.TripleStore {
|
||||||
glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
|
glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case "mongo", "mongodb":
|
case "mongo", "mongodb":
|
||||||
return mongo.NewMongoTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
return mongo.NewTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
||||||
case "leveldb":
|
case "leveldb":
|
||||||
return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
return leveldb.NewTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
|
||||||
case "mem":
|
case "mem":
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
CayleyLoad(ts, cfg, cfg.DatabasePath, true)
|
Load(ts, cfg, cfg.DatabasePath, true)
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
panic("Unsupported database backend " + cfg.DatabaseType)
|
panic("Unsupported database backend " + cfg.DatabaseType)
|
||||||
|
|
|
||||||
16
db/repl.go
16
db/repl.go
|
|
@ -40,7 +40,7 @@ func un(s string, startTime time.Time) {
|
||||||
fmt.Printf(s, float64(endTime.UnixNano()-startTime.UnixNano())/float64(1E6))
|
fmt.Printf(s, float64(endTime.UnixNano()-startTime.UnixNano())/float64(1E6))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunQuery(query string, ses graph.Session) {
|
func Run(query string, ses graph.Session) {
|
||||||
nResults := 0
|
nResults := 0
|
||||||
startTrace, startTime := trace("Elapsed time: %g ms\n\n")
|
startTrace, startTime := trace("Elapsed time: %g ms\n\n")
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -60,17 +60,17 @@ func RunQuery(query string, ses graph.Session) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) {
|
func Repl(ts graph.TripleStore, queryLanguage string, cfg *config.Config) {
|
||||||
var ses graph.Session
|
var ses graph.Session
|
||||||
switch queryLanguage {
|
switch queryLanguage {
|
||||||
case "sexp":
|
case "sexp":
|
||||||
ses = sexp.NewSexpSession(ts)
|
ses = sexp.NewSession(ts)
|
||||||
case "mql":
|
case "mql":
|
||||||
ses = mql.NewMqlSession(ts)
|
ses = mql.NewSession(ts)
|
||||||
case "gremlin":
|
case "gremlin":
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
ses = gremlin.NewGremlinSession(ts, cfg.GremlinTimeout, true)
|
ses = gremlin.NewSession(ts, cfg.GremlinTimeout, true)
|
||||||
}
|
}
|
||||||
inputBf := bufio.NewReader(os.Stdin)
|
inputBf := bufio.NewReader(os.Stdin)
|
||||||
line := ""
|
line := ""
|
||||||
|
|
@ -106,7 +106,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyCo
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, ":a") {
|
if strings.HasPrefix(line, ":a") {
|
||||||
var tripleStmt = line[3:]
|
var tripleStmt = line[3:]
|
||||||
triple := nquads.ParseLineToTriple(tripleStmt)
|
triple := nquads.Parse(tripleStmt)
|
||||||
if triple == nil {
|
if triple == nil {
|
||||||
fmt.Println("Not a valid triple.")
|
fmt.Println("Not a valid triple.")
|
||||||
line = ""
|
line = ""
|
||||||
|
|
@ -118,7 +118,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyCo
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, ":d") {
|
if strings.HasPrefix(line, ":d") {
|
||||||
var tripleStmt = line[3:]
|
var tripleStmt = line[3:]
|
||||||
triple := nquads.ParseLineToTriple(tripleStmt)
|
triple := nquads.Parse(tripleStmt)
|
||||||
if triple == nil {
|
if triple == nil {
|
||||||
fmt.Println("Not a valid triple.")
|
fmt.Println("Not a valid triple.")
|
||||||
line = ""
|
line = ""
|
||||||
|
|
@ -131,7 +131,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyCo
|
||||||
result, err := ses.InputParses(line)
|
result, err := ses.InputParses(line)
|
||||||
switch result {
|
switch result {
|
||||||
case graph.Parsed:
|
case graph.Parsed:
|
||||||
RunQuery(line, ses)
|
Run(line, ses)
|
||||||
line = ""
|
line = ""
|
||||||
case graph.ParseFail:
|
case graph.ParseFail:
|
||||||
fmt.Println("Error: ", err)
|
fmt.Println("Error: ", err)
|
||||||
|
|
|
||||||
|
|
@ -19,26 +19,26 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
|
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||||
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LevelDBAllIterator struct {
|
type AllIterator struct {
|
||||||
graph.BaseIterator
|
graph.BaseIterator
|
||||||
prefix []byte
|
prefix []byte
|
||||||
dir string
|
dir string
|
||||||
open bool
|
open bool
|
||||||
it leveldb_it.Iterator
|
it iterator.Iterator
|
||||||
ts *LevelDBTripleStore
|
ts *TripleStore
|
||||||
ro *leveldb_opt.ReadOptions
|
ro *opt.ReadOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLevelDBAllIterator(prefix, dir string, ts *LevelDBTripleStore) *LevelDBAllIterator {
|
func NewLevelDBAllIterator(prefix, dir string, ts *TripleStore) *AllIterator {
|
||||||
var it LevelDBAllIterator
|
var it AllIterator
|
||||||
graph.BaseIteratorInit(&it.BaseIterator)
|
graph.BaseIteratorInit(&it.BaseIterator)
|
||||||
it.ro = &leveldb_opt.ReadOptions{}
|
it.ro = &opt.ReadOptions{}
|
||||||
it.ro.DontFillCache = true
|
it.ro.DontFillCache = true
|
||||||
it.it = ts.db.NewIterator(nil, it.ro)
|
it.it = ts.db.NewIterator(nil, it.ro)
|
||||||
it.prefix = []byte(prefix)
|
it.prefix = []byte(prefix)
|
||||||
|
|
@ -53,7 +53,7 @@ func NewLevelDBAllIterator(prefix, dir string, ts *LevelDBTripleStore) *LevelDBA
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *LevelDBAllIterator) Reset() {
|
func (a *AllIterator) Reset() {
|
||||||
if !a.open {
|
if !a.open {
|
||||||
a.it = a.ts.db.NewIterator(nil, a.ro)
|
a.it = a.ts.db.NewIterator(nil, a.ro)
|
||||||
a.open = true
|
a.open = true
|
||||||
|
|
@ -65,13 +65,13 @@ func (a *LevelDBAllIterator) Reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *LevelDBAllIterator) Clone() graph.Iterator {
|
func (a *AllIterator) Clone() graph.Iterator {
|
||||||
out := NewLevelDBAllIterator(string(a.prefix), a.dir, a.ts)
|
out := NewLevelDBAllIterator(string(a.prefix), a.dir, a.ts)
|
||||||
out.CopyTagsFrom(a)
|
out.CopyTagsFrom(a)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *LevelDBAllIterator) Next() (graph.TSVal, bool) {
|
func (a *AllIterator) Next() (graph.TSVal, bool) {
|
||||||
if !a.open {
|
if !a.open {
|
||||||
a.Last = nil
|
a.Last = nil
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|
@ -91,19 +91,19 @@ func (a *LevelDBAllIterator) Next() (graph.TSVal, bool) {
|
||||||
return out, true
|
return out, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *LevelDBAllIterator) Check(v graph.TSVal) bool {
|
func (a *AllIterator) Check(v graph.TSVal) bool {
|
||||||
a.Last = v
|
a.Last = v
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBAllIterator) Close() {
|
func (lit *AllIterator) Close() {
|
||||||
if lit.open {
|
if lit.open {
|
||||||
lit.it.Release()
|
lit.it.Release()
|
||||||
lit.open = false
|
lit.open = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *LevelDBAllIterator) Size() (int64, bool) {
|
func (a *AllIterator) Size() (int64, bool) {
|
||||||
size, err := a.ts.GetApproximateSizeForPrefix(a.prefix)
|
size, err := a.ts.GetApproximateSizeForPrefix(a.prefix)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return size, false
|
return size, false
|
||||||
|
|
@ -112,19 +112,19 @@ func (a *LevelDBAllIterator) Size() (int64, bool) {
|
||||||
return int64(^uint64(0) >> 1), false
|
return int64(^uint64(0) >> 1), false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBAllIterator) DebugString(indent int) string {
|
func (lit *AllIterator) DebugString(indent int) string {
|
||||||
size, _ := lit.Size()
|
size, _ := lit.Size()
|
||||||
return fmt.Sprintf("%s(%s tags: %v leveldb size:%d %s %p)", strings.Repeat(" ", indent), lit.Type(), lit.Tags(), size, lit.dir, lit)
|
return fmt.Sprintf("%s(%s tags: %v leveldb size:%d %s %p)", strings.Repeat(" ", indent), lit.Type(), lit.Tags(), size, lit.dir, lit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBAllIterator) Type() string { return "all" }
|
func (lit *AllIterator) Type() string { return "all" }
|
||||||
func (lit *LevelDBAllIterator) Sorted() bool { return false }
|
func (lit *AllIterator) Sorted() bool { return false }
|
||||||
|
|
||||||
func (lit *LevelDBAllIterator) Optimize() (graph.Iterator, bool) {
|
func (lit *AllIterator) Optimize() (graph.Iterator, bool) {
|
||||||
return lit, false
|
return lit, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBAllIterator) GetStats() *graph.IteratorStats {
|
func (lit *AllIterator) GetStats() *graph.IteratorStats {
|
||||||
s, _ := lit.Size()
|
s, _ := lit.Size()
|
||||||
return &graph.IteratorStats{
|
return &graph.IteratorStats{
|
||||||
CheckCost: 1,
|
CheckCost: 1,
|
||||||
|
|
@ -16,30 +16,29 @@ package leveldb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
_ "encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
|
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||||
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
|
"github.com/syndtr/goleveldb/leveldb/opt"
|
||||||
|
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LevelDBIterator struct {
|
type Iterator struct {
|
||||||
graph.BaseIterator
|
graph.BaseIterator
|
||||||
nextPrefix []byte
|
nextPrefix []byte
|
||||||
checkId []byte
|
checkId []byte
|
||||||
dir string
|
dir string
|
||||||
open bool
|
open bool
|
||||||
it leveldb_it.Iterator
|
it iterator.Iterator
|
||||||
ts *LevelDBTripleStore
|
ts *TripleStore
|
||||||
ro *leveldb_opt.ReadOptions
|
ro *opt.ReadOptions
|
||||||
originalPrefix string
|
originalPrefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTripleStore) *LevelDBIterator {
|
func NewIterator(prefix, dir string, value graph.TSVal, ts *TripleStore) *Iterator {
|
||||||
var it LevelDBIterator
|
var it Iterator
|
||||||
graph.BaseIteratorInit(&it.BaseIterator)
|
graph.BaseIteratorInit(&it.BaseIterator)
|
||||||
it.checkId = value.([]byte)
|
it.checkId = value.([]byte)
|
||||||
it.dir = dir
|
it.dir = dir
|
||||||
|
|
@ -47,7 +46,7 @@ func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTriple
|
||||||
it.nextPrefix = make([]byte, 0, 2+ts.hasher.Size())
|
it.nextPrefix = make([]byte, 0, 2+ts.hasher.Size())
|
||||||
it.nextPrefix = append(it.nextPrefix, []byte(prefix)...)
|
it.nextPrefix = append(it.nextPrefix, []byte(prefix)...)
|
||||||
it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
|
it.nextPrefix = append(it.nextPrefix, []byte(it.checkId[1:])...)
|
||||||
it.ro = &leveldb_opt.ReadOptions{}
|
it.ro = &opt.ReadOptions{}
|
||||||
it.ro.DontFillCache = true
|
it.ro.DontFillCache = true
|
||||||
it.it = ts.db.NewIterator(nil, it.ro)
|
it.it = ts.db.NewIterator(nil, it.ro)
|
||||||
it.open = true
|
it.open = true
|
||||||
|
|
@ -60,7 +59,7 @@ func NewLevelDBIterator(prefix, dir string, value graph.TSVal, ts *LevelDBTriple
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Reset() {
|
func (lit *Iterator) Reset() {
|
||||||
if !lit.open {
|
if !lit.open {
|
||||||
lit.it = lit.ts.db.NewIterator(nil, lit.ro)
|
lit.it = lit.ts.db.NewIterator(nil, lit.ro)
|
||||||
lit.open = true
|
lit.open = true
|
||||||
|
|
@ -72,20 +71,20 @@ func (lit *LevelDBIterator) Reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Clone() graph.Iterator {
|
func (lit *Iterator) Clone() graph.Iterator {
|
||||||
out := NewLevelDBIterator(lit.originalPrefix, lit.dir, lit.checkId, lit.ts)
|
out := NewIterator(lit.originalPrefix, lit.dir, lit.checkId, lit.ts)
|
||||||
out.CopyTagsFrom(lit)
|
out.CopyTagsFrom(lit)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Close() {
|
func (lit *Iterator) Close() {
|
||||||
if lit.open {
|
if lit.open {
|
||||||
lit.it.Release()
|
lit.it.Release()
|
||||||
lit.open = false
|
lit.open = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Next() (graph.TSVal, bool) {
|
func (lit *Iterator) Next() (graph.TSVal, bool) {
|
||||||
if lit.it == nil {
|
if lit.it == nil {
|
||||||
lit.Last = nil
|
lit.Last = nil
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|
@ -114,7 +113,7 @@ func (lit *LevelDBIterator) Next() (graph.TSVal, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPositionFromPrefix(prefix []byte, dir string, ts *LevelDBTripleStore) int {
|
func GetPositionFromPrefix(prefix []byte, dir string, ts *TripleStore) int {
|
||||||
if bytes.Equal(prefix, []byte("sp")) {
|
if bytes.Equal(prefix, []byte("sp")) {
|
||||||
switch dir {
|
switch dir {
|
||||||
case "s":
|
case "s":
|
||||||
|
|
@ -166,7 +165,7 @@ func GetPositionFromPrefix(prefix []byte, dir string, ts *LevelDBTripleStore) in
|
||||||
panic("Notreached")
|
panic("Notreached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Check(v graph.TSVal) bool {
|
func (lit *Iterator) Check(v graph.TSVal) bool {
|
||||||
val := v.([]byte)
|
val := v.([]byte)
|
||||||
if val[0] == 'z' {
|
if val[0] == 'z' {
|
||||||
return false
|
return false
|
||||||
|
|
@ -186,23 +185,23 @@ func (lit *LevelDBIterator) Check(v graph.TSVal) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Size() (int64, bool) {
|
func (lit *Iterator) Size() (int64, bool) {
|
||||||
return lit.ts.GetSizeFor(lit.checkId), true
|
return lit.ts.GetSizeFor(lit.checkId), true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) DebugString(indent int) string {
|
func (lit *Iterator) DebugString(indent int) string {
|
||||||
size, _ := lit.Size()
|
size, _ := lit.Size()
|
||||||
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), lit.Type(), lit.GetUid(), lit.Tags(), lit.dir, size, lit.ts.GetNameFor(lit.checkId))
|
return fmt.Sprintf("%s(%s %d tags: %v dir: %s size:%d %s)", strings.Repeat(" ", indent), lit.Type(), lit.GetUid(), lit.Tags(), lit.dir, size, lit.ts.GetNameFor(lit.checkId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Type() string { return "leveldb" }
|
func (lit *Iterator) Type() string { return "leveldb" }
|
||||||
func (lit *LevelDBIterator) Sorted() bool { return false }
|
func (lit *Iterator) Sorted() bool { return false }
|
||||||
|
|
||||||
func (lit *LevelDBIterator) Optimize() (graph.Iterator, bool) {
|
func (lit *Iterator) Optimize() (graph.Iterator, bool) {
|
||||||
return lit, false
|
return lit, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lit *LevelDBIterator) GetStats() *graph.IteratorStats {
|
func (lit *Iterator) GetStats() *graph.IteratorStats {
|
||||||
s, _ := lit.Size()
|
s, _ := lit.Size()
|
||||||
return &graph.IteratorStats{
|
return &graph.IteratorStats{
|
||||||
CheckCost: 1,
|
CheckCost: 1,
|
||||||
|
|
@ -79,7 +79,7 @@ func TestCreateDatabase(t *testing.T) {
|
||||||
ok := CreateNewLevelDB(tmpDir)
|
ok := CreateNewLevelDB(tmpDir)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
Convey("And has good defaults for a new database", func() {
|
Convey("And has good defaults for a new database", func() {
|
||||||
ts := NewDefaultLevelDBTripleStore(tmpDir, nil)
|
ts := NewTripleStore(tmpDir, nil)
|
||||||
So(ts, ShouldNotBeNil)
|
So(ts, ShouldNotBeNil)
|
||||||
So(ts.Size(), ShouldEqual, 0)
|
So(ts.Size(), ShouldEqual, 0)
|
||||||
ts.Close()
|
ts.Close()
|
||||||
|
|
@ -89,7 +89,7 @@ func TestCreateDatabase(t *testing.T) {
|
||||||
Convey("Fails if it cannot create the database", func() {
|
Convey("Fails if it cannot create the database", func() {
|
||||||
ok := CreateNewLevelDB("/dev/null/some terrible path")
|
ok := CreateNewLevelDB("/dev/null/some terrible path")
|
||||||
So(ok, ShouldBeFalse)
|
So(ok, ShouldBeFalse)
|
||||||
So(func() { NewDefaultLevelDBTripleStore("/dev/null/some terrible path", nil) }, ShouldPanic)
|
So(func() { NewTripleStore("/dev/null/some terrible path", nil) }, ShouldPanic)
|
||||||
})
|
})
|
||||||
|
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
|
|
@ -101,14 +101,14 @@ func TestCreateDatabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDatabase(t *testing.T) {
|
func TestLoadDatabase(t *testing.T) {
|
||||||
var ts *LevelDBTripleStore
|
var ts *TripleStore
|
||||||
|
|
||||||
Convey("Given a created database path", t, func() {
|
Convey("Given a created database path", t, func() {
|
||||||
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
||||||
t.Log(tmpDir)
|
t.Log(tmpDir)
|
||||||
ok := CreateNewLevelDB(tmpDir)
|
ok := CreateNewLevelDB(tmpDir)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
ts = NewTripleStore(tmpDir, nil)
|
||||||
|
|
||||||
Convey("Can load a single triple", func() {
|
Convey("Can load a single triple", func() {
|
||||||
ts.AddTriple(graph.MakeTriple("Something", "points_to", "Something Else", "context"))
|
ts.AddTriple(graph.MakeTriple("Something", "points_to", "Something Else", "context"))
|
||||||
|
|
@ -139,7 +139,7 @@ func TestLoadDatabase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIterator(t *testing.T) {
|
func TestIterator(t *testing.T) {
|
||||||
var ts *LevelDBTripleStore
|
var ts *TripleStore
|
||||||
|
|
||||||
Convey("Given a prepared database", t, func() {
|
Convey("Given a prepared database", t, func() {
|
||||||
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
tmpDir, _ := ioutil.TempDir(os.TempDir(), "cayley_test")
|
||||||
|
|
@ -147,7 +147,7 @@ func TestIterator(t *testing.T) {
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
ok := CreateNewLevelDB(tmpDir)
|
ok := CreateNewLevelDB(tmpDir)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
ts = NewTripleStore(tmpDir, nil)
|
||||||
ts.AddTripleSet(makeTripleSet())
|
ts.AddTripleSet(makeTripleSet())
|
||||||
var it graph.Iterator
|
var it graph.Iterator
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ func TestIterator(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetIterator(t *testing.T) {
|
func TestSetIterator(t *testing.T) {
|
||||||
var ts *LevelDBTripleStore
|
var ts *TripleStore
|
||||||
var tmpDir string
|
var tmpDir string
|
||||||
|
|
||||||
Convey("Given a prepared database", t, func() {
|
Convey("Given a prepared database", t, func() {
|
||||||
|
|
@ -243,7 +243,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
ok := CreateNewLevelDB(tmpDir)
|
ok := CreateNewLevelDB(tmpDir)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
ts = NewTripleStore(tmpDir, nil)
|
||||||
ts.AddTripleSet(makeTripleSet())
|
ts.AddTripleSet(makeTripleSet())
|
||||||
var it graph.Iterator
|
var it graph.Iterator
|
||||||
|
|
||||||
|
|
@ -383,7 +383,7 @@ func TestSetIterator(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOptimize(t *testing.T) {
|
func TestOptimize(t *testing.T) {
|
||||||
var ts *LevelDBTripleStore
|
var ts *TripleStore
|
||||||
var lto graph.Iterator
|
var lto graph.Iterator
|
||||||
var tmpDir string
|
var tmpDir string
|
||||||
|
|
||||||
|
|
@ -393,7 +393,7 @@ func TestOptimize(t *testing.T) {
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
ok := CreateNewLevelDB(tmpDir)
|
ok := CreateNewLevelDB(tmpDir)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
ts = NewDefaultLevelDBTripleStore(tmpDir, nil)
|
ts = NewTripleStore(tmpDir, nil)
|
||||||
ts.AddTripleSet(makeTripleSet())
|
ts.AddTripleSet(makeTripleSet())
|
||||||
|
|
||||||
Convey("With an linksto-fixed pair", func() {
|
Convey("With an linksto-fixed pair", func() {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ import (
|
||||||
const DefaultCacheSize = 2
|
const DefaultCacheSize = 2
|
||||||
const DefaultWriteBufferSize = 20
|
const DefaultWriteBufferSize = 20
|
||||||
|
|
||||||
type LevelDBTripleStore struct {
|
type TripleStore struct {
|
||||||
dbOpts *leveldb_opt.Options
|
dbOpts *leveldb_opt.Options
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
path string
|
path string
|
||||||
|
|
@ -53,7 +53,7 @@ func CreateNewLevelDB(path string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
ts := &LevelDBTripleStore{}
|
ts := &TripleStore{}
|
||||||
ts.db = db
|
ts.db = db
|
||||||
ts.writeopts = &leveldb_opt.WriteOptions{
|
ts.writeopts = &leveldb_opt.WriteOptions{
|
||||||
Sync: true,
|
Sync: true,
|
||||||
|
|
@ -62,8 +62,8 @@ func CreateNewLevelDB(path string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultLevelDBTripleStore(path string, options graph.OptionsDict) *LevelDBTripleStore {
|
func NewTripleStore(path string, options graph.OptionsDict) *TripleStore {
|
||||||
var ts LevelDBTripleStore
|
var ts TripleStore
|
||||||
ts.path = path
|
ts.path = path
|
||||||
cache_size := DefaultCacheSize
|
cache_size := DefaultCacheSize
|
||||||
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
if val, ok := options.GetIntKey("cache_size_mb"); ok {
|
||||||
|
|
@ -94,7 +94,7 @@ func NewDefaultLevelDBTripleStore(path string, options graph.OptionsDict) *Level
|
||||||
return &ts
|
return &ts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetStats() string {
|
func (ts *TripleStore) GetStats() string {
|
||||||
out := ""
|
out := ""
|
||||||
stats, err := ts.db.GetProperty("leveldb.stats")
|
stats, err := ts.db.GetProperty("leveldb.stats")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -104,11 +104,11 @@ func (ts *LevelDBTripleStore) GetStats() string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) Size() int64 {
|
func (ts *TripleStore) Size() int64 {
|
||||||
return ts.size
|
return ts.size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) createKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
func (ts *TripleStore) createKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||||
key := make([]byte, 0, 2+(ts.hasher.Size()*3))
|
key := make([]byte, 0, 2+(ts.hasher.Size()*3))
|
||||||
key = append(key, []byte(dir1+dir2)...)
|
key = append(key, []byte(dir1+dir2)...)
|
||||||
key = append(key, ts.convertStringToByteHash(triple.Get(dir1))...)
|
key = append(key, ts.convertStringToByteHash(triple.Get(dir1))...)
|
||||||
|
|
@ -117,7 +117,7 @@ func (ts *LevelDBTripleStore) createKeyFor(dir1, dir2, dir3 string, triple *grap
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
func (ts *TripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *graph.Triple) []byte {
|
||||||
key := make([]byte, 0, 2+(ts.hasher.Size()*4))
|
key := make([]byte, 0, 2+(ts.hasher.Size()*4))
|
||||||
key = append(key, []byte("c"+dir1)...)
|
key = append(key, []byte("c"+dir1)...)
|
||||||
key = append(key, ts.convertStringToByteHash(triple.Get("c"))...)
|
key = append(key, ts.convertStringToByteHash(triple.Get("c"))...)
|
||||||
|
|
@ -127,14 +127,14 @@ func (ts *LevelDBTripleStore) createProvKeyFor(dir1, dir2, dir3 string, triple *
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) createValueKeyFor(s string) []byte {
|
func (ts *TripleStore) createValueKeyFor(s string) []byte {
|
||||||
key := make([]byte, 0, 1+ts.hasher.Size())
|
key := make([]byte, 0, 1+ts.hasher.Size())
|
||||||
key = append(key, []byte("z")...)
|
key = append(key, []byte("z")...)
|
||||||
key = append(key, ts.convertStringToByteHash(s)...)
|
key = append(key, ts.convertStringToByteHash(s)...)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) AddTriple(t *graph.Triple) {
|
func (ts *TripleStore) AddTriple(t *graph.Triple) {
|
||||||
batch := &leveldb.Batch{}
|
batch := &leveldb.Batch{}
|
||||||
ts.buildWrite(batch, t)
|
ts.buildWrite(batch, t)
|
||||||
err := ts.db.Write(batch, ts.writeopts)
|
err := ts.db.Write(batch, ts.writeopts)
|
||||||
|
|
@ -145,7 +145,7 @@ func (ts *LevelDBTripleStore) AddTriple(t *graph.Triple) {
|
||||||
ts.size++
|
ts.size++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) RemoveTriple(t *graph.Triple) {
|
func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
_, err := ts.db.Get(ts.createKeyFor("s", "p", "o", t), ts.readopts)
|
_, err := ts.db.Get(ts.createKeyFor("s", "p", "o", t), ts.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
glog.Errorf("Couldn't access DB to confirm deletion")
|
glog.Errorf("Couldn't access DB to confirm deletion")
|
||||||
|
|
@ -174,7 +174,7 @@ func (ts *LevelDBTripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
ts.size--
|
ts.size--
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
|
func (ts *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||||
bytes, err := json.Marshal(*t)
|
bytes, err := json.Marshal(*t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't write to buffer for triple %s\n %s\n", t.ToString(), err)
|
glog.Errorf("Couldn't write to buffer for triple %s\n %s\n", t.ToString(), err)
|
||||||
|
|
@ -188,7 +188,7 @@ func (ts *LevelDBTripleStore) buildTripleWrite(batch *leveldb.Batch, t *graph.Tr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
|
func (ts *TripleStore) buildWrite(batch *leveldb.Batch, t *graph.Triple) {
|
||||||
ts.buildTripleWrite(batch, t)
|
ts.buildTripleWrite(batch, t)
|
||||||
ts.UpdateValueKeyBy(t.Get("s"), 1, nil)
|
ts.UpdateValueKeyBy(t.Get("s"), 1, nil)
|
||||||
ts.UpdateValueKeyBy(t.Get("p"), 1, nil)
|
ts.UpdateValueKeyBy(t.Get("p"), 1, nil)
|
||||||
|
|
@ -203,7 +203,7 @@ type ValueData struct {
|
||||||
Size int64
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.Batch) {
|
func (ts *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.Batch) {
|
||||||
value := &ValueData{name, int64(amount)}
|
value := &ValueData{name, int64(amount)}
|
||||||
key := ts.createValueKeyFor(name)
|
key := ts.createValueKeyFor(name)
|
||||||
b, err := ts.db.Get(key, ts.readopts)
|
b, err := ts.db.Get(key, ts.readopts)
|
||||||
|
|
@ -249,7 +249,7 @@ func (ts *LevelDBTripleStore) UpdateValueKeyBy(name string, amount int, batch *l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) AddTripleSet(t_s []*graph.Triple) {
|
func (ts *TripleStore) AddTripleSet(t_s []*graph.Triple) {
|
||||||
batch := &leveldb.Batch{}
|
batch := &leveldb.Batch{}
|
||||||
newTs := len(t_s)
|
newTs := len(t_s)
|
||||||
resizeMap := make(map[string]int)
|
resizeMap := make(map[string]int)
|
||||||
|
|
@ -273,7 +273,7 @@ func (ts *LevelDBTripleStore) AddTripleSet(t_s []*graph.Triple) {
|
||||||
ts.size += int64(newTs)
|
ts.size += int64(newTs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ldbts *LevelDBTripleStore) Close() {
|
func (ldbts *TripleStore) Close() {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := binary.Write(buf, binary.LittleEndian, ldbts.size)
|
err := binary.Write(buf, binary.LittleEndian, ldbts.size)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -288,7 +288,7 @@ func (ldbts *LevelDBTripleStore) Close() {
|
||||||
ldbts.open = false
|
ldbts.open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
||||||
var triple graph.Triple
|
var triple graph.Triple
|
||||||
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
b, err := ts.db.Get(k.([]byte), ts.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
|
|
@ -307,7 +307,7 @@ func (ts *LevelDBTripleStore) GetTriple(k graph.TSVal) *graph.Triple {
|
||||||
return &triple
|
return &triple
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) convertStringToByteHash(s string) []byte {
|
func (ts *TripleStore) convertStringToByteHash(s string) []byte {
|
||||||
ts.hasher.Reset()
|
ts.hasher.Reset()
|
||||||
key := make([]byte, 0, ts.hasher.Size())
|
key := make([]byte, 0, ts.hasher.Size())
|
||||||
ts.hasher.Write([]byte(s))
|
ts.hasher.Write([]byte(s))
|
||||||
|
|
@ -315,11 +315,11 @@ func (ts *LevelDBTripleStore) convertStringToByteHash(s string) []byte {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetIdFor(s string) graph.TSVal {
|
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
||||||
return ts.createValueKeyFor(s)
|
return ts.createValueKeyFor(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) getValueData(value_key []byte) ValueData {
|
func (ts *TripleStore) getValueData(value_key []byte) ValueData {
|
||||||
var out ValueData
|
var out ValueData
|
||||||
if glog.V(3) {
|
if glog.V(3) {
|
||||||
glog.V(3).Infof("%s %v\n", string(value_key[0]), value_key)
|
glog.V(3).Infof("%s %v\n", string(value_key[0]), value_key)
|
||||||
|
|
@ -339,7 +339,7 @@ func (ts *LevelDBTripleStore) getValueData(value_key []byte) ValueData {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetNameFor(k graph.TSVal) string {
|
func (ts *TripleStore) GetNameFor(k graph.TSVal) string {
|
||||||
if k == nil {
|
if k == nil {
|
||||||
glog.V(2).Infoln("k was nil")
|
glog.V(2).Infoln("k was nil")
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -347,14 +347,14 @@ func (ts *LevelDBTripleStore) GetNameFor(k graph.TSVal) string {
|
||||||
return ts.getValueData(k.([]byte)).Name
|
return ts.getValueData(k.([]byte)).Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetSizeFor(k graph.TSVal) int64 {
|
func (ts *TripleStore) GetSizeFor(k graph.TSVal) int64 {
|
||||||
if k == nil {
|
if k == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return int64(ts.getValueData(k.([]byte)).Size)
|
return int64(ts.getValueData(k.([]byte)).Size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) getSize() {
|
func (ts *TripleStore) getSize() {
|
||||||
var size int64
|
var size int64
|
||||||
b, err := ts.db.Get([]byte("__size"), ts.readopts)
|
b, err := ts.db.Get([]byte("__size"), ts.readopts)
|
||||||
if err != nil && err != leveldb.ErrNotFound {
|
if err != nil && err != leveldb.ErrNotFound {
|
||||||
|
|
@ -373,7 +373,7 @@ func (ts *LevelDBTripleStore) getSize() {
|
||||||
ts.size = size
|
ts.size = size
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
func (ts *TripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, error) {
|
||||||
limit := make([]byte, len(pre))
|
limit := make([]byte, len(pre))
|
||||||
copy(limit, pre)
|
copy(limit, pre)
|
||||||
end := len(limit) - 1
|
end := len(limit) - 1
|
||||||
|
|
@ -388,29 +388,29 @@ func (ts *LevelDBTripleStore) GetApproximateSizeForPrefix(pre []byte) (int64, er
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
||||||
switch dir {
|
switch dir {
|
||||||
case "s":
|
case "s":
|
||||||
return NewLevelDBIterator("sp", "s", val, ts)
|
return NewIterator("sp", "s", val, ts)
|
||||||
case "p":
|
case "p":
|
||||||
return NewLevelDBIterator("po", "p", val, ts)
|
return NewIterator("po", "p", val, ts)
|
||||||
case "o":
|
case "o":
|
||||||
return NewLevelDBIterator("os", "o", val, ts)
|
return NewIterator("os", "o", val, ts)
|
||||||
case "c":
|
case "c":
|
||||||
return NewLevelDBIterator("cp", "c", val, ts)
|
return NewIterator("cp", "c", val, ts)
|
||||||
}
|
}
|
||||||
panic("Notreached " + dir)
|
panic("Notreached " + dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||||
return NewLevelDBAllIterator("z", "v", ts)
|
return NewLevelDBAllIterator("z", "v", ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||||
return NewLevelDBAllIterator("po", "p", ts)
|
return NewLevelDBAllIterator("po", "p", ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
||||||
v := val.([]uint8)
|
v := val.([]uint8)
|
||||||
offset := GetPositionFromPrefix(v[0:2], direction, ts)
|
offset := GetPositionFromPrefix(v[0:2], direction, ts)
|
||||||
if offset != -1 {
|
if offset != -1 {
|
||||||
|
|
@ -424,6 +424,6 @@ func compareBytes(a, b graph.TSVal) bool {
|
||||||
return bytes.Equal(a.([]uint8), b.([]uint8))
|
return bytes.Equal(a.([]uint8), b.([]uint8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) MakeFixed() *graph.FixedIterator {
|
func (ts *TripleStore) MakeFixed() *graph.FixedIterator {
|
||||||
return graph.NewFixedIteratorWithCompare(compareBytes)
|
return graph.NewFixedIteratorWithCompare(compareBytes)
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||||
switch it.Type() {
|
switch it.Type() {
|
||||||
case "linksto":
|
case "linksto":
|
||||||
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
||||||
|
|
@ -27,7 +27,7 @@ func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterato
|
||||||
return it, false
|
return it, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *LevelDBTripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||||
l := it.GetSubIterators()
|
l := it.GetSubIterators()
|
||||||
if l.Len() != 1 {
|
if l.Len() != 1 {
|
||||||
return it, false
|
return it, false
|
||||||
|
|
@ -18,19 +18,19 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MemstoreAllIterator struct {
|
type AllIterator struct {
|
||||||
graph.Int64AllIterator
|
graph.Int64AllIterator
|
||||||
ts *MemTripleStore
|
ts *TripleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMemstoreAllIterator(ts *MemTripleStore) *MemstoreAllIterator {
|
func NewMemstoreAllIterator(ts *TripleStore) *AllIterator {
|
||||||
var out MemstoreAllIterator
|
var out AllIterator
|
||||||
out.Int64AllIterator = *graph.NewInt64AllIterator(1, ts.idCounter-1)
|
out.Int64AllIterator = *graph.NewInt64AllIterator(1, ts.idCounter-1)
|
||||||
out.ts = ts
|
out.ts = ts
|
||||||
return &out
|
return &out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (memall *MemstoreAllIterator) Next() (graph.TSVal, bool) {
|
func (memall *AllIterator) Next() (graph.TSVal, bool) {
|
||||||
next, out := memall.Int64AllIterator.Next()
|
next, out := memall.Int64AllIterator.Next()
|
||||||
if !out {
|
if !out {
|
||||||
return next, out
|
return next, out
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LlrbIterator struct {
|
type Iterator struct {
|
||||||
graph.BaseIterator
|
graph.BaseIterator
|
||||||
tree *llrb.LLRB
|
tree *llrb.LLRB
|
||||||
data string
|
data string
|
||||||
|
|
@ -51,8 +51,8 @@ func IterateOne(tree *llrb.LLRB, last Int64) Int64 {
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLlrbIterator(tree *llrb.LLRB, data string) *LlrbIterator {
|
func NewLlrbIterator(tree *llrb.LLRB, data string) *Iterator {
|
||||||
var it LlrbIterator
|
var it Iterator
|
||||||
graph.BaseIteratorInit(&it.BaseIterator)
|
graph.BaseIteratorInit(&it.BaseIterator)
|
||||||
it.tree = tree
|
it.tree = tree
|
||||||
it.iterLast = Int64(-1)
|
it.iterLast = Int64(-1)
|
||||||
|
|
@ -60,19 +60,19 @@ func NewLlrbIterator(tree *llrb.LLRB, data string) *LlrbIterator {
|
||||||
return &it
|
return &it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Reset() {
|
func (it *Iterator) Reset() {
|
||||||
it.iterLast = Int64(-1)
|
it.iterLast = Int64(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Clone() graph.Iterator {
|
func (it *Iterator) Clone() graph.Iterator {
|
||||||
var new_it = NewLlrbIterator(it.tree, it.data)
|
var new_it = NewLlrbIterator(it.tree, it.data)
|
||||||
new_it.CopyTagsFrom(it)
|
new_it.CopyTagsFrom(it)
|
||||||
return new_it
|
return new_it
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Close() {}
|
func (it *Iterator) Close() {}
|
||||||
|
|
||||||
func (it *LlrbIterator) Next() (graph.TSVal, bool) {
|
func (it *Iterator) Next() (graph.TSVal, bool) {
|
||||||
graph.NextLogIn(it)
|
graph.NextLogIn(it)
|
||||||
if it.tree.Max() == nil || it.Last == int64(it.tree.Max().(Int64)) {
|
if it.tree.Max() == nil || it.Last == int64(it.tree.Max().(Int64)) {
|
||||||
return graph.NextLogOut(it, nil, false)
|
return graph.NextLogOut(it, nil, false)
|
||||||
|
|
@ -82,11 +82,11 @@ func (it *LlrbIterator) Next() (graph.TSVal, bool) {
|
||||||
return graph.NextLogOut(it, it.Last, true)
|
return graph.NextLogOut(it, it.Last, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Size() (int64, bool) {
|
func (it *Iterator) Size() (int64, bool) {
|
||||||
return int64(it.tree.Len()), true
|
return int64(it.tree.Len()), true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Check(v graph.TSVal) bool {
|
func (it *Iterator) Check(v graph.TSVal) bool {
|
||||||
graph.CheckLogIn(it, v)
|
graph.CheckLogIn(it, v)
|
||||||
if it.tree.Has(Int64(v.(int64))) {
|
if it.tree.Has(Int64(v.(int64))) {
|
||||||
it.Last = v
|
it.Last = v
|
||||||
|
|
@ -95,22 +95,22 @@ func (it *LlrbIterator) Check(v graph.TSVal) bool {
|
||||||
return graph.CheckLogOut(it, v, false)
|
return graph.CheckLogOut(it, v, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) DebugString(indent int) string {
|
func (it *Iterator) DebugString(indent int) string {
|
||||||
size, _ := it.Size()
|
size, _ := it.Size()
|
||||||
return fmt.Sprintf("%s(%s tags:%s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.Tags(), size, it.data)
|
return fmt.Sprintf("%s(%s tags:%s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.Tags(), size, it.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) Type() string {
|
func (it *Iterator) Type() string {
|
||||||
return "llrb"
|
return "llrb"
|
||||||
}
|
}
|
||||||
func (it *LlrbIterator) Sorted() bool {
|
func (it *Iterator) Sorted() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (it *LlrbIterator) Optimize() (graph.Iterator, bool) {
|
func (it *Iterator) Optimize() (graph.Iterator, bool) {
|
||||||
return it, false
|
return it, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *LlrbIterator) GetStats() *graph.IteratorStats {
|
func (it *Iterator) GetStats() *graph.IteratorStats {
|
||||||
return &graph.IteratorStats{
|
return &graph.IteratorStats{
|
||||||
CheckCost: int64(math.Log(float64(it.tree.Len()))) + 1,
|
CheckCost: int64(math.Log(float64(it.tree.Len()))) + 1,
|
||||||
NextCost: 1,
|
NextCost: 1,
|
||||||
|
|
@ -28,8 +28,8 @@ import "github.com/google/cayley/graph"
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
|
|
||||||
func MakeTestingMemstore() *MemTripleStore {
|
func MakeTestingMemstore() *TripleStore {
|
||||||
ts := NewMemTripleStore()
|
ts := NewTripleStore()
|
||||||
ts.AddTriple(graph.MakeTriple("A", "follows", "B", ""))
|
ts.AddTriple(graph.MakeTriple("A", "follows", "B", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("C", "follows", "B", ""))
|
ts.AddTriple(graph.MakeTriple("C", "follows", "B", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("C", "follows", "D", ""))
|
ts.AddTriple(graph.MakeTriple("C", "follows", "D", ""))
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ func (tdi *TripleDirectionIndex) Get(dir string, id int64) (*llrb.LLRB, bool) {
|
||||||
return tree, exists
|
return tree, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemTripleStore struct {
|
type TripleStore struct {
|
||||||
idCounter int64
|
idCounter int64
|
||||||
tripleIdCounter int64
|
tripleIdCounter int64
|
||||||
idMap map[string]int64
|
idMap map[string]int64
|
||||||
|
|
@ -77,8 +77,8 @@ type MemTripleStore struct {
|
||||||
// vip_index map[string]map[int64]map[string]map[int64]*llrb.Tree
|
// vip_index map[string]map[int64]map[string]map[int64]*llrb.Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMemTripleStore() *MemTripleStore {
|
func NewTripleStore() *TripleStore {
|
||||||
var ts MemTripleStore
|
var ts TripleStore
|
||||||
ts.idMap = make(map[string]int64)
|
ts.idMap = make(map[string]int64)
|
||||||
ts.revIdMap = make(map[int64]string)
|
ts.revIdMap = make(map[int64]string)
|
||||||
ts.triples = make([]graph.Triple, 1, 200)
|
ts.triples = make([]graph.Triple, 1, 200)
|
||||||
|
|
@ -92,13 +92,13 @@ func NewMemTripleStore() *MemTripleStore {
|
||||||
return &ts
|
return &ts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) AddTripleSet(triples []*graph.Triple) {
|
func (ts *TripleStore) AddTripleSet(triples []*graph.Triple) {
|
||||||
for _, t := range triples {
|
for _, t := range triples {
|
||||||
ts.AddTriple(t)
|
ts.AddTriple(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) tripleExists(t *graph.Triple) (bool, int64) {
|
func (ts *TripleStore) tripleExists(t *graph.Triple) (bool, int64) {
|
||||||
smallest := -1
|
smallest := -1
|
||||||
var smallest_tree *llrb.LLRB
|
var smallest_tree *llrb.LLRB
|
||||||
for _, dir := range graph.TripleDirections {
|
for _, dir := range graph.TripleDirections {
|
||||||
|
|
@ -135,7 +135,7 @@ func (ts *MemTripleStore) tripleExists(t *graph.Triple) (bool, int64) {
|
||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) AddTriple(t *graph.Triple) {
|
func (ts *TripleStore) AddTriple(t *graph.Triple) {
|
||||||
if exists, _ := ts.tripleExists(t); exists {
|
if exists, _ := ts.tripleExists(t); exists {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +169,7 @@ func (ts *MemTripleStore) AddTriple(t *graph.Triple) {
|
||||||
// TODO(barakmich): Add VIP indexing
|
// TODO(barakmich): Add VIP indexing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) RemoveTriple(t *graph.Triple) {
|
func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
var tripleID int64
|
var tripleID int64
|
||||||
var exists bool
|
var exists bool
|
||||||
tripleID = 0
|
tripleID = 0
|
||||||
|
|
@ -215,11 +215,11 @@ func (ts *MemTripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetTriple(index graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) GetTriple(index graph.TSVal) *graph.Triple {
|
||||||
return &ts.triples[index.(int64)]
|
return &ts.triples[index.(int64)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetTripleIterator(direction string, value graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) GetTripleIterator(direction string, value graph.TSVal) graph.Iterator {
|
||||||
index, ok := ts.index.Get(direction, value.(int64))
|
index, ok := ts.index.Get(direction, value.(int64))
|
||||||
data := fmt.Sprintf("dir:%s val:%d", direction, value.(int64))
|
data := fmt.Sprintf("dir:%s val:%d", direction, value.(int64))
|
||||||
if ok {
|
if ok {
|
||||||
|
|
@ -228,11 +228,11 @@ func (ts *MemTripleStore) GetTripleIterator(direction string, value graph.TSVal)
|
||||||
return &graph.NullIterator{}
|
return &graph.NullIterator{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) Size() int64 {
|
func (ts *TripleStore) Size() int64 {
|
||||||
return ts.size - 1 // Don't count the sentinel
|
return ts.size - 1 // Don't count the sentinel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) DebugPrint() {
|
func (ts *TripleStore) DebugPrint() {
|
||||||
for i, t := range ts.triples {
|
for i, t := range ts.triples {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
continue
|
continue
|
||||||
|
|
@ -241,28 +241,28 @@ func (ts *MemTripleStore) DebugPrint() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetIdFor(name string) graph.TSVal {
|
func (ts *TripleStore) GetIdFor(name string) graph.TSVal {
|
||||||
return ts.idMap[name]
|
return ts.idMap[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetNameFor(id graph.TSVal) string {
|
func (ts *TripleStore) GetNameFor(id graph.TSVal) string {
|
||||||
return ts.revIdMap[id.(int64)]
|
return ts.revIdMap[id.(int64)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||||
return graph.NewInt64AllIterator(0, ts.Size())
|
return graph.NewInt64AllIterator(0, ts.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) MakeFixed() *graph.FixedIterator {
|
func (ts *TripleStore) MakeFixed() *graph.FixedIterator {
|
||||||
return graph.NewFixedIteratorWithCompare(graph.BasicEquality)
|
return graph.NewFixedIteratorWithCompare(graph.BasicEquality)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
func (ts *TripleStore) GetTripleDirection(val graph.TSVal, direction string) graph.TSVal {
|
||||||
name := ts.GetTriple(val).Get(direction)
|
name := ts.GetTriple(val).Get(direction)
|
||||||
return ts.GetIdFor(name)
|
return ts.GetIdFor(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||||
return NewMemstoreAllIterator(ts)
|
return NewMemstoreAllIterator(ts)
|
||||||
}
|
}
|
||||||
func (ts *MemTripleStore) Close() {}
|
func (ts *TripleStore) Close() {}
|
||||||
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ts *MemTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||||
switch it.Type() {
|
switch it.Type() {
|
||||||
case "linksto":
|
case "linksto":
|
||||||
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
||||||
|
|
@ -27,7 +27,7 @@ func (ts *MemTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, b
|
||||||
return it, false
|
return it, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MemTripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||||
l := it.GetSubIterators()
|
l := it.GetSubIterators()
|
||||||
if l.Len() != 1 {
|
if l.Len() != 1 {
|
||||||
return it, false
|
return it, false
|
||||||
|
|
@ -107,7 +107,7 @@ func TestLinksToOptimization(t *testing.T) {
|
||||||
if newIt.Type() != "llrb" {
|
if newIt.Type() != "llrb" {
|
||||||
t.Fatal("Didn't swap out to LLRB")
|
t.Fatal("Didn't swap out to LLRB")
|
||||||
}
|
}
|
||||||
v := newIt.(*LlrbIterator)
|
v := newIt.(*Iterator)
|
||||||
v_clone := v.Clone()
|
v_clone := v.Clone()
|
||||||
if v_clone.DebugString(0) != v.DebugString(0) {
|
if v_clone.DebugString(0) != v.DebugString(0) {
|
||||||
t.Fatal("Wrong iterator. Got ", v_clone.DebugString(0))
|
t.Fatal("Wrong iterator. Got ", v_clone.DebugString(0))
|
||||||
|
|
@ -25,9 +25,9 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MongoIterator struct {
|
type Iterator struct {
|
||||||
graph.BaseIterator
|
graph.BaseIterator
|
||||||
ts *MongoTripleStore
|
ts *TripleStore
|
||||||
dir string
|
dir string
|
||||||
iter *mgo.Iter
|
iter *mgo.Iter
|
||||||
hash string
|
hash string
|
||||||
|
|
@ -38,8 +38,8 @@ type MongoIterator struct {
|
||||||
collection string
|
collection string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMongoIterator(ts *MongoTripleStore, collection string, dir string, val graph.TSVal) *MongoIterator {
|
func NewMongoIterator(ts *TripleStore, collection string, dir string, val graph.TSVal) *Iterator {
|
||||||
var m MongoIterator
|
var m Iterator
|
||||||
graph.BaseIteratorInit(&m.BaseIterator)
|
graph.BaseIteratorInit(&m.BaseIterator)
|
||||||
|
|
||||||
m.name = ts.GetNameFor(val)
|
m.name = ts.GetNameFor(val)
|
||||||
|
|
@ -70,8 +70,8 @@ func NewMongoIterator(ts *MongoTripleStore, collection string, dir string, val g
|
||||||
return &m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMongoAllIterator(ts *MongoTripleStore, collection string) *MongoIterator {
|
func NewMongoAllIterator(ts *TripleStore, collection string) *Iterator {
|
||||||
var m MongoIterator
|
var m Iterator
|
||||||
m.ts = ts
|
m.ts = ts
|
||||||
m.dir = "all"
|
m.dir = "all"
|
||||||
m.constraint = nil
|
m.constraint = nil
|
||||||
|
|
@ -88,17 +88,17 @@ func NewMongoAllIterator(ts *MongoTripleStore, collection string) *MongoIterator
|
||||||
return &m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Reset() {
|
func (m *Iterator) Reset() {
|
||||||
m.iter.Close()
|
m.iter.Close()
|
||||||
m.iter = m.ts.db.C(m.collection).Find(m.constraint).Iter()
|
m.iter = m.ts.db.C(m.collection).Find(m.constraint).Iter()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Close() {
|
func (m *Iterator) Close() {
|
||||||
m.iter.Close()
|
m.iter.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Clone() graph.Iterator {
|
func (m *Iterator) Clone() graph.Iterator {
|
||||||
var newM graph.Iterator
|
var newM graph.Iterator
|
||||||
if m.isAll {
|
if m.isAll {
|
||||||
newM = NewMongoAllIterator(m.ts, m.collection)
|
newM = NewMongoAllIterator(m.ts, m.collection)
|
||||||
|
|
@ -109,7 +109,7 @@ func (m *MongoIterator) Clone() graph.Iterator {
|
||||||
return newM
|
return newM
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Next() (graph.TSVal, bool) {
|
func (m *Iterator) Next() (graph.TSVal, bool) {
|
||||||
var result struct {
|
var result struct {
|
||||||
Id string "_id"
|
Id string "_id"
|
||||||
//Sub string "Sub"
|
//Sub string "Sub"
|
||||||
|
|
@ -120,7 +120,7 @@ func (m *MongoIterator) Next() (graph.TSVal, bool) {
|
||||||
if !found {
|
if !found {
|
||||||
err := m.iter.Err()
|
err := m.iter.Err()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorln("Error Nexting MongoIterator: ", err)
|
glog.Errorln("Error Nexting Iterator: ", err)
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ func (m *MongoIterator) Next() (graph.TSVal, bool) {
|
||||||
return result.Id, true
|
return result.Id, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Check(v graph.TSVal) bool {
|
func (m *Iterator) Check(v graph.TSVal) bool {
|
||||||
graph.CheckLogIn(m, v)
|
graph.CheckLogIn(m, v)
|
||||||
if m.isAll {
|
if m.isAll {
|
||||||
m.Last = v
|
m.Last = v
|
||||||
|
|
@ -153,25 +153,25 @@ func (m *MongoIterator) Check(v graph.TSVal) bool {
|
||||||
return graph.CheckLogOut(m, v, false)
|
return graph.CheckLogOut(m, v, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Size() (int64, bool) {
|
func (m *Iterator) Size() (int64, bool) {
|
||||||
return m.size, true
|
return m.size, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) Type() string {
|
func (m *Iterator) Type() string {
|
||||||
if m.isAll {
|
if m.isAll {
|
||||||
return "all"
|
return "all"
|
||||||
}
|
}
|
||||||
return "mongo"
|
return "mongo"
|
||||||
}
|
}
|
||||||
func (m *MongoIterator) Sorted() bool { return true }
|
func (m *Iterator) Sorted() bool { return true }
|
||||||
func (m *MongoIterator) Optimize() (graph.Iterator, bool) { return m, false }
|
func (m *Iterator) Optimize() (graph.Iterator, bool) { return m, false }
|
||||||
|
|
||||||
func (m *MongoIterator) DebugString(indent int) string {
|
func (m *Iterator) DebugString(indent int) string {
|
||||||
size, _ := m.Size()
|
size, _ := m.Size()
|
||||||
return fmt.Sprintf("%s(%s size:%d %s %s)", strings.Repeat(" ", indent), m.Type(), size, m.hash, m.name)
|
return fmt.Sprintf("%s(%s size:%d %s %s)", strings.Repeat(" ", indent), m.Type(), size, m.hash, m.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MongoIterator) GetStats() *graph.IteratorStats {
|
func (m *Iterator) GetStats() *graph.IteratorStats {
|
||||||
size, _ := m.Size()
|
size, _ := m.Size()
|
||||||
return &graph.IteratorStats{
|
return &graph.IteratorStats{
|
||||||
CheckCost: 1,
|
CheckCost: 1,
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
const DefaultDBName = "cayley"
|
const DefaultDBName = "cayley"
|
||||||
|
|
||||||
type MongoTripleStore struct {
|
type TripleStore struct {
|
||||||
session *mgo.Session
|
session *mgo.Session
|
||||||
db *mgo.Database
|
db *mgo.Database
|
||||||
hasher hash.Hash
|
hasher hash.Hash
|
||||||
|
|
@ -65,8 +65,8 @@ func CreateNewMongoGraph(addr string, options graph.OptionsDict) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMongoTripleStore(addr string, options graph.OptionsDict) *MongoTripleStore {
|
func NewTripleStore(addr string, options graph.OptionsDict) *TripleStore {
|
||||||
var ts MongoTripleStore
|
var ts TripleStore
|
||||||
conn, err := mgo.Dial(addr)
|
conn, err := mgo.Dial(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal("Error connecting: ", err)
|
glog.Fatal("Error connecting: ", err)
|
||||||
|
|
@ -83,7 +83,7 @@ func NewMongoTripleStore(addr string, options graph.OptionsDict) *MongoTripleSto
|
||||||
return &ts
|
return &ts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) getIdForTriple(t *graph.Triple) string {
|
func (ts *TripleStore) getIdForTriple(t *graph.Triple) string {
|
||||||
id := ts.ConvertStringToByteHash(t.Sub)
|
id := ts.ConvertStringToByteHash(t.Sub)
|
||||||
id += ts.ConvertStringToByteHash(t.Pred)
|
id += ts.ConvertStringToByteHash(t.Pred)
|
||||||
id += ts.ConvertStringToByteHash(t.Obj)
|
id += ts.ConvertStringToByteHash(t.Obj)
|
||||||
|
|
@ -91,7 +91,7 @@ func (ts *MongoTripleStore) getIdForTriple(t *graph.Triple) string {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) ConvertStringToByteHash(s string) string {
|
func (ts *TripleStore) ConvertStringToByteHash(s string) string {
|
||||||
ts.hasher.Reset()
|
ts.hasher.Reset()
|
||||||
key := make([]byte, 0, ts.hasher.Size())
|
key := make([]byte, 0, ts.hasher.Size())
|
||||||
ts.hasher.Write([]byte(s))
|
ts.hasher.Write([]byte(s))
|
||||||
|
|
@ -105,7 +105,7 @@ type MongoNode struct {
|
||||||
Size int "Size"
|
Size int "Size"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) updateNodeBy(node_name string, inc int) {
|
func (ts *TripleStore) updateNodeBy(node_name string, inc int) {
|
||||||
var size MongoNode
|
var size MongoNode
|
||||||
node := ts.GetIdFor(node_name)
|
node := ts.GetIdFor(node_name)
|
||||||
err := ts.db.C("nodes").FindId(node).One(&size)
|
err := ts.db.C("nodes").FindId(node).One(&size)
|
||||||
|
|
@ -142,7 +142,7 @@ func (ts *MongoTripleStore) updateNodeBy(node_name string, inc int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) writeTriple(t *graph.Triple) bool {
|
func (ts *TripleStore) writeTriple(t *graph.Triple) bool {
|
||||||
tripledoc := bson.M{"_id": ts.getIdForTriple(t), "Sub": t.Sub, "Pred": t.Pred, "Obj": t.Obj, "Provenance": t.Provenance}
|
tripledoc := bson.M{"_id": ts.getIdForTriple(t), "Sub": t.Sub, "Pred": t.Pred, "Obj": t.Obj, "Provenance": t.Provenance}
|
||||||
err := ts.db.C("triples").Insert(tripledoc)
|
err := ts.db.C("triples").Insert(tripledoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -156,7 +156,7 @@ func (ts *MongoTripleStore) writeTriple(t *graph.Triple) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) AddTriple(t *graph.Triple) {
|
func (ts *TripleStore) AddTriple(t *graph.Triple) {
|
||||||
_ = ts.writeTriple(t)
|
_ = ts.writeTriple(t)
|
||||||
ts.updateNodeBy(t.Sub, 1)
|
ts.updateNodeBy(t.Sub, 1)
|
||||||
ts.updateNodeBy(t.Pred, 1)
|
ts.updateNodeBy(t.Pred, 1)
|
||||||
|
|
@ -166,7 +166,7 @@ func (ts *MongoTripleStore) AddTriple(t *graph.Triple) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) AddTripleSet(in []*graph.Triple) {
|
func (ts *TripleStore) AddTripleSet(in []*graph.Triple) {
|
||||||
ts.session.SetSafe(nil)
|
ts.session.SetSafe(nil)
|
||||||
idMap := make(map[string]int)
|
idMap := make(map[string]int)
|
||||||
for _, t := range in {
|
for _, t := range in {
|
||||||
|
|
@ -186,7 +186,7 @@ func (ts *MongoTripleStore) AddTripleSet(in []*graph.Triple) {
|
||||||
ts.session.SetSafe(&mgo.Safe{})
|
ts.session.SetSafe(&mgo.Safe{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) RemoveTriple(t *graph.Triple) {
|
func (ts *TripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
err := ts.db.C("triples").RemoveId(ts.getIdForTriple(t))
|
err := ts.db.C("triples").RemoveId(ts.getIdForTriple(t))
|
||||||
if err == mgo.ErrNotFound {
|
if err == mgo.ErrNotFound {
|
||||||
return
|
return
|
||||||
|
|
@ -202,7 +202,7 @@ func (ts *MongoTripleStore) RemoveTriple(t *graph.Triple) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
func (ts *TripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
||||||
var bsonDoc bson.M
|
var bsonDoc bson.M
|
||||||
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
err := ts.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -215,23 +215,23 @@ func (ts *MongoTripleStore) GetTriple(val graph.TSVal) *graph.Triple {
|
||||||
bsonDoc["Provenance"].(string))
|
bsonDoc["Provenance"].(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
func (ts *TripleStore) GetTripleIterator(dir string, val graph.TSVal) graph.Iterator {
|
||||||
return NewMongoIterator(ts, "triples", dir, val)
|
return NewMongoIterator(ts, "triples", dir, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetNodesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetNodesAllIterator() graph.Iterator {
|
||||||
return NewMongoAllIterator(ts, "nodes")
|
return NewMongoAllIterator(ts, "nodes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetTriplesAllIterator() graph.Iterator {
|
func (ts *TripleStore) GetTriplesAllIterator() graph.Iterator {
|
||||||
return NewMongoAllIterator(ts, "triples")
|
return NewMongoAllIterator(ts, "triples")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetIdFor(s string) graph.TSVal {
|
func (ts *TripleStore) GetIdFor(s string) graph.TSVal {
|
||||||
return ts.ConvertStringToByteHash(s)
|
return ts.ConvertStringToByteHash(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetNameFor(v graph.TSVal) string {
|
func (ts *TripleStore) GetNameFor(v graph.TSVal) string {
|
||||||
val, ok := ts.idCache.Get(v.(string))
|
val, ok := ts.idCache.Get(v.(string))
|
||||||
if ok {
|
if ok {
|
||||||
return val
|
return val
|
||||||
|
|
@ -245,7 +245,7 @@ func (ts *MongoTripleStore) GetNameFor(v graph.TSVal) string {
|
||||||
return node.Name
|
return node.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) Size() int64 {
|
func (ts *TripleStore) Size() int64 {
|
||||||
count, err := ts.db.C("triples").Count()
|
count, err := ts.db.C("triples").Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("Error: ", err)
|
glog.Error("Error: ", err)
|
||||||
|
|
@ -258,15 +258,15 @@ func compareStrings(a, b graph.TSVal) bool {
|
||||||
return a.(string) == b.(string)
|
return a.(string) == b.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) MakeFixed() *graph.FixedIterator {
|
func (ts *TripleStore) MakeFixed() *graph.FixedIterator {
|
||||||
return graph.NewFixedIteratorWithCompare(compareStrings)
|
return graph.NewFixedIteratorWithCompare(compareStrings)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) Close() {
|
func (ts *TripleStore) Close() {
|
||||||
ts.db.Session.Close()
|
ts.db.Session.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) GetTripleDirection(in graph.TSVal, dir string) graph.TSVal {
|
func (ts *TripleStore) GetTripleDirection(in graph.TSVal, dir string) graph.TSVal {
|
||||||
// Maybe do the trick here
|
// Maybe do the trick here
|
||||||
var offset int
|
var offset int
|
||||||
switch dir {
|
switch dir {
|
||||||
|
|
@ -283,7 +283,7 @@ func (ts *MongoTripleStore) GetTripleDirection(in graph.TSVal, dir string) graph
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) BulkLoad(t_chan chan *graph.Triple) {
|
func (ts *TripleStore) BulkLoad(t_chan chan *graph.Triple) {
|
||||||
ts.session.SetSafe(nil)
|
ts.session.SetSafe(nil)
|
||||||
for triple := range t_chan {
|
for triple := range t_chan {
|
||||||
ts.writeTriple(triple)
|
ts.writeTriple(triple)
|
||||||
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {
|
||||||
switch it.Type() {
|
switch it.Type() {
|
||||||
case "linksto":
|
case "linksto":
|
||||||
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
return ts.optimizeLinksTo(it.(*graph.LinksToIterator))
|
||||||
|
|
@ -27,7 +27,7 @@ func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator,
|
||||||
return it, false
|
return it, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *MongoTripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
func (ts *TripleStore) optimizeLinksTo(it *graph.LinksToIterator) (graph.Iterator, bool) {
|
||||||
l := it.GetSubIterators()
|
l := it.GetSubIterators()
|
||||||
if l.Len() != 1 {
|
if l.Len() != 1 {
|
||||||
return it, false
|
return it, false
|
||||||
|
|
@ -32,7 +32,7 @@ func TestBadParse(t *testing.T) {
|
||||||
|
|
||||||
func TestParseSexpWithMemstore(t *testing.T) {
|
func TestParseSexpWithMemstore(t *testing.T) {
|
||||||
Convey("With a Memstore", t, func() {
|
Convey("With a Memstore", t, func() {
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
|
|
||||||
Convey("It should parse an empty query", func() {
|
Convey("It should parse an empty query", func() {
|
||||||
it := BuildIteratorTreeForQuery(ts, "()")
|
it := BuildIteratorTreeForQuery(ts, "()")
|
||||||
|
|
@ -64,7 +64,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeConstraintParse(t *testing.T) {
|
func TestTreeConstraintParse(t *testing.T) {
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
|
ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
|
||||||
query := "(\"i\"\n" +
|
query := "(\"i\"\n" +
|
||||||
|
|
@ -84,7 +84,7 @@ func TestTreeConstraintParse(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeConstraintTagParse(t *testing.T) {
|
func TestTreeConstraintTagParse(t *testing.T) {
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
|
ts.AddTriple(graph.MakeTriple("food", "is", "good", ""))
|
||||||
query := "(\"i\"\n" +
|
query := "(\"i\"\n" +
|
||||||
|
|
@ -104,7 +104,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultipleConstraintParse(t *testing.T) {
|
func TestMultipleConstraintParse(t *testing.T) {
|
||||||
ts := memstore.NewMemTripleStore()
|
ts := memstore.NewTripleStore()
|
||||||
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
ts.AddTriple(graph.MakeTriple("i", "like", "food", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("i", "like", "beer", ""))
|
ts.AddTriple(graph.MakeTriple("i", "like", "beer", ""))
|
||||||
ts.AddTriple(graph.MakeTriple("you", "like", "beer", ""))
|
ts.AddTriple(graph.MakeTriple("you", "like", "beer", ""))
|
||||||
|
|
|
||||||
|
|
@ -24,22 +24,22 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SexpSession struct {
|
type Session struct {
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSexpSession(inputTripleStore graph.TripleStore) *SexpSession {
|
func NewSession(inputTripleStore graph.TripleStore) *Session {
|
||||||
var s SexpSession
|
var s Session
|
||||||
s.ts = inputTripleStore
|
s.ts = inputTripleStore
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SexpSession) ToggleDebug() {
|
func (s *Session) ToggleDebug() {
|
||||||
s.debug = !s.debug
|
s.debug = !s.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SexpSession) InputParses(input string) (graph.ParseResult, error) {
|
func (s *Session) InputParses(input string) (graph.ParseResult, error) {
|
||||||
var parenDepth int
|
var parenDepth int
|
||||||
for i, x := range input {
|
for i, x := range input {
|
||||||
if x == '(' {
|
if x == '(' {
|
||||||
|
|
@ -65,7 +65,7 @@ func (s *SexpSession) InputParses(input string) (graph.ParseResult, error) {
|
||||||
return graph.ParseFail, errors.New("Invalid Syntax")
|
return graph.ParseFail, errors.New("Invalid Syntax")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SexpSession) ExecInput(input string, out chan interface{}, limit int) {
|
func (s *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
it := BuildIteratorTreeForQuery(s.ts, input)
|
it := BuildIteratorTreeForQuery(s.ts, input)
|
||||||
newIt, changed := it.Optimize()
|
newIt, changed := it.Optimize()
|
||||||
if changed {
|
if changed {
|
||||||
|
|
@ -101,7 +101,7 @@ func (s *SexpSession) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
close(out)
|
close(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SexpSession) ToText(result interface{}) string {
|
func (s *Session) ToText(result interface{}) string {
|
||||||
out := fmt.Sprintln("****")
|
out := fmt.Sprintln("****")
|
||||||
tags := result.(*map[string]graph.TSVal)
|
tags := result.(*map[string]graph.TSVal)
|
||||||
tagKeys := make([]string, len(*tags))
|
tagKeys := make([]string, len(*tags))
|
||||||
|
|
@ -106,7 +106,7 @@ func (h *TemplateRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
config *config.CayleyConfig
|
config *config.Config
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ func (api *Api) ApiV1(r *httprouter.Router) {
|
||||||
r.POST("/api/v1/delete", LogRequest(api.ServeV1Delete))
|
r.POST("/api/v1/delete", LogRequest(api.ServeV1Delete))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
|
func SetupRoutes(ts graph.TripleStore, cfg *config.Config) {
|
||||||
r := httprouter.New()
|
r := httprouter.New()
|
||||||
assets := findAssetsPath()
|
assets := findAssetsPath()
|
||||||
if glog.V(2) {
|
if glog.V(2) {
|
||||||
|
|
@ -141,7 +141,7 @@ func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CayleyHTTP(ts graph.TripleStore, cfg *config.CayleyConfig) {
|
func Serve(ts graph.TripleStore, cfg *config.Config) {
|
||||||
SetupRoutes(ts, cfg)
|
SetupRoutes(ts, cfg)
|
||||||
glog.Infof("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
|
glog.Infof("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
|
||||||
fmt.Printf("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
|
fmt.Printf("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
|
||||||
|
|
@ -71,9 +71,9 @@ func (api *Api) ServeV1Query(w http.ResponseWriter, r *http.Request, params http
|
||||||
var ses graph.HttpSession
|
var ses graph.HttpSession
|
||||||
switch params.ByName("query_lang") {
|
switch params.ByName("query_lang") {
|
||||||
case "gremlin":
|
case "gremlin":
|
||||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false)
|
ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false)
|
||||||
case "mql":
|
case "mql":
|
||||||
ses = mql.NewMqlSession(api.ts)
|
ses = mql.NewSession(api.ts)
|
||||||
default:
|
default:
|
||||||
return FormatJson400(w, "Need a query language.")
|
return FormatJson400(w, "Need a query language.")
|
||||||
}
|
}
|
||||||
|
|
@ -120,9 +120,9 @@ func (api *Api) ServeV1Shape(w http.ResponseWriter, r *http.Request, params http
|
||||||
var ses graph.HttpSession
|
var ses graph.HttpSession
|
||||||
switch params.ByName("query_lang") {
|
switch params.ByName("query_lang") {
|
||||||
case "gremlin":
|
case "gremlin":
|
||||||
ses = gremlin.NewGremlinSession(api.ts, api.config.GremlinTimeout, false)
|
ses = gremlin.NewSession(api.ts, api.config.GremlinTimeout, false)
|
||||||
case "mql":
|
case "mql":
|
||||||
ses = mql.NewMqlSession(api.ts)
|
ses = mql.NewSession(api.ts)
|
||||||
default:
|
default:
|
||||||
return FormatJson400(w, "Need a query language.")
|
return FormatJson400(w, "Need a query language.")
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
func isWhitespace(s uint8) bool {
|
func isWhitespace(s uint8) bool {
|
||||||
return (s == '\t' || s == '\r' || s == ' ')
|
return (s == '\t' || s == '\r' || s == ' ')
|
||||||
}
|
}
|
||||||
func ParseLineToTriple(str string) *graph.Triple {
|
func Parse(str string) *graph.Triple {
|
||||||
// Skip leading whitespace.
|
// Skip leading whitespace.
|
||||||
str = skipWhitespace(str)
|
str = skipWhitespace(str)
|
||||||
// Check for a comment
|
// Check for a comment
|
||||||
|
|
@ -184,7 +184,7 @@ func ReadNQuadsFromReader(c chan *graph.Triple, reader io.Reader) {
|
||||||
if pre {
|
if pre {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
triple := ParseLineToTriple(line)
|
triple := Parse(line)
|
||||||
line = ""
|
line = ""
|
||||||
if triple != nil {
|
if triple != nil {
|
||||||
nTriples++
|
nTriples++
|
||||||
|
|
|
||||||
|
|
@ -25,61 +25,61 @@ import (
|
||||||
func TestParsingNTriples(t *testing.T) {
|
func TestParsingNTriples(t *testing.T) {
|
||||||
Convey("When parsing", t, func() {
|
Convey("When parsing", t, func() {
|
||||||
Convey("It should not parse invalid triples", func() {
|
Convey("It should not parse invalid triples", func() {
|
||||||
x := ParseLineToTriple("invalid")
|
x := Parse("invalid")
|
||||||
So(x, ShouldBeNil)
|
So(x, ShouldBeNil)
|
||||||
})
|
})
|
||||||
Convey("It should not parse comments", func() {
|
Convey("It should not parse comments", func() {
|
||||||
x := ParseLineToTriple("# nominally valid triple .")
|
x := Parse("# nominally valid triple .")
|
||||||
So(x, ShouldBeNil)
|
So(x, ShouldBeNil)
|
||||||
})
|
})
|
||||||
Convey("It should parse simple triples", func() {
|
Convey("It should parse simple triples", func() {
|
||||||
x := ParseLineToTriple("this is valid .")
|
x := Parse("this is valid .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Sub, ShouldEqual, "this")
|
So(x.Sub, ShouldEqual, "this")
|
||||||
})
|
})
|
||||||
Convey("It should parse quoted triples", func() {
|
Convey("It should parse quoted triples", func() {
|
||||||
x := ParseLineToTriple("this is \"valid too\" .")
|
x := Parse("this is \"valid too\" .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "valid too")
|
So(x.Obj, ShouldEqual, "valid too")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
Convey("It should parse escaped quoted triples", func() {
|
Convey("It should parse escaped quoted triples", func() {
|
||||||
x := ParseLineToTriple("he said \"\\\"That's all folks\\\"\" .")
|
x := Parse("he said \"\\\"That's all folks\\\"\" .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "\"That's all folks\"")
|
So(x.Obj, ShouldEqual, "\"That's all folks\"")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should parse an example real triple", func() {
|
Convey("It should parse an example real triple", func() {
|
||||||
x := ParseLineToTriple("\":/guid/9202a8c04000641f80000000010c843c\" \"name\" \"George Morris\" .")
|
x := Parse("\":/guid/9202a8c04000641f80000000010c843c\" \"name\" \"George Morris\" .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "George Morris")
|
So(x.Obj, ShouldEqual, "George Morris")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should parse a pathologically spaced triple", func() {
|
Convey("It should parse a pathologically spaced triple", func() {
|
||||||
x := ParseLineToTriple("foo is \"\\tA big tough\\r\\nDeal\\\\\" .")
|
x := Parse("foo is \"\\tA big tough\\r\\nDeal\\\\\" .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "\tA big tough\r\nDeal\\")
|
So(x.Obj, ShouldEqual, "\tA big tough\r\nDeal\\")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should parse a simple quad", func() {
|
Convey("It should parse a simple quad", func() {
|
||||||
x := ParseLineToTriple("this is valid quad .")
|
x := Parse("this is valid quad .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "valid")
|
So(x.Obj, ShouldEqual, "valid")
|
||||||
So(x.Provenance, ShouldEqual, "quad")
|
So(x.Provenance, ShouldEqual, "quad")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should parse a quoted quad", func() {
|
Convey("It should parse a quoted quad", func() {
|
||||||
x := ParseLineToTriple("this is valid \"quad thing\" .")
|
x := Parse("this is valid \"quad thing\" .")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "valid")
|
So(x.Obj, ShouldEqual, "valid")
|
||||||
So(x.Provenance, ShouldEqual, "quad thing")
|
So(x.Provenance, ShouldEqual, "quad thing")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("It should parse crazy escaped quads", func() {
|
Convey("It should parse crazy escaped quads", func() {
|
||||||
x := ParseLineToTriple("\"\\\"this\" \"\\\"is\" \"\\\"valid\" \"\\\"quad thing\".")
|
x := Parse("\"\\\"this\" \"\\\"is\" \"\\\"valid\" \"\\\"quad thing\".")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Sub, ShouldEqual, "\"this")
|
So(x.Sub, ShouldEqual, "\"this")
|
||||||
So(x.Pred, ShouldEqual, "\"is")
|
So(x.Pred, ShouldEqual, "\"is")
|
||||||
|
|
@ -93,27 +93,27 @@ func TestParsingNTriplesOfficial(t *testing.T) {
|
||||||
Convey("When using some public test cases...", t, func() {
|
Convey("When using some public test cases...", t, func() {
|
||||||
Convey("It should handle some simple cases with comments", func() {
|
Convey("It should handle some simple cases with comments", func() {
|
||||||
var x *graph.Triple
|
var x *graph.Triple
|
||||||
x = ParseLineToTriple("<http://example/s> <http://example/p> <http://example/o> . # comment")
|
x = Parse("<http://example/s> <http://example/p> <http://example/o> . # comment")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Sub, ShouldEqual, "http://example/s")
|
So(x.Sub, ShouldEqual, "http://example/s")
|
||||||
So(x.Pred, ShouldEqual, "http://example/p")
|
So(x.Pred, ShouldEqual, "http://example/p")
|
||||||
So(x.Obj, ShouldEqual, "http://example/o")
|
So(x.Obj, ShouldEqual, "http://example/o")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
x = ParseLineToTriple("<http://example/s> <http://example/p> _:o . # comment")
|
x = Parse("<http://example/s> <http://example/p> _:o . # comment")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Sub, ShouldEqual, "http://example/s")
|
So(x.Sub, ShouldEqual, "http://example/s")
|
||||||
So(x.Pred, ShouldEqual, "http://example/p")
|
So(x.Pred, ShouldEqual, "http://example/p")
|
||||||
So(x.Obj, ShouldEqual, "_:o")
|
So(x.Obj, ShouldEqual, "_:o")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
x = ParseLineToTriple("<http://example/s> <http://example/p> \"o\" . # comment")
|
x = Parse("<http://example/s> <http://example/p> \"o\" . # comment")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "o")
|
So(x.Obj, ShouldEqual, "o")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
x = ParseLineToTriple("<http://example/s> <http://example/p> \"o\"^^<http://example/dt> . # comment")
|
x = Parse("<http://example/s> <http://example/p> \"o\"^^<http://example/dt> . # comment")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "o")
|
So(x.Obj, ShouldEqual, "o")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
x = ParseLineToTriple("<http://example/s> <http://example/p> \"o\"@en . # comment")
|
x = Parse("<http://example/s> <http://example/p> \"o\"@en . # comment")
|
||||||
So(x, ShouldNotBeNil)
|
So(x, ShouldNotBeNil)
|
||||||
So(x.Obj, ShouldEqual, "o")
|
So(x.Obj, ShouldEqual, "o")
|
||||||
So(x.Provenance, ShouldEqual, "")
|
So(x.Provenance, ShouldEqual, "")
|
||||||
|
|
@ -123,7 +123,7 @@ func TestParsingNTriplesOfficial(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkParser(b *testing.B) {
|
func BenchmarkParser(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
x := ParseLineToTriple("<http://example/s> <http://example/p> \"object of some real\\tlength\"@en . # comment")
|
x := Parse("<http://example/s> <http://example/p> \"object of some real\\tlength\"@en . # comment")
|
||||||
if x.Obj != "object of some real\tlength" {
|
if x.Obj != "object of some real\tlength" {
|
||||||
b.Fail()
|
b.Fail()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildGremlinEnv(ses *GremlinSession) *otto.Otto {
|
func BuildEnviron(ses *Session) *otto.Otto {
|
||||||
env := otto.New()
|
env := otto.New()
|
||||||
setupGremlin(env, ses)
|
setupGremlin(env, ses)
|
||||||
return env
|
return env
|
||||||
|
|
@ -55,7 +55,7 @@ func isVertexChain(obj *otto.Object) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupGremlin(env *otto.Otto, ses *GremlinSession) {
|
func setupGremlin(env *otto.Otto, ses *Session) {
|
||||||
graph, _ := env.Object("graph = {}")
|
graph, _ := env.Object("graph = {}")
|
||||||
graph.Set("Vertex", func(call otto.FunctionCall) otto.Value {
|
graph.Set("Vertex", func(call otto.FunctionCall) otto.Value {
|
||||||
call.Otto.Run("var out = {}")
|
call.Otto.Run("var out = {}")
|
||||||
|
|
@ -21,9 +21,9 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
const GremlinTopResultTag = "id"
|
const TopResultTag = "id"
|
||||||
|
|
||||||
func embedFinals(env *otto.Otto, ses *GremlinSession, obj *otto.Object) {
|
func embedFinals(env *otto.Otto, ses *Session, obj *otto.Object) {
|
||||||
obj.Set("All", allFunc(env, ses, obj))
|
obj.Set("All", allFunc(env, ses, obj))
|
||||||
obj.Set("GetLimit", limitFunc(env, ses, obj))
|
obj.Set("GetLimit", limitFunc(env, ses, obj))
|
||||||
obj.Set("ToArray", toArrayFunc(env, ses, obj, false))
|
obj.Set("ToArray", toArrayFunc(env, ses, obj, false))
|
||||||
|
|
@ -34,10 +34,10 @@ func embedFinals(env *otto.Otto, ses *GremlinSession, obj *otto.Object) {
|
||||||
obj.Set("ForEach", mapFunc(env, ses, obj))
|
obj.Set("ForEach", mapFunc(env, ses, obj))
|
||||||
}
|
}
|
||||||
|
|
||||||
func allFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
func allFunc(env *otto.Otto, ses *Session, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
it := buildIteratorTree(obj, ses.ts)
|
it := buildIteratorTree(obj, ses.ts)
|
||||||
it.AddTag(GremlinTopResultTag)
|
it.AddTag(TopResultTag)
|
||||||
ses.limit = -1
|
ses.limit = -1
|
||||||
ses.count = 0
|
ses.count = 0
|
||||||
runIteratorOnSession(it, ses)
|
runIteratorOnSession(it, ses)
|
||||||
|
|
@ -45,12 +45,12 @@ func allFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.Fu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func limitFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
func limitFunc(env *otto.Otto, ses *Session, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
if len(call.ArgumentList) > 0 {
|
if len(call.ArgumentList) > 0 {
|
||||||
limitVal, _ := call.Argument(0).ToInteger()
|
limitVal, _ := call.Argument(0).ToInteger()
|
||||||
it := buildIteratorTree(obj, ses.ts)
|
it := buildIteratorTree(obj, ses.ts)
|
||||||
it.AddTag(GremlinTopResultTag)
|
it.AddTag(TopResultTag)
|
||||||
ses.limit = int(limitVal)
|
ses.limit = int(limitVal)
|
||||||
ses.count = 0
|
ses.count = 0
|
||||||
runIteratorOnSession(it, ses)
|
runIteratorOnSession(it, ses)
|
||||||
|
|
@ -59,10 +59,10 @@ func limitFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toArrayFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
|
func toArrayFunc(env *otto.Otto, ses *Session, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
it := buildIteratorTree(obj, ses.ts)
|
it := buildIteratorTree(obj, ses.ts)
|
||||||
it.AddTag(GremlinTopResultTag)
|
it.AddTag(TopResultTag)
|
||||||
limit := -1
|
limit := -1
|
||||||
if len(call.ArgumentList) > 0 {
|
if len(call.ArgumentList) > 0 {
|
||||||
limitParsed, _ := call.Argument(0).ToInteger()
|
limitParsed, _ := call.Argument(0).ToInteger()
|
||||||
|
|
@ -86,10 +86,10 @@ func toArrayFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object, withTags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toValueFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
|
func toValueFunc(env *otto.Otto, ses *Session, obj *otto.Object, withTags bool) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
it := buildIteratorTree(obj, ses.ts)
|
it := buildIteratorTree(obj, ses.ts)
|
||||||
it.AddTag(GremlinTopResultTag)
|
it.AddTag(TopResultTag)
|
||||||
limit := 1
|
limit := 1
|
||||||
var val otto.Value
|
var val otto.Value
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -116,10 +116,10 @@ func toValueFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object, withTags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
func mapFunc(env *otto.Otto, ses *Session, obj *otto.Object) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
it := buildIteratorTree(obj, ses.ts)
|
it := buildIteratorTree(obj, ses.ts)
|
||||||
it.AddTag(GremlinTopResultTag)
|
it.AddTag(TopResultTag)
|
||||||
limit := -1
|
limit := -1
|
||||||
if len(call.ArgumentList) == 0 {
|
if len(call.ArgumentList) == 0 {
|
||||||
return otto.NullValue()
|
return otto.NullValue()
|
||||||
|
|
@ -134,7 +134,7 @@ func mapFunc(env *otto.Otto, ses *GremlinSession, obj *otto.Object) func(otto.Fu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tagsToValueMap(m map[string]graph.TSVal, ses *GremlinSession) map[string]string {
|
func tagsToValueMap(m map[string]graph.TSVal, ses *Session) map[string]string {
|
||||||
outputMap := make(map[string]string)
|
outputMap := make(map[string]string)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
outputMap[k] = ses.ts.GetNameFor(v)
|
outputMap[k] = ses.ts.GetNameFor(v)
|
||||||
|
|
@ -142,7 +142,7 @@ func tagsToValueMap(m map[string]graph.TSVal, ses *GremlinSession) map[string]st
|
||||||
return outputMap
|
return outputMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func runIteratorToArray(it graph.Iterator, ses *GremlinSession, limit int) []map[string]string {
|
func runIteratorToArray(it graph.Iterator, ses *Session, limit int) []map[string]string {
|
||||||
output := make([]map[string]string, 0)
|
output := make([]map[string]string, 0)
|
||||||
count := 0
|
count := 0
|
||||||
it, _ = it.Optimize()
|
it, _ = it.Optimize()
|
||||||
|
|
@ -178,7 +178,7 @@ func runIteratorToArray(it graph.Iterator, ses *GremlinSession, limit int) []map
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func runIteratorToArrayNoTags(it graph.Iterator, ses *GremlinSession, limit int) []string {
|
func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []string {
|
||||||
output := make([]string, 0)
|
output := make([]string, 0)
|
||||||
count := 0
|
count := 0
|
||||||
it, _ = it.Optimize()
|
it, _ = it.Optimize()
|
||||||
|
|
@ -200,7 +200,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *GremlinSession, limit int)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func runIteratorWithCallback(it graph.Iterator, ses *GremlinSession, callback otto.Value, this otto.FunctionCall, limit int) {
|
func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
|
||||||
count := 0
|
count := 0
|
||||||
it, _ = it.Optimize()
|
it, _ = it.Optimize()
|
||||||
for {
|
for {
|
||||||
|
|
@ -236,7 +236,7 @@ func runIteratorWithCallback(it graph.Iterator, ses *GremlinSession, callback ot
|
||||||
it.Close()
|
it.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func runIteratorOnSession(it graph.Iterator, ses *GremlinSession) {
|
func runIteratorOnSession(it graph.Iterator, ses *Session) {
|
||||||
if ses.lookingForQueryShape {
|
if ses.lookingForQueryShape {
|
||||||
graph.OutputQueryShapeForIterator(it, ses.ts, &(ses.queryShape))
|
graph.OutputQueryShapeForIterator(it, ses.ts, &(ses.queryShape))
|
||||||
return
|
return
|
||||||
|
|
@ -35,9 +35,9 @@ import (
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
|
|
||||||
func buildTripleStore() *GremlinSession {
|
func buildTripleStore() *Session {
|
||||||
ts := memstore.MakeTestingMemstore()
|
ts := memstore.MakeTestingMemstore()
|
||||||
return NewGremlinSession(ts, -1, false)
|
return NewSession(ts, -1, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldBeUnordered(actual interface{}, expected ...interface{}) string {
|
func shouldBeUnordered(actual interface{}, expected ...interface{}) string {
|
||||||
|
|
@ -71,7 +71,7 @@ func runQueryGetTag(query string, tag string) ([]string, int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConveyQuery(doc string, query string, expected []string) {
|
func ConveyQuery(doc string, query string, expected []string) {
|
||||||
ConveyQueryTag(doc, query, GremlinTopResultTag, expected)
|
ConveyQueryTag(doc, query, TopResultTag, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConveyQueryTag(doc string, query string, tag string, expected []string) {
|
func ConveyQueryTag(doc string, query string, tag string, expected []string) {
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GremlinSession struct {
|
type Session struct {
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
currentChannel chan interface{}
|
currentChannel chan interface{}
|
||||||
env *otto.Otto
|
env *otto.Otto
|
||||||
|
|
@ -42,10 +42,10 @@ type GremlinSession struct {
|
||||||
emptyEnv *otto.Otto
|
emptyEnv *otto.Otto
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGremlinSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool) *GremlinSession {
|
func NewSession(inputTripleStore graph.TripleStore, timeoutSec int, persist bool) *Session {
|
||||||
var g GremlinSession
|
var g Session
|
||||||
g.ts = inputTripleStore
|
g.ts = inputTripleStore
|
||||||
g.env = BuildGremlinEnv(&g)
|
g.env = BuildEnviron(&g)
|
||||||
g.limit = -1
|
g.limit = -1
|
||||||
g.count = 0
|
g.count = 0
|
||||||
g.lookingForQueryShape = false
|
g.lookingForQueryShape = false
|
||||||
|
|
@ -68,11 +68,11 @@ type GremlinResult struct {
|
||||||
actualResults *map[string]graph.TSVal
|
actualResults *map[string]graph.TSVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GremlinSession) ToggleDebug() {
|
func (g *Session) ToggleDebug() {
|
||||||
g.debug = !g.debug
|
g.debug = !g.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GremlinSession) GetQuery(input string, output_struct chan map[string]interface{}) {
|
func (g *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
|
||||||
defer close(output_struct)
|
defer close(output_struct)
|
||||||
g.queryShape = make(map[string]interface{})
|
g.queryShape = make(map[string]interface{})
|
||||||
g.lookingForQueryShape = true
|
g.lookingForQueryShape = true
|
||||||
|
|
@ -81,7 +81,7 @@ func (g *GremlinSession) GetQuery(input string, output_struct chan map[string]in
|
||||||
g.queryShape = nil
|
g.queryShape = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GremlinSession) InputParses(input string) (graph.ParseResult, error) {
|
func (g *Session) InputParses(input string) (graph.ParseResult, error) {
|
||||||
script, err := g.env.Compile("", input)
|
script, err := g.env.Compile("", input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return graph.ParseFail, err
|
return graph.ParseFail, err
|
||||||
|
|
@ -90,7 +90,7 @@ func (g *GremlinSession) InputParses(input string) (graph.ParseResult, error) {
|
||||||
return graph.Parsed, nil
|
return graph.Parsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GremlinSession) SendResult(result *GremlinResult) bool {
|
func (g *Session) SendResult(result *GremlinResult) bool {
|
||||||
if g.limit >= 0 && g.limit == g.count {
|
if g.limit >= 0 && g.limit == g.count {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +111,7 @@ func (g *GremlinSession) SendResult(result *GremlinResult) bool {
|
||||||
|
|
||||||
var halt = errors.New("Query Timeout")
|
var halt = errors.New("Query Timeout")
|
||||||
|
|
||||||
func (g *GremlinSession) runUnsafe(input interface{}) (otto.Value, error) {
|
func (g *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
||||||
g.doHalt = false
|
g.doHalt = false
|
||||||
defer func() {
|
defer func() {
|
||||||
if caught := recover(); caught != nil {
|
if caught := recover(); caught != nil {
|
||||||
|
|
@ -141,7 +141,7 @@ func (g *GremlinSession) runUnsafe(input interface{}) (otto.Value, error) {
|
||||||
return g.env.Run(input) // Here be dragons (risky code)
|
return g.env.Run(input) // Here be dragons (risky code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GremlinSession) ExecInput(input string, out chan interface{}, limit int) {
|
func (g *Session) ExecInput(input string, out chan interface{}, limit int) {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
g.err = nil
|
g.err = nil
|
||||||
g.currentChannel = out
|
g.currentChannel = out
|
||||||
|
|
@ -169,7 +169,7 @@ func (g *GremlinSession) ExecInput(input string, out chan interface{}, limit int
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GremlinSession) ToText(result interface{}) string {
|
func (s *Session) ToText(result interface{}) string {
|
||||||
data := result.(*GremlinResult)
|
data := result.(*GremlinResult)
|
||||||
if data.metaresult {
|
if data.metaresult {
|
||||||
if data.err != "" {
|
if data.err != "" {
|
||||||
|
|
@ -220,7 +220,7 @@ func (s *GremlinSession) ToText(result interface{}) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Web stuff
|
// Web stuff
|
||||||
func (ses *GremlinSession) BuildJson(result interface{}) {
|
func (ses *Session) BuildJson(result interface{}) {
|
||||||
data := result.(*GremlinResult)
|
data := result.(*GremlinResult)
|
||||||
if !data.metaresult {
|
if !data.metaresult {
|
||||||
if data.val == nil {
|
if data.val == nil {
|
||||||
|
|
@ -250,7 +250,7 @@ func (ses *GremlinSession) BuildJson(result interface{}) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ses *GremlinSession) GetJson() (interface{}, error) {
|
func (ses *Session) GetJson() (interface{}, error) {
|
||||||
defer ses.ClearJson()
|
defer ses.ClearJson()
|
||||||
if ses.err != nil {
|
if ses.err != nil {
|
||||||
return nil, ses.err
|
return nil, ses.err
|
||||||
|
|
@ -261,6 +261,6 @@ func (ses *GremlinSession) GetJson() (interface{}, error) {
|
||||||
return ses.dataOutput, nil
|
return ses.dataOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ses *GremlinSession) ClearJson() {
|
func (ses *Session) ClearJson() {
|
||||||
ses.dataOutput = nil
|
ses.dataOutput = nil
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func embedTraversals(env *otto.Otto, ses *GremlinSession, obj *otto.Object) {
|
func embedTraversals(env *otto.Otto, ses *Session, obj *otto.Object) {
|
||||||
obj.Set("In", gremlinFunc("in", obj, env, ses))
|
obj.Set("In", gremlinFunc("in", obj, env, ses))
|
||||||
obj.Set("Out", gremlinFunc("out", obj, env, ses))
|
obj.Set("Out", gremlinFunc("out", obj, env, ses))
|
||||||
obj.Set("Is", gremlinFunc("is", obj, env, ses))
|
obj.Set("Is", gremlinFunc("is", obj, env, ses))
|
||||||
|
|
@ -40,7 +40,7 @@ func embedTraversals(env *otto.Otto, ses *GremlinSession, obj *otto.Object) {
|
||||||
obj.Set("SaveR", gremlinFunc("saver", obj, env, ses))
|
obj.Set("SaveR", gremlinFunc("saver", obj, env, ses))
|
||||||
}
|
}
|
||||||
|
|
||||||
func gremlinFunc(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
|
func gremlinFunc(kind string, prevObj *otto.Object, env *otto.Otto, ses *Session) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
call.Otto.Run("var out = {}")
|
call.Otto.Run("var out = {}")
|
||||||
out, _ := call.Otto.Object("out")
|
out, _ := call.Otto.Object("out")
|
||||||
|
|
@ -59,7 +59,7 @@ func gremlinFunc(kind string, prevObj *otto.Object, env *otto.Otto, ses *Gremlin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func gremlinBack(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
|
func gremlinBack(kind string, prevObj *otto.Object, env *otto.Otto, ses *Session) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
call.Otto.Run("var out = {}")
|
call.Otto.Run("var out = {}")
|
||||||
out, _ := call.Otto.Object("out")
|
out, _ := call.Otto.Object("out")
|
||||||
|
|
@ -87,7 +87,7 @@ func gremlinBack(kind string, prevObj *otto.Object, env *otto.Otto, ses *Gremlin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func gremlinFollowR(kind string, prevObj *otto.Object, env *otto.Otto, ses *GremlinSession) func(otto.FunctionCall) otto.Value {
|
func gremlinFollowR(kind string, prevObj *otto.Object, env *otto.Otto, ses *Session) func(otto.FunctionCall) otto.Value {
|
||||||
return func(call otto.FunctionCall) otto.Value {
|
return func(call otto.FunctionCall) otto.Value {
|
||||||
call.Otto.Run("var out = {}")
|
call.Otto.Run("var out = {}")
|
||||||
out, _ := call.Otto.Object("out")
|
out, _ := call.Otto.Object("out")
|
||||||
|
|
@ -35,9 +35,9 @@ import (
|
||||||
// +---+
|
// +---+
|
||||||
//
|
//
|
||||||
|
|
||||||
func buildTripleStore() *MqlSession {
|
func buildTripleStore() *Session {
|
||||||
ts := memstore.MakeTestingMemstore()
|
ts := memstore.MakeTestingMemstore()
|
||||||
return NewMqlSession(ts)
|
return NewSession(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareJsonInterfaces(actual interface{}, expected interface{}, path MqlPath, t *testing.T) {
|
func compareJsonInterfaces(actual interface{}, expected interface{}, path MqlPath, t *testing.T) {
|
||||||
|
|
@ -25,7 +25,7 @@ type MqlPath string
|
||||||
type MqlResultPath string
|
type MqlResultPath string
|
||||||
|
|
||||||
type MqlQuery struct {
|
type MqlQuery struct {
|
||||||
ses *MqlSession
|
ses *Session
|
||||||
it graph.Iterator
|
it graph.Iterator
|
||||||
isRepeated map[MqlPath]bool
|
isRepeated map[MqlPath]bool
|
||||||
queryStructure map[MqlPath]map[string]interface{}
|
queryStructure map[MqlPath]map[string]interface{}
|
||||||
|
|
@ -100,7 +100,7 @@ func (p MqlPath) ToResultPathFromMap(resultMap map[MqlPath]string) MqlResultPath
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMqlQuery(ses *MqlSession) *MqlQuery {
|
func NewMqlQuery(ses *Session) *MqlQuery {
|
||||||
var q MqlQuery
|
var q MqlQuery
|
||||||
q.ses = ses
|
q.ses = ses
|
||||||
q.results = make([]interface{}, 0)
|
q.results = make([]interface{}, 0)
|
||||||
|
|
@ -24,23 +24,23 @@ import (
|
||||||
"github.com/google/cayley/graph"
|
"github.com/google/cayley/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MqlSession struct {
|
type Session struct {
|
||||||
ts graph.TripleStore
|
ts graph.TripleStore
|
||||||
currentQuery *MqlQuery
|
currentQuery *MqlQuery
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMqlSession(ts graph.TripleStore) *MqlSession {
|
func NewSession(ts graph.TripleStore) *Session {
|
||||||
var m MqlSession
|
var m Session
|
||||||
m.ts = ts
|
m.ts = ts
|
||||||
return &m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) ToggleDebug() {
|
func (m *Session) ToggleDebug() {
|
||||||
m.debug = !m.debug
|
m.debug = !m.debug
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interface{}) {
|
func (m *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
|
||||||
defer close(output_struct)
|
defer close(output_struct)
|
||||||
var mqlQuery interface{}
|
var mqlQuery interface{}
|
||||||
err := json.Unmarshal([]byte(input), &mqlQuery)
|
err := json.Unmarshal([]byte(input), &mqlQuery)
|
||||||
|
|
@ -61,7 +61,7 @@ func (m *MqlSession) GetQuery(input string, output_struct chan map[string]interf
|
||||||
output_struct <- output
|
output_struct <- output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) {
|
func (m *Session) InputParses(input string) (graph.ParseResult, error) {
|
||||||
var x interface{}
|
var x interface{}
|
||||||
err := json.Unmarshal([]byte(input), &x)
|
err := json.Unmarshal([]byte(input), &x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -70,7 +70,7 @@ func (m *MqlSession) InputParses(input string) (graph.ParseResult, error) {
|
||||||
return graph.Parsed, nil
|
return graph.Parsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) {
|
func (m *Session) ExecInput(input string, c chan interface{}, limit int) {
|
||||||
defer close(c)
|
defer close(c)
|
||||||
var mqlQuery interface{}
|
var mqlQuery interface{}
|
||||||
err := json.Unmarshal([]byte(input), &mqlQuery)
|
err := json.Unmarshal([]byte(input), &mqlQuery)
|
||||||
|
|
@ -102,7 +102,7 @@ func (m *MqlSession) ExecInput(input string, c chan interface{}, limit int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) ToText(result interface{}) string {
|
func (m *Session) ToText(result interface{}) string {
|
||||||
tags := *(result.(*map[string]graph.TSVal))
|
tags := *(result.(*map[string]graph.TSVal))
|
||||||
out := fmt.Sprintln("****")
|
out := fmt.Sprintln("****")
|
||||||
tagKeys := make([]string, len(tags))
|
tagKeys := make([]string, len(tags))
|
||||||
|
|
@ -125,11 +125,11 @@ func (m *MqlSession) ToText(result interface{}) string {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) BuildJson(result interface{}) {
|
func (m *Session) BuildJson(result interface{}) {
|
||||||
m.currentQuery.treeifyResult(*(result.(*map[string]graph.TSVal)))
|
m.currentQuery.treeifyResult(*(result.(*map[string]graph.TSVal)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) GetJson() (interface{}, error) {
|
func (m *Session) GetJson() (interface{}, error) {
|
||||||
m.currentQuery.buildResults()
|
m.currentQuery.buildResults()
|
||||||
if m.currentQuery.isError {
|
if m.currentQuery.isError {
|
||||||
return nil, m.currentQuery.err
|
return nil, m.currentQuery.err
|
||||||
|
|
@ -138,7 +138,7 @@ func (m *MqlSession) GetJson() (interface{}, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MqlSession) ClearJson() {
|
func (m *Session) ClearJson() {
|
||||||
// Since we create a new MqlQuery underneath every query, clearing isn't necessary.
|
// Since we create a new MqlQuery underneath every query, clearing isn't necessary.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue