Merge pull request #8 from kortschak/master

make cayley go-gettable
This commit is contained in:
Barak Michener 2014-06-27 19:36:59 -07:00
commit a63bce6474
139 changed files with 10176 additions and 10231 deletions

4
.gitignore vendored
View file

@ -2,8 +2,4 @@
main main
*.test *.test
*.peg.go *.peg.go
cayley
cayley.cfg cayley.cfg
leveldb/
snappy/
pkg/

View file

@ -1,29 +0,0 @@
# Copyright 2014 The Cayley Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
default: build
build:
./make.sh build
deps:
./make.sh deps
test:
ls ./src | grep -v "\." | sed 's/\///g' | xargs go test -cover
convey:
./bin/goconvey --depth=2

View file

@ -52,10 +52,7 @@ Make sure you have the right packages installed. Mostly, this is just Go as a de
Now you can clone the repository and build the project. Now you can clone the repository and build the project.
```bash ```bash
git clone git@github.com:google/cayley.git go get github.com/google/cayley/cmd/cayley
cd cayley
make deps
make
``` ```
And the `cayley` binary will be built and ready. And the `cayley` binary will be built and ready.

View file

@ -1,9 +0,0 @@
# Absolute path this script is in. /home/user/bin
cd "`dirname '${BASH_SOURCE:-$0}'`"
SCRIPTPATH="`pwd`"
echo $dir
cd - > /dev/null
export GOPATH=$SCRIPTPATH
#export GOOS="linux"
#export GOARCH="amd64"

View file

@ -15,22 +15,24 @@
package cayleyappengine package cayleyappengine
import ( import (
"cayley_config"
"cayley_http"
"github.com/barakmich/glog"
"graph"
"graph_memstore"
"nquads"
"os" "os"
"github.com/barakmich/glog"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore"
"github.com/google/cayley/http"
"github.com/google/cayley/nquads"
) )
func init() { func init() {
glog.SetToStderr(true) glog.SetToStderr(true)
config := cayley_config.ParseConfigFromFile("cayley_appengine.cfg") cfg := config.ParseConfigFromFile("cayley_appengine.cfg")
ts := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
glog.Errorln(config) glog.Errorln(cfg)
LoadTriplesFromFileInto(ts, config.DatabasePath, config.LoadSize) LoadTriplesFromFileInto(ts, cfg.DatabasePath, cfg.LoadSize)
cayley_http.SetupRoutes(ts, config) http.SetupRoutes(ts, cfg)
} }
func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) { func ReadTriplesFromFile(c chan *graph.Triple, tripleFile string) {

View file

@ -15,15 +15,17 @@
package main package main
import ( import (
cayley "cayley_cmd"
cfg "cayley_config"
cayley_http "cayley_http"
"flag" "flag"
"fmt" "fmt"
"github.com/barakmich/glog"
"graph"
"os" "os"
"runtime" "runtime"
"github.com/barakmich/glog"
"github.com/google/cayley/config"
"github.com/google/cayley/db"
"github.com/google/cayley/graph"
"github.com/google/cayley/http"
) )
var tripleFile = flag.String("triples", "", "Triple File to load before going to REPL.") var tripleFile = flag.String("triples", "", "Triple File to load before going to REPL.")
@ -58,7 +60,7 @@ func main() {
os.Args = newargs os.Args = newargs
flag.Parse() flag.Parse()
var ts graph.TripleStore var ts graph.TripleStore
config := cfg.ParseConfigFromFlagsAndFile(*configFile) cfg := config.ParseConfigFromFlagsAndFile(*configFile)
if os.Getenv("GOMAXPROCS") == "" { if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
glog.Infoln("Setting GOMAXPROCS to", runtime.NumCPU()) glog.Infoln("Setting GOMAXPROCS to", runtime.NumCPU())
@ -67,18 +69,18 @@ func main() {
} }
switch cmd { switch cmd {
case "init": case "init":
cayley.CayleyInit(config, *tripleFile) db.CayleyInit(cfg, *tripleFile)
case "load": case "load":
ts = cayley.OpenTSFromConfig(config) ts = db.OpenTSFromConfig(cfg)
cayley.CayleyLoad(ts, config, *tripleFile, false) db.CayleyLoad(ts, cfg, *tripleFile, false)
ts.Close() ts.Close()
case "repl": case "repl":
ts = cayley.OpenTSFromConfig(config) ts = db.OpenTSFromConfig(cfg)
cayley.CayleyRepl(ts, *queryLanguage, config) db.CayleyRepl(ts, *queryLanguage, cfg)
ts.Close() ts.Close()
case "http": case "http":
ts = cayley.OpenTSFromConfig(config) ts = db.OpenTSFromConfig(cfg)
cayley_http.CayleyHTTP(ts, config) http.CayleyHTTP(ts, cfg)
ts.Close() ts.Close()
default: default:
fmt.Println("No command", cmd) fmt.Println("No command", cmd)

View file

@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_config package config
import ( import (
"encoding/json" "encoding/json"
"flag" "flag"
"github.com/barakmich/glog"
"os" "os"
"github.com/barakmich/glog"
) )
type CayleyConfig struct { type CayleyConfig struct {

View file

@ -12,28 +12,28 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley package db
import ( import (
cfg "cayley_config" "github.com/google/cayley/config"
"graph_leveldb" "github.com/google/cayley/graph/leveldb"
"graph_mongo" "github.com/google/cayley/graph/mongo"
) )
func CayleyInit(config *cfg.CayleyConfig, triplePath string) bool { func CayleyInit(cfg *config.CayleyConfig, triplePath string) bool {
created := false created := false
dbpath := config.DatabasePath dbpath := cfg.DatabasePath
switch config.DatabaseType { switch cfg.DatabaseType {
case "mongo", "mongodb": case "mongo", "mongodb":
created = graph_mongo.CreateNewMongoGraph(dbpath, config.DatabaseOptions) created = mongo.CreateNewMongoGraph(dbpath, cfg.DatabaseOptions)
case "leveldb": case "leveldb":
created = graph_leveldb.CreateNewLevelDB(dbpath) created = leveldb.CreateNewLevelDB(dbpath)
case "mem": case "mem":
return true return true
} }
if created && triplePath != "" { if created && triplePath != "" {
ts := OpenTSFromConfig(config) ts := OpenTSFromConfig(cfg)
CayleyLoad(ts, config, triplePath, true) CayleyLoad(ts, cfg, triplePath, true)
ts.Close() ts.Close()
} }
return created return created

View file

@ -12,36 +12,38 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley package db
import ( import (
cfg "cayley_config"
"github.com/barakmich/glog"
"graph"
"graph_mongo"
"nquads"
"os" "os"
"github.com/barakmich/glog"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/mongo"
"github.com/google/cayley/nquads"
) )
func CayleyLoad(ts graph.TripleStore, config *cfg.CayleyConfig, triplePath string, firstTime bool) { func CayleyLoad(ts graph.TripleStore, cfg *config.CayleyConfig, triplePath string, firstTime bool) {
switch config.DatabaseType { switch cfg.DatabaseType {
case "mongo", "mongodb": case "mongo", "mongodb":
if firstTime { if firstTime {
loadMongo(ts.(*graph_mongo.MongoTripleStore), triplePath) loadMongo(ts.(*mongo.MongoTripleStore), triplePath)
} else { } else {
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
} }
case "rethink", "rethinkdb": case "rethink", "rethinkdb":
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
case "leveldb": case "leveldb":
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
case "mem": case "mem":
LoadTriplesFromFileInto(ts, triplePath, config.LoadSize) LoadTriplesFromFileInto(ts, triplePath, cfg.LoadSize)
} }
} }
func loadMongo(ts *graph_mongo.MongoTripleStore, path string) { func loadMongo(ts *mongo.MongoTripleStore, 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)

View file

@ -12,29 +12,29 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley package db
import ( import (
"graph"
cfg "cayley_config"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"graph_leveldb"
"graph_memstore" "github.com/google/cayley/config"
"graph_mongo" "github.com/google/cayley/graph"
"github.com/google/cayley/graph/leveldb"
"github.com/google/cayley/graph/memstore"
"github.com/google/cayley/graph/mongo"
) )
func OpenTSFromConfig(config *cfg.CayleyConfig) graph.TripleStore { func OpenTSFromConfig(cfg *config.CayleyConfig) graph.TripleStore {
glog.Infof("Opening database \"%s\" at %s", config.DatabaseType, config.DatabasePath) glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
switch config.DatabaseType { switch cfg.DatabaseType {
case "mongo", "mongodb": case "mongo", "mongodb":
return graph_mongo.NewMongoTripleStore(config.DatabasePath, config.DatabaseOptions) return mongo.NewMongoTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
case "leveldb": case "leveldb":
return graph_leveldb.NewDefaultLevelDBTripleStore(config.DatabasePath, config.DatabaseOptions) return leveldb.NewDefaultLevelDBTripleStore(cfg.DatabasePath, cfg.DatabaseOptions)
case "mem": case "mem":
ts := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
CayleyLoad(ts, config, config.DatabasePath, true) CayleyLoad(ts, cfg, cfg.DatabasePath, true)
return ts return ts
} }
panic("Unsupported database backend " + config.DatabaseType) panic("Unsupported database backend " + cfg.DatabaseType)
} }

View file

@ -12,21 +12,22 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley package db
import ( import (
"bufio" "bufio"
cfg "cayley_config"
"fmt" "fmt"
"graph"
sexp "graph_sexp"
"gremlin"
"io" "io"
"mql"
"nquads"
"os" "os"
"strings" "strings"
"time" "time"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/sexp"
"github.com/google/cayley/nquads"
"github.com/google/cayley/query/gremlin"
"github.com/google/cayley/query/mql"
) )
func trace(s string) (string, time.Time) { func trace(s string) (string, time.Time) {
@ -59,7 +60,7 @@ func RunQuery(query string, ses graph.Session) {
} }
} }
func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyConfig) { func CayleyRepl(ts graph.TripleStore, queryLanguage string, cfg *config.CayleyConfig) {
var ses graph.Session var ses graph.Session
switch queryLanguage { switch queryLanguage {
case "sexp": case "sexp":
@ -69,7 +70,7 @@ func CayleyRepl(ts graph.TripleStore, queryLanguage string, config *cfg.CayleyCo
case "gremlin": case "gremlin":
fallthrough fallthrough
default: default:
ses = gremlin.NewGremlinSession(ts, config.GremlinTimeout, true) ses = gremlin.NewGremlinSession(ts, cfg.GremlinTimeout, true)
} }
inputBf := bufio.NewReader(os.Stdin) inputBf := bufio.NewReader(os.Stdin)
line := "" line := ""

View file

@ -12,15 +12,17 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_leveldb package leveldb
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"strings"
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator" leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
"graph"
"strings" "github.com/google/cayley/graph"
) )
type LevelDBAllIterator struct { type LevelDBAllIterator struct {

View file

@ -12,16 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_leveldb package leveldb
import ( import (
"bytes" "bytes"
_ "encoding/binary" _ "encoding/binary"
"fmt" "fmt"
"strings"
leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator" leveldb_it "github.com/syndtr/goleveldb/leveldb/iterator"
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
"graph"
"strings" "github.com/google/cayley/graph"
) )
type LevelDBIterator struct { type LevelDBIterator struct {

View file

@ -12,15 +12,17 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_leveldb package leveldb
import ( import (
. "github.com/smartystreets/goconvey/convey"
"graph"
"io/ioutil" "io/ioutil"
"os" "os"
"sort" "sort"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph"
) )
func makeTripleSet() []*graph.Triple { func makeTripleSet() []*graph.Triple {
@ -136,7 +138,7 @@ func TestLoadDatabase(t *testing.T) {
} }
func TestAllIterator(t *testing.T) { func TestIterator(t *testing.T) {
var ts *LevelDBTripleStore var ts *LevelDBTripleStore
Convey("Given a prepared database", t, func() { Convey("Given a prepared database", t, func() {

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_leveldb package leveldb
import ( import (
"bytes" "bytes"
@ -20,13 +20,15 @@ import (
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
"hash"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
leveldb_cache "github.com/syndtr/goleveldb/leveldb/cache" leveldb_cache "github.com/syndtr/goleveldb/leveldb/cache"
leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt" leveldb_opt "github.com/syndtr/goleveldb/leveldb/opt"
leveldb_util "github.com/syndtr/goleveldb/leveldb/util" leveldb_util "github.com/syndtr/goleveldb/leveldb/util"
"graph"
"hash" "github.com/google/cayley/graph"
) )
const DefaultCacheSize = 2 const DefaultCacheSize = 2

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_leveldb package leveldb
import ( import (
"graph" "github.com/google/cayley/graph"
) )
func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { func (ts *LevelDBTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {

View file

@ -12,14 +12,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import ( import (
"fmt" "fmt"
"github.com/petar/GoLLRB/llrb"
"graph"
"math" "math"
"strings" "strings"
"github.com/petar/GoLLRB/llrb"
"github.com/google/cayley/graph"
) )
type LlrbIterator struct { type LlrbIterator struct {

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import ( import (
"graph" "github.com/google/cayley/graph"
) )
type MemstoreAllIterator struct { type MemstoreAllIterator struct {

View file

@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import ( import (
"fmt" "fmt"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"github.com/google/cayley/graph"
"github.com/petar/GoLLRB/llrb" "github.com/petar/GoLLRB/llrb"
"graph"
) )
type TripleDirectionIndex struct { type TripleDirectionIndex struct {

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import ( import (
"graph" "github.com/google/cayley/graph"
) )
func (ts *MemTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { func (ts *MemTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {

View file

@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import ( import (
. "github.com/smartystreets/goconvey/convey"
"graph"
"sort" "sort"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph"
) )
func TestMemstore(t *testing.T) { func TestMemstore(t *testing.T) {

View file

@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_memstore package memstore
import "graph" import "github.com/google/cayley/graph"
// +---+ +---+ // +---+ +---+
// | A |------- ->| F |<-- // | A |------- ->| F |<--

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_mongo package mongo
import ( import (
"container/list" "container/list"

View file

@ -12,15 +12,17 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_mongo package mongo
import ( import (
"fmt" "fmt"
"strings"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"graph"
"labix.org/v2/mgo" "labix.org/v2/mgo"
"labix.org/v2/mgo/bson" "labix.org/v2/mgo/bson"
"strings"
"github.com/google/cayley/graph"
) )
type MongoIterator struct { type MongoIterator struct {

View file

@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_mongo package mongo
import ( import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"github.com/barakmich/glog"
"graph"
"hash" "hash"
"log"
"labix.org/v2/mgo" "labix.org/v2/mgo"
"labix.org/v2/mgo/bson" "labix.org/v2/mgo/bson"
"log"
"github.com/barakmich/glog"
"github.com/google/cayley/graph"
) )
const DefaultDBName = "cayley" const DefaultDBName = "cayley"

View file

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_mongo package mongo
import ( import (
"graph" "github.com/google/cayley/graph"
) )
func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) { func (ts *MongoTripleStore) OptimizeIterator(it graph.Iterator) (graph.Iterator, bool) {

View file

@ -12,11 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_sexp package sexp
import ( import (
"github.com/badgerodon/peg" "github.com/badgerodon/peg"
"graph"
"github.com/google/cayley/graph"
) )
func BuildIteratorTreeForQuery(ts graph.TripleStore, query string) graph.Iterator { func BuildIteratorTreeForQuery(ts graph.TripleStore, query string) graph.Iterator {

View file

@ -12,13 +12,15 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_sexp package sexp
import ( import (
. "github.com/smartystreets/goconvey/convey"
"graph"
"graph_memstore"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/memstore"
) )
func TestBadParse(t *testing.T) { func TestBadParse(t *testing.T) {
@ -30,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 := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
Convey("It should parse an empty query", func() { Convey("It should parse an empty query", func() {
it := BuildIteratorTreeForQuery(ts, "()") it := BuildIteratorTreeForQuery(ts, "()")
@ -62,7 +64,7 @@ func TestParseSexpWithMemstore(t *testing.T) {
} }
func TestTreeConstraintParse(t *testing.T) { func TestTreeConstraintParse(t *testing.T) {
ts := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
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" +
@ -82,7 +84,7 @@ func TestTreeConstraintParse(t *testing.T) {
} }
func TestTreeConstraintTagParse(t *testing.T) { func TestTreeConstraintTagParse(t *testing.T) {
ts := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
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" +
@ -102,7 +104,7 @@ func TestTreeConstraintTagParse(t *testing.T) {
} }
func TestMultipleConstraintParse(t *testing.T) { func TestMultipleConstraintParse(t *testing.T) {
ts := graph_memstore.NewMemTripleStore() ts := memstore.NewMemTripleStore()
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", ""))

View file

@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package graph_sexp package sexp
// Defines a running session of the sexp query language. // Defines a running session of the sexp query language.
import ( import (
"errors" "errors"
"fmt" "fmt"
"graph"
"sort" "sort"
"github.com/google/cayley/graph"
) )
type SexpSession struct { type SexpSession struct {

View file

@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_http package http
import ( import (
cfg "cayley_config"
"fmt" "fmt"
"github.com/barakmich/glog"
"github.com/julienschmidt/httprouter"
"graph"
"html/template" "html/template"
"net/http" "net/http"
"time" "time"
"github.com/barakmich/glog"
"github.com/julienschmidt/httprouter"
"github.com/google/cayley/config"
"github.com/google/cayley/graph"
) )
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) int type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) int
@ -69,7 +71,7 @@ func (h *TemplateRequestHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
} }
type Api struct { type Api struct {
config *cfg.CayleyConfig config *config.CayleyConfig
ts graph.TripleStore ts graph.TripleStore
} }
@ -82,13 +84,13 @@ 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, config *cfg.CayleyConfig) { func SetupRoutes(ts graph.TripleStore, cfg *config.CayleyConfig) {
r := httprouter.New() r := httprouter.New()
var templates = template.Must(template.ParseGlob("templates/*.tmpl")) var templates = template.Must(template.ParseGlob("templates/*.tmpl"))
templates.ParseGlob("templates/*.html") templates.ParseGlob("templates/*.html")
root := &TemplateRequestHandler{templates: templates} root := &TemplateRequestHandler{templates: templates}
docs := &DocRequestHandler{} docs := &DocRequestHandler{}
api := &Api{config: config, ts: ts} api := &Api{config: cfg, ts: ts}
api.ApiV1(r) api.ApiV1(r)
//m.Use(martini.Static("static", martini.StaticOptions{Prefix: "/static", SkipLogging: true})) //m.Use(martini.Static("static", martini.StaticOptions{Prefix: "/static", SkipLogging: true}))
@ -100,11 +102,11 @@ func SetupRoutes(ts graph.TripleStore, config *cfg.CayleyConfig) {
http.Handle("/", r) http.Handle("/", r)
} }
func CayleyHTTP(ts graph.TripleStore, config *cfg.CayleyConfig) { func CayleyHTTP(ts graph.TripleStore, cfg *config.CayleyConfig) {
SetupRoutes(ts, config) SetupRoutes(ts, cfg)
glog.Infof("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort) glog.Infof("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
fmt.Printf("Cayley now listening on %s:%s\n", config.ListenHost, config.ListenPort) fmt.Printf("Cayley now listening on %s:%s\n", cfg.ListenHost, cfg.ListenPort)
err := http.ListenAndServe(fmt.Sprintf("%s:%s", config.ListenHost, config.ListenPort), nil) err := http.ListenAndServe(fmt.Sprintf("%s:%s", cfg.ListenHost, cfg.ListenPort), nil)
if err != nil { if err != nil {
glog.Fatal("ListenAndServe: ", err) glog.Fatal("ListenAndServe: ", err)
} }

View file

@ -12,15 +12,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_http package http
import ( import (
"fmt" "fmt"
"github.com/julienschmidt/httprouter"
"github.com/russross/blackfriday"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"github.com/julienschmidt/httprouter"
"github.com/russross/blackfriday"
) )
type DocRequestHandler struct { type DocRequestHandler struct {

View file

@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_http package http
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/julienschmidt/httprouter"
"graph"
"gremlin"
"io/ioutil" "io/ioutil"
"mql"
"net/http" "net/http"
"github.com/julienschmidt/httprouter"
"github.com/google/cayley/graph"
"github.com/google/cayley/query/gremlin"
"github.com/google/cayley/query/mql"
) )
type SuccessQueryWrapper struct { type SuccessQueryWrapper struct {

View file

@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_http package http
import ( import (
. "github.com/smartystreets/goconvey/convey"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
) )
func TestParseJSONOkay(t *testing.T) { func TestParseJSONOkay(t *testing.T) {

View file

@ -12,19 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package cayley_http package http
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/barakmich/glog"
"github.com/julienschmidt/httprouter"
"graph"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"nquads"
"strconv" "strconv"
"github.com/barakmich/glog"
"github.com/julienschmidt/httprouter"
"github.com/google/cayley/graph"
"github.com/google/cayley/nquads"
) )
func ParseJsonToTripleList(jsonBody []byte) ([]*graph.Triple, error) { func ParseJsonToTripleList(jsonBody []byte) ([]*graph.Triple, error) {

65
make.sh
View file

@ -1,65 +0,0 @@
#!/usr/bin/env bash
# Copyright 2014 The Cayley Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
cd "`dirname '$0'`"
SCRIPTPATH="`pwd`"
cd - > /dev/null
export GOPATH=$SCRIPTPATH
export GOBIN=
function deps {
echo "Fetching dependencies to $SCRIPTPATH..."
printf " (00/15)\r"
go get -u -t github.com/smartystreets/goconvey
printf "# (01/15)\r"
go get -u github.com/badgerodon/peg
printf "## (02/15)\r"
go get -u github.com/barakmich/glog
printf "#### (03/15)\r"
go get -u github.com/julienschmidt/httprouter
printf "##### (04/15)\r"
go get -u github.com/petar/GoLLRB/llrb
printf "###### (05/15)\r"
go get -u github.com/robertkrimen/otto
printf "####### (06/15)\r"
go get -u github.com/stretchrcom/testify
printf "######## (07/15)\r"
go get -u github.com/syndtr/goleveldb/leveldb
printf "######### (08/15)\r"
go get -u github.com/syndtr/goleveldb/leveldb/cache
printf "########## (09/15)\r"
go get -u github.com/syndtr/goleveldb/leveldb/iterator
printf "########### (10/15)\r"
go get -u github.com/syndtr/goleveldb/leveldb/opt
printf "############ (11/15)\r"
go get -u github.com/syndtr/goleveldb/leveldb/util
printf "############# (12/15)\r"
go get -u labix.org/v2/mgo
printf "############## (13/15)\r"
go get -u labix.org/v2/mgo/bson
printf "############### (14/15)\r"
go get -u github.com/russross/blackfriday
printf "################ (15/15)\r"
printf "\n"
}
function build {
go build cayley
}
$1

View file

@ -16,10 +16,12 @@ package nquads
import ( import (
"bufio" "bufio"
"github.com/barakmich/glog"
"graph"
"io" "io"
"strings" "strings"
"github.com/barakmich/glog"
"github.com/google/cayley/graph"
) )
func isWhitespace(s uint8) bool { func isWhitespace(s uint8) bool {

View file

@ -15,9 +15,11 @@
package nquads package nquads
import ( import (
. "github.com/smartystreets/goconvey/convey"
"graph"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph"
) )
func TestParsingNTriples(t *testing.T) { func TestParsingNTriples(t *testing.T) {

View file

@ -15,10 +15,12 @@
package gremlin package gremlin
import ( import (
"strconv"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"github.com/robertkrimen/otto" "github.com/robertkrimen/otto"
"graph"
"strconv" "github.com/google/cayley/graph"
) )
func getStrings(obj *otto.Object, field string) []string { func getStrings(obj *otto.Object, field string) []string {

View file

@ -17,7 +17,8 @@ package gremlin
import ( import (
"github.com/barakmich/glog" "github.com/barakmich/glog"
"github.com/robertkrimen/otto" "github.com/robertkrimen/otto"
"graph"
"github.com/google/cayley/graph"
) )
const GremlinTopResultTag = "id" const GremlinTopResultTag = "id"

View file

@ -15,10 +15,12 @@
package gremlin package gremlin
import ( import (
. "github.com/smartystreets/goconvey/convey"
"graph_memstore"
"sort" "sort"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph/memstore"
) )
// +---+ +---+ // +---+ +---+
@ -34,8 +36,8 @@ import (
// //
func buildTripleStore() *GremlinSession { func buildTripleStore() *GremlinSession {
ts := graph_memstore.MakeTestingMemstore() ts := memstore.MakeTestingMemstore()
return NewGremlinSession(ts, -1) return NewGremlinSession(ts, -1, false)
} }
func shouldBeUnordered(actual interface{}, expected ...interface{}) string { func shouldBeUnordered(actual interface{}, expected ...interface{}) string {

View file

@ -17,10 +17,12 @@ package gremlin
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/robertkrimen/otto"
"graph"
"sort" "sort"
"time" "time"
"github.com/robertkrimen/otto"
"github.com/google/cayley/graph"
) )
type GremlinSession struct { type GremlinSession struct {

View file

@ -17,10 +17,11 @@ package mql
import ( import (
"errors" "errors"
"fmt" "fmt"
"graph"
"log" "log"
"math" "math"
"strings" "strings"
"github.com/google/cayley/graph"
) )
func (m *MqlQuery) buildFixed(s string) graph.Iterator { func (m *MqlQuery) buildFixed(s string) graph.Iterator {

View file

@ -15,8 +15,9 @@
package mql package mql
import ( import (
"graph"
"sort" "sort"
"github.com/google/cayley/graph"
) )
func (m *MqlQuery) treeifyResult(tags map[string]graph.TSVal) map[MqlResultPath]string { func (m *MqlQuery) treeifyResult(tags map[string]graph.TSVal) map[MqlResultPath]string {

View file

@ -16,9 +16,11 @@ package mql
import ( import (
"encoding/json" "encoding/json"
. "github.com/smartystreets/goconvey/convey"
"graph_memstore"
"testing" "testing"
. "github.com/smartystreets/goconvey/convey"
"github.com/google/cayley/graph/memstore"
) )
// +---+ +---+ // +---+ +---+
@ -34,7 +36,7 @@ import (
// //
func buildTripleStore() *MqlSession { func buildTripleStore() *MqlSession {
ts := graph_memstore.MakeTestingMemstore() ts := memstore.MakeTestingMemstore()
return NewMqlSession(ts) return NewMqlSession(ts)
} }

View file

@ -16,8 +16,9 @@ package mql
import ( import (
"fmt" "fmt"
"graph"
"strings" "strings"
"github.com/google/cayley/graph"
) )
type MqlPath string type MqlPath string

View file

@ -17,9 +17,11 @@ package mql
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/barakmich/glog"
"graph"
"sort" "sort"
"github.com/barakmich/glog"
"github.com/google/cayley/graph"
) )
type MqlSession struct { type MqlSession struct {