Merge pull request #90 from kortschak/stringer
Remove terminal newline from quad.Quad stringer
This commit is contained in:
commit
d54cd6a3d3
6 changed files with 37 additions and 39 deletions
|
|
@ -22,7 +22,7 @@ import (
|
|||
)
|
||||
|
||||
func Open(cfg *config.Config) (graph.TripleStore, error) {
|
||||
glog.Infof("Opening database \"%s\" at %s", cfg.DatabaseType, cfg.DatabasePath)
|
||||
glog.Infof("Opening database %q at %s", cfg.DatabaseType, cfg.DatabasePath)
|
||||
ts, err := graph.NewTripleStore(cfg.DatabaseType, cfg.DatabasePath, cfg.DatabaseOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ import (
|
|||
"github.com/google/cayley/quad"
|
||||
)
|
||||
|
||||
func init() {
|
||||
graph.RegisterTripleStore("leveldb", newTripleStore, createNewLevelDB)
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultCacheSize = 2
|
||||
DefaultWriteBufferSize = 20
|
||||
|
|
@ -53,7 +57,7 @@ func createNewLevelDB(path string, _ graph.Options) error {
|
|||
opts := &opt.Options{}
|
||||
db, err := leveldb.OpenFile(path, opts)
|
||||
if err != nil {
|
||||
glog.Errorln("Error: couldn't create database: ", err)
|
||||
glog.Errorf("Error: couldn't create database: %v", err)
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
|
|
@ -145,7 +149,7 @@ func (qs *TripleStore) AddTriple(t *quad.Quad) {
|
|||
qs.buildWrite(batch, t)
|
||||
err := qs.db.Write(batch, qs.writeopts)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't write to DB for triple %s", t)
|
||||
glog.Errorf("Couldn't write to DB for triple %s.", t)
|
||||
return
|
||||
}
|
||||
qs.size++
|
||||
|
|
@ -162,7 +166,7 @@ var (
|
|||
func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
||||
_, err := qs.db.Get(qs.createKeyFor(spo, t), qs.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
glog.Errorf("Couldn't access DB to confirm deletion")
|
||||
glog.Error("Couldn't access DB to confirm deletion")
|
||||
return
|
||||
}
|
||||
if err == leveldb.ErrNotFound {
|
||||
|
|
@ -182,7 +186,7 @@ func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
|||
}
|
||||
err = qs.db.Write(batch, nil)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't delete triple %s", t)
|
||||
glog.Errorf("Couldn't delete triple %s.", t)
|
||||
return
|
||||
}
|
||||
qs.size--
|
||||
|
|
@ -191,7 +195,7 @@ func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
|||
func (qs *TripleStore) buildTripleWrite(batch *leveldb.Batch, t *quad.Quad) {
|
||||
bytes, err := json.Marshal(*t)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't write to buffer for triple %s\n %s\n", t, err)
|
||||
glog.Errorf("Couldn't write to buffer for triple %s: %s", t, err)
|
||||
return
|
||||
}
|
||||
batch.Put(qs.createKeyFor(spo, t), bytes)
|
||||
|
|
@ -224,7 +228,7 @@ func (qs *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.
|
|||
|
||||
// Error getting the node from the database.
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
glog.Errorf("Error reading Value %s from the DB\n", name)
|
||||
glog.Errorf("Error reading Value %s from the DB.", name)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +236,7 @@ func (qs *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.
|
|||
if b != nil && err != leveldb.ErrNotFound {
|
||||
err = json.Unmarshal(b, value)
|
||||
if err != nil {
|
||||
glog.Errorln("Error: couldn't reconstruct value ", err)
|
||||
glog.Errorf("Error: couldn't reconstruct value: %v", err)
|
||||
return
|
||||
}
|
||||
value.Size += int64(amount)
|
||||
|
|
@ -253,7 +257,7 @@ func (qs *TripleStore) UpdateValueKeyBy(name string, amount int, batch *leveldb.
|
|||
// Repackage and rewrite.
|
||||
bytes, err := json.Marshal(&value)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't write to buffer for value %s\n %s", name, err)
|
||||
glog.Errorf("Couldn't write to buffer for value %s: %s", name, err)
|
||||
return
|
||||
}
|
||||
if batch == nil {
|
||||
|
|
@ -281,7 +285,7 @@ func (qs *TripleStore) AddTripleSet(t_s []*quad.Quad) {
|
|||
}
|
||||
err := qs.db.Write(batch, qs.writeopts)
|
||||
if err != nil {
|
||||
glog.Errorf("Couldn't write to DB for tripleset")
|
||||
glog.Error("Couldn't write to DB for tripleset.")
|
||||
return
|
||||
}
|
||||
qs.size += int64(newTs)
|
||||
|
|
@ -293,7 +297,7 @@ func (qs *TripleStore) Close() {
|
|||
if err == nil {
|
||||
werr := qs.db.Put([]byte("__size"), buf.Bytes(), qs.writeopts)
|
||||
if werr != nil {
|
||||
glog.Errorf("Couldn't write size before closing!")
|
||||
glog.Error("Couldn't write size before closing!")
|
||||
}
|
||||
} else {
|
||||
glog.Errorf("Couldn't convert size before closing!")
|
||||
|
|
@ -306,7 +310,7 @@ func (qs *TripleStore) Quad(k graph.Value) *quad.Quad {
|
|||
var triple quad.Quad
|
||||
b, err := qs.db.Get(k.([]byte), qs.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
glog.Errorln("Error: couldn't get triple from DB")
|
||||
glog.Error("Error: couldn't get triple from DB.")
|
||||
return &quad.Quad{}
|
||||
}
|
||||
if err == leveldb.ErrNotFound {
|
||||
|
|
@ -315,7 +319,7 @@ func (qs *TripleStore) Quad(k graph.Value) *quad.Quad {
|
|||
}
|
||||
err = json.Unmarshal(b, &triple)
|
||||
if err != nil {
|
||||
glog.Errorln("Error: couldn't reconstruct triple")
|
||||
glog.Error("Error: couldn't reconstruct triple.")
|
||||
return &quad.Quad{}
|
||||
}
|
||||
return &triple
|
||||
|
|
@ -336,7 +340,7 @@ func (qs *TripleStore) ValueOf(s string) graph.Value {
|
|||
func (qs *TripleStore) valueData(value_key []byte) ValueData {
|
||||
var out ValueData
|
||||
if glog.V(3) {
|
||||
glog.V(3).Infof("%s %v\n", string(value_key[0]), value_key)
|
||||
glog.V(3).Infof("%s %v", string(value_key[0]), value_key)
|
||||
}
|
||||
b, err := qs.db.Get(value_key, qs.readopts)
|
||||
if err != nil && err != leveldb.ErrNotFound {
|
||||
|
|
@ -355,7 +359,7 @@ func (qs *TripleStore) valueData(value_key []byte) ValueData {
|
|||
|
||||
func (qs *TripleStore) NameOf(k graph.Value) string {
|
||||
if k == nil {
|
||||
glog.V(2).Infoln("k was nil")
|
||||
glog.V(2).Info("k was nil")
|
||||
return ""
|
||||
}
|
||||
return qs.valueData(k.([]byte)).Name
|
||||
|
|
@ -444,7 +448,3 @@ func compareBytes(a, b graph.Value) bool {
|
|||
func (qs *TripleStore) FixedIterator() graph.FixedIterator {
|
||||
return iterator.NewFixedIteratorWithCompare(compareBytes)
|
||||
}
|
||||
|
||||
func init() {
|
||||
graph.RegisterTripleStore("leveldb", newTripleStore, createNewLevelDB)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ import (
|
|||
"github.com/petar/GoLLRB/llrb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
graph.RegisterTripleStore("memstore", func(string, graph.Options) (graph.TripleStore, error) {
|
||||
return newTripleStore(), nil
|
||||
}, nil)
|
||||
}
|
||||
|
||||
type TripleDirectionIndex struct {
|
||||
subject map[int64]*llrb.LLRB
|
||||
predicate map[int64]*llrb.LLRB
|
||||
|
|
@ -240,7 +246,7 @@ func (ts *TripleStore) DebugPrint() {
|
|||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
glog.V(2).Infoln("%d: %s", i, t)
|
||||
glog.V(2).Infof("%d: %s", i, t)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,9 +275,3 @@ func (ts *TripleStore) NodesAllIterator() graph.Iterator {
|
|||
return NewMemstoreAllIterator(ts)
|
||||
}
|
||||
func (ts *TripleStore) Close() {}
|
||||
|
||||
func init() {
|
||||
graph.RegisterTripleStore("memstore", func(string, graph.Options) (graph.TripleStore, error) {
|
||||
return newTripleStore(), nil
|
||||
}, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import (
|
|||
"encoding/hex"
|
||||
"hash"
|
||||
"io"
|
||||
"log"
|
||||
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
|
|
@ -125,7 +124,7 @@ func (qs *TripleStore) updateNodeBy(node_name string, inc int) {
|
|||
size.Name = node_name
|
||||
size.Size = inc
|
||||
} else {
|
||||
glog.Error("Error:", err)
|
||||
glog.Errorf("Error: %v", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
|
@ -139,7 +138,7 @@ func (qs *TripleStore) updateNodeBy(node_name string, inc int) {
|
|||
if size.Size <= 0 {
|
||||
err := qs.db.C("nodes").RemoveId(node)
|
||||
if err != nil {
|
||||
glog.Error("Error: ", err, " while removing node ", node_name)
|
||||
glog.Errorf("Error: %v while removing node %s", err, node_name)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +146,7 @@ func (qs *TripleStore) updateNodeBy(node_name string, inc int) {
|
|||
|
||||
_, err2 := qs.db.C("nodes").UpsertId(node, size)
|
||||
if err2 != nil {
|
||||
glog.Error("Error: ", err)
|
||||
glog.Errorf("Error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +164,7 @@ func (qs *TripleStore) writeTriple(t *quad.Quad) bool {
|
|||
if err.(*mgo.LastError).Code == 11000 {
|
||||
return false
|
||||
}
|
||||
glog.Error("Error: ", err)
|
||||
glog.Errorf("Error: %v", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
@ -206,7 +205,7 @@ func (qs *TripleStore) RemoveTriple(t *quad.Quad) {
|
|||
if err == mgo.ErrNotFound {
|
||||
return
|
||||
} else if err != nil {
|
||||
log.Println("Error: ", err, " while removing triple ", t)
|
||||
glog.Errorf("Error: %v while removing triple %v", err, t)
|
||||
return
|
||||
}
|
||||
qs.updateNodeBy(t.Subject, -1)
|
||||
|
|
@ -221,7 +220,7 @@ func (qs *TripleStore) Quad(val graph.Value) *quad.Quad {
|
|||
var bsonDoc bson.M
|
||||
err := qs.db.C("triples").FindId(val.(string)).One(&bsonDoc)
|
||||
if err != nil {
|
||||
log.Println("Error: Couldn't retrieve triple", val.(string), err)
|
||||
glog.Errorf("Error: Couldn't retrieve triple %s %v", val, err)
|
||||
}
|
||||
return &quad.Quad{
|
||||
bsonDoc["Subject"].(string),
|
||||
|
|
@ -255,7 +254,7 @@ func (qs *TripleStore) NameOf(v graph.Value) string {
|
|||
var node MongoNode
|
||||
err := qs.db.C("nodes").FindId(v.(string)).One(&node)
|
||||
if err != nil {
|
||||
log.Println("Error: Couldn't retrieve node", v.(string), err)
|
||||
glog.Errorf("Error: Couldn't retrieve node %s %v", v, err)
|
||||
}
|
||||
qs.idCache.Put(v.(string), node.Name)
|
||||
return node.Name
|
||||
|
|
@ -264,7 +263,7 @@ func (qs *TripleStore) NameOf(v graph.Value) string {
|
|||
func (qs *TripleStore) Size() int64 {
|
||||
count, err := qs.db.C("triples").Count()
|
||||
if err != nil {
|
||||
glog.Error("Error: ", err)
|
||||
glog.Errorf("Error: %v", err)
|
||||
return 0
|
||||
}
|
||||
return int64(count)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func TestSingleIterator(t *testing.T) {
|
|||
result := StringResultTreeEvaluator(all)
|
||||
expected := "(1)\n(2)\n(3)\n"
|
||||
if expected != result {
|
||||
t.Errorf("Expected \"%s\" got \"%s\"", expected, result)
|
||||
t.Errorf("Expected %q got %q", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +40,6 @@ func TestAndIterator(t *testing.T) {
|
|||
result := StringResultTreeEvaluator(and)
|
||||
expected := "(3 (3) (3))\n"
|
||||
if expected != result {
|
||||
t.Errorf("Expected \"%s\" got \"%s\"", expected, result)
|
||||
t.Errorf("Expected %q got %q", expected, result)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,8 +125,7 @@ func (q *Quad) Equals(o *Quad) bool {
|
|||
|
||||
// Pretty-prints a triple.
|
||||
func (q *Quad) String() string {
|
||||
// TODO(kortschak) String methods should generally not terminate in '\n'.
|
||||
return fmt.Sprintf("%s -- %s -> %s\n", q.Subject, q.Predicate, q.Object)
|
||||
return fmt.Sprintf("%s -- %s -> %s", q.Subject, q.Predicate, q.Object)
|
||||
}
|
||||
|
||||
func (q *Quad) IsValid() bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue