From 41bf496d9dfe622b385c1482789480df8b106472 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sat, 23 Dec 2017 12:58:28 +0200 Subject: [PATCH] deprecate quad.Raw type --- graph/bolt/bolt_test.go | 8 +- graph/gaedatastore/quadstore.go | 8 +- graph/gaedatastore/quadstore_test.go | 6 +- graph/graphmock/graphmock.go | 4 +- graph/graphtest/graphtest.go | 136 +++++++++++++-------------- graph/graphtest/integration.go | 3 + graph/iterator/recursive_test.go | 6 +- graph/iterator/regex.go | 2 - graph/iterator/value_comparison.go | 2 - graph/leveldb/leveldb_test.go | 2 +- graph/memstore/quadstore_test.go | 14 +-- graph/mongo/quadstore.go | 2 - graph/nosql/quadstore.go | 5 - graph/nosql/shapes.go | 1 - graph/transaction_test.go | 28 +++--- quad/json/json_test.go | 2 +- quad/nquads/nquads.go | 4 +- quad/nquads/raw_test.go | 2 +- quad/nquads/typed_test.go | 2 +- quad/pquads/quads.go | 22 ++--- quad/quad.go | 18 ++-- quad/value.go | 22 +++-- quad/value_test.go | 1 - query/sexp/parser_test.go | 2 +- 24 files changed, 153 insertions(+), 149 deletions(-) diff --git a/graph/bolt/bolt_test.go b/graph/bolt/bolt_test.go index 122bf8322..c0215e185 100644 --- a/graph/bolt/bolt_test.go +++ b/graph/bolt/bolt_test.go @@ -100,14 +100,14 @@ func TestLoadDatabase(t *testing.T) { } w, _ := writer.NewSingleReplication(qs, nil) - w.AddQuad(quad.MakeRaw( + w.AddQuad(quad.Make( "Something", "points_to", "Something Else", "context", )) for _, pq := range []string{"Something", "points_to", "Something Else", "context"} { - if got := qs.NameOf(qs.ValueOf(quad.Raw(pq))).String(); got != pq { + if got := quad.ToString(qs.NameOf(qs.ValueOf(quad.Raw(pq)))); got != pq { t.Errorf("Failed to roundtrip %q, got:%q expect:%q", pq, got, pq) } } @@ -139,11 +139,11 @@ func TestLoadDatabase(t *testing.T) { t.Errorf("Unexpected quadstore size, got:%d expect:5", s) } - w.RemoveQuad(quad.MakeRaw( + w.RemoveQuad(quad.Make( "A", "follows", "B", - "", + nil, )) if s := qs.Size(); s != 11 { t.Errorf("Unexpected quadstore size after RemoveQuad, got:%d expect:11", s) diff --git a/graph/gaedatastore/quadstore.go b/graph/gaedatastore/quadstore.go index 17af98994..417d44b40 100644 --- a/graph/gaedatastore/quadstore.go +++ b/graph/gaedatastore/quadstore.go @@ -461,11 +461,15 @@ func (qs *QuadStore) Quad(val graph.Value) quad.Quad { clog.Errorf("Error: %v", err) } } - return quad.MakeRaw( + var label interface{} + if q.Label != "" { + label = q.Label + } + return quad.Make( q.Subject, q.Predicate, q.Object, - q.Label, + label, ) } diff --git a/graph/gaedatastore/quadstore_test.go b/graph/gaedatastore/quadstore_test.go index 2897fc2c5..5083308f6 100644 --- a/graph/gaedatastore/quadstore_test.go +++ b/graph/gaedatastore/quadstore_test.go @@ -107,8 +107,8 @@ func TestIterators(t *testing.T) { require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads") var expected = []quad.Quad{ - quad.MakeRaw("C", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), + quad.Make("C", "follows", "B", ""), + quad.Make("C", "follows", "D", ""), } it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("C"))) @@ -117,7 +117,7 @@ func TestIterators(t *testing.T) { // Test contains it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.Raw("status_graph"))) gqs := qs.(*QuadStore) - key := gqs.createKeyForQuad(quad.MakeRaw("G", "status", "cool", "status_graph")) + key := gqs.createKeyForQuad(quad.Make("G", "status", "cool", "status_graph")) token := &Token{quadKind, key.StringID()} require.True(t, it.Contains(token), "Contains failed") diff --git a/graph/graphmock/graphmock.go b/graph/graphmock/graphmock.go index 39f96a7af..3c71777ae 100644 --- a/graph/graphmock/graphmock.go +++ b/graph/graphmock/graphmock.go @@ -44,7 +44,7 @@ func (qs *Oldstore) ValueOf(s quad.Value) graph.Value { return nil } for i := range qs.Data { - if s.String() == qs.valueAt(i).String() { + if va := qs.valueAt(i); va != nil && s.String() == va.String() { return iterator.Int64Node(i) } } @@ -75,7 +75,7 @@ func (qs *Oldstore) NameOf(v graph.Value) quad.Value { if qs.Parse { return quad.String(v.(StringNode)) } - return quad.Raw(v.(StringNode)) + return quad.Raw(string(v.(StringNode))) default: return nil } diff --git a/graph/graphtest/graphtest.go b/graph/graphtest/graphtest.go index 1e25e5a5d..76cdcda5a 100644 --- a/graph/graphtest/graphtest.go +++ b/graph/graphtest/graphtest.go @@ -85,17 +85,17 @@ func TestAll(t *testing.T, gen testutil.DatabaseFunc, conf *Config) { // func MakeQuadSet() []quad.Quad { return []quad.Quad{ - quad.MakeRaw("A", "follows", "B", ""), - quad.MakeRaw("C", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), - quad.MakeRaw("D", "follows", "B", ""), - quad.MakeRaw("B", "follows", "F", ""), - quad.MakeRaw("F", "follows", "G", ""), - quad.MakeRaw("D", "follows", "G", ""), - quad.MakeRaw("E", "follows", "F", ""), - quad.MakeRaw("B", "status", "cool", "status_graph"), - quad.MakeRaw("D", "status", "cool", "status_graph"), - quad.MakeRaw("G", "status", "cool", "status_graph"), + quad.Make("A", "follows", "B", nil), + quad.Make("C", "follows", "B", nil), + quad.Make("C", "follows", "D", nil), + quad.Make("D", "follows", "B", nil), + quad.Make("B", "follows", "F", nil), + quad.Make("F", "follows", "G", nil), + quad.Make("D", "follows", "G", nil), + quad.Make("E", "follows", "F", nil), + quad.Make("B", "status", "cool", "status_graph"), + quad.Make("D", "status", "cool", "status_graph"), + quad.Make("G", "status", "cool", "status_graph"), } } @@ -121,7 +121,7 @@ func ExpectIteratedQuads(t testing.TB, qs graph.QuadStore, it graph.Iterator, ex func ExpectIteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator, exp []string) { //sort.Strings(exp) - got := IteratedRawStrings(t, qs, it) + got := IteratedStrings(t, qs, it) //sort.Strings(got) require.Equal(t, exp, got) } @@ -140,11 +140,11 @@ func ExpectIteratedValues(t testing.TB, qs graph.QuadStore, it graph.Iterator, e } } -func IteratedRawStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string { +func IteratedStrings(t testing.TB, qs graph.QuadStore, it graph.Iterator) []string { ctx := context.TODO() var res []string for it.Next(ctx) { - res = append(res, quad.StringOf(qs.NameOf(it.Result()))) + res = append(res, quad.ToString(qs.NameOf(it.Result()))) } require.Nil(t, it.Err()) sort.Strings(res) @@ -168,7 +168,7 @@ func TestLoadOneQuad(t testing.TB, gen testutil.DatabaseFunc, c *Config) { w := testutil.MakeWriter(t, qs, opts) - q := quad.MakeRaw( + q := quad.Make( "Something", "points_to", "Something Else", @@ -177,13 +177,12 @@ func TestLoadOneQuad(t testing.TB, gen testutil.DatabaseFunc, c *Config) { err := w.AddQuad(q) require.NoError(t, err) - for _, pq := range []string{"Something", "points_to", "Something Else", "context"} { - tok := qs.ValueOf(quad.Raw(pq)) + for _, pq := range []quad.String{"Something", "points_to", "Something Else", "context"} { + tok := qs.ValueOf(pq) require.NotNil(t, tok, "quad store failed to find value: %q", pq) val := qs.NameOf(tok) require.NotNil(t, val, "quad store failed to decode value: %q", pq) - got := quad.StringOf(val) - require.Equal(t, pq, got, "quad store failed to roundtrip value: %q", pq) + require.Equal(t, pq, val, "quad store failed to roundtrip value: %q", pq) } exp := int64(5) if c.NoPrimitives { @@ -213,22 +212,22 @@ func TestSizes(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { require.Equal(t, exp, qs.Size(), "Unexpected quadstore size") if qss, ok := qs.(ValueSizer); ok { - s := qss.SizeOf(qs.ValueOf(quad.Raw("B"))) + s := qss.SizeOf(qs.ValueOf(quad.String("B"))) require.Equal(t, int64(5), s, "Unexpected quadstore value size") } - err = w.RemoveQuad(quad.MakeRaw( + err = w.RemoveQuad(quad.Make( "A", "follows", "B", - "", + nil, )) require.NoError(t, err) - err = w.RemoveQuad(quad.MakeRaw( + err = w.RemoveQuad(quad.Make( "A", "follows", "B", - "", + nil, )) require.True(t, graph.IsQuadNotExist(err)) if !conf.SkipSizeCheckAfterDelete { @@ -242,7 +241,7 @@ func TestSizes(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { } if qss, ok := qs.(ValueSizer); ok { - s := qss.SizeOf(qs.ValueOf(quad.Raw("B"))) + s := qss.SizeOf(qs.ValueOf(quad.String("B"))) require.Equal(t, int64(4), s, "Unexpected quadstore value size") } } @@ -285,7 +284,7 @@ func TestIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { } sort.Strings(expect) for i := 0; i < 2; i++ { - got := IteratedRawStrings(t, qs, it) + got := IteratedStrings(t, qs, it) sort.Strings(got) require.Equal(t, expect, got, "Unexpected iterated result on repeat %d", i) it.Reset() @@ -362,11 +361,11 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { } // Subject iterator. - it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("C"))) + it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("C"))) expectIteratedQuads(it, []quad.Quad{ - quad.MakeRaw("C", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), + quad.Make("C", "follows", "B", nil), + quad.Make("C", "follows", "D", nil), }) it.Reset() @@ -376,65 +375,65 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { ) expectIteratedQuads(and, []quad.Quad{ - quad.MakeRaw("C", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), + quad.Make("C", "follows", "B", nil), + quad.Make("C", "follows", "D", nil), }) // Object iterator. - it = qs.QuadIterator(quad.Object, qs.ValueOf(quad.Raw("F"))) + it = qs.QuadIterator(quad.Object, qs.ValueOf(quad.String("F"))) expectIteratedQuads(it, []quad.Quad{ - quad.MakeRaw("B", "follows", "F", ""), - quad.MakeRaw("E", "follows", "F", ""), + quad.Make("B", "follows", "F", nil), + quad.Make("E", "follows", "F", nil), }) and = iterator.NewAnd(qs, - qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("B"))), + qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))), it, ) expectIteratedQuads(and, []quad.Quad{ - quad.MakeRaw("B", "follows", "F", ""), + quad.Make("B", "follows", "F", nil), }) // Predicate iterator. - it = qs.QuadIterator(quad.Predicate, qs.ValueOf(quad.Raw("status"))) + it = qs.QuadIterator(quad.Predicate, qs.ValueOf(quad.String("status"))) expectIteratedQuads(it, []quad.Quad{ - quad.MakeRaw("B", "status", "cool", "status_graph"), - quad.MakeRaw("D", "status", "cool", "status_graph"), - quad.MakeRaw("G", "status", "cool", "status_graph"), + quad.Make("B", "status", "cool", "status_graph"), + quad.Make("D", "status", "cool", "status_graph"), + quad.Make("G", "status", "cool", "status_graph"), }) // Label iterator. - it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.Raw("status_graph"))) + it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.String("status_graph"))) expectIteratedQuads(it, []quad.Quad{ - quad.MakeRaw("B", "status", "cool", "status_graph"), - quad.MakeRaw("D", "status", "cool", "status_graph"), - quad.MakeRaw("G", "status", "cool", "status_graph"), + quad.Make("B", "status", "cool", "status_graph"), + quad.Make("D", "status", "cool", "status_graph"), + quad.Make("G", "status", "cool", "status_graph"), }) it.Reset() // Order is important and = iterator.NewAnd(qs, - qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("B"))), + qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))), it, ) expectIteratedQuads(and, []quad.Quad{ - quad.MakeRaw("B", "status", "cool", "status_graph"), + quad.Make("B", "status", "cool", "status_graph"), }) it.Reset() // Order is important and = iterator.NewAnd(qs, it, - qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("B"))), + qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))), ) expectIteratedQuads(and, []quad.Quad{ - quad.MakeRaw("B", "status", "cool", "status_graph"), + quad.Make("B", "status", "cool", "status_graph"), }) } @@ -449,11 +448,11 @@ func TestDeleteQuad(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { it := qs.QuadIterator(quad.Subject, vn) ExpectIteratedQuads(t, qs, it, []quad.Quad{ - quad.MakeRaw("E", "follows", "F", ""), + quad.Make("E", "follows", "F", nil), }, false) it.Close() - err := w.RemoveQuad(quad.MakeRaw("E", "follows", "F", "")) + err := w.RemoveQuad(quad.Make("E", "follows", "F", nil)) require.NoError(t, err) it = qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("E"))) @@ -462,16 +461,16 @@ func TestDeleteQuad(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { it = qs.QuadsAllIterator() ExpectIteratedQuads(t, qs, it, []quad.Quad{ - quad.MakeRaw("A", "follows", "B", ""), - quad.MakeRaw("C", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), - quad.MakeRaw("D", "follows", "B", ""), - quad.MakeRaw("B", "follows", "F", ""), - quad.MakeRaw("F", "follows", "G", ""), - quad.MakeRaw("D", "follows", "G", ""), - quad.MakeRaw("B", "status", "cool", "status_graph"), - quad.MakeRaw("D", "status", "cool", "status_graph"), - quad.MakeRaw("G", "status", "cool", "status_graph"), + quad.Make("A", "follows", "B", nil), + quad.Make("C", "follows", "B", nil), + quad.Make("C", "follows", "D", nil), + quad.Make("D", "follows", "B", nil), + quad.Make("B", "follows", "F", nil), + quad.Make("F", "follows", "G", nil), + quad.Make("D", "follows", "G", nil), + quad.Make("B", "status", "cool", "status_graph"), + quad.Make("D", "status", "cool", "status_graph"), + quad.Make("G", "status", "cool", "status_graph"), }, true) it.Close() } @@ -489,12 +488,12 @@ func TestDeletedFromIterator(t testing.TB, gen testutil.DatabaseFunc, conf *Conf it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("E"))) ExpectIteratedQuads(t, qs, it, []quad.Quad{ - quad.MakeRaw("E", "follows", "F", ""), + quad.Make("E", "follows", "F", nil), }, false) it.Reset() - w.RemoveQuad(quad.MakeRaw("E", "follows", "F", "")) + w.RemoveQuad(quad.Make("E", "follows", "F", nil)) ExpectIteratedQuads(t, qs, it, nil, false) } @@ -552,7 +551,6 @@ func TestLoadTypedQuads(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { assert.True(t, eq.Equal(got), "Failed to roundtrip %q (%T), got %q (%T)", pq, pq, got, got) } else { assert.Equal(t, pq, got, "Failed to roundtrip %q (%T)", pq, pq) - assert.Equal(t, pq, qs.NameOf(qs.ValueOf(quad.Raw(pq.String()))), "Failed to exchange raw value %q (%T)", pq, pq) } // check if we can get received value again (hash roundtrip) got2 := qs.NameOf(qs.ValueOf(got)) @@ -605,10 +603,10 @@ func TestAddRemove(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { // Add more quads, some conflicts err := w.AddQuadSet([]quad.Quad{ - quad.MakeRaw("A", "follows", "B", ""), // duplicate - quad.MakeRaw("F", "follows", "B", ""), - quad.MakeRaw("C", "follows", "D", ""), // duplicate - quad.MakeRaw("X", "follows", "B", ""), + quad.Make("A", "follows", "B", nil), // duplicate + quad.Make("F", "follows", "B", nil), + quad.Make("C", "follows", "D", nil), // duplicate + quad.Make("X", "follows", "B", nil), }) assert.Nil(t, err, "AddQuadSet failed") @@ -636,7 +634,7 @@ func TestAddRemove(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { ExpectIteratedRawStrings(t, qs, all, expect) // Remove quad - toRemove := quad.MakeRaw("X", "follows", "B", "") + toRemove := quad.Make("X", "follows", "B", nil) err = w.RemoveQuad(toRemove) require.Nil(t, err, "RemoveQuad failed") err = w.RemoveQuad(toRemove) @@ -714,7 +712,7 @@ func TestIteratorsAndNextResultOrderA(t testing.TB, gen testutil.DatabaseFunc, c expect = []string{"B", "D"} ) for { - got = append(got, quad.StringOf(qs.NameOf(all.Result()))) + got = append(got, quad.ToString(qs.NameOf(all.Result()))) if !outerAnd.NextPath(ctx) { break } diff --git a/graph/graphtest/integration.go b/graph/graphtest/integration.go index 7976404b7..968d01543 100644 --- a/graph/graphtest/integration.go +++ b/graph/graphtest/integration.go @@ -48,6 +48,9 @@ const ( ) func TestIntegration(t *testing.T, gen testutil.DatabaseFunc, force bool) { + if testing.Short() { + t.SkipNow() + } if !force && os.Getenv("RUN_INTEGRATION") != "true" { t.Skip("skipping integration tests; set RUN_INTEGRATION=true to run them") } diff --git a/graph/iterator/recursive_test.go b/graph/iterator/recursive_test.go index 062ba24d6..e0c78136d 100644 --- a/graph/iterator/recursive_test.go +++ b/graph/iterator/recursive_test.go @@ -61,7 +61,7 @@ func TestRecursiveNext(t *testing.T) { var got []string for r.Next(ctx) { - got = append(got, qs.NameOf(r.Result()).String()) + got = append(got, quad.ToString(qs.NameOf(r.Result()))) } sort.Strings(expected) sort.Strings(got) @@ -105,11 +105,11 @@ func TestRecursiveNextPath(t *testing.T) { for r.Next(ctx) { res := make(map[string]graph.Value) r.TagResults(res) - got = append(got, qs.NameOf(res["person"]).String()) + got = append(got, quad.ToString(qs.NameOf(res["person"]))) for r.NextPath(ctx) { res := make(map[string]graph.Value) r.TagResults(res) - got = append(got, qs.NameOf(res["person"]).String()) + got = append(got, quad.ToString(qs.NameOf(res["person"]))) } } sort.Strings(expected) diff --git a/graph/iterator/regex.go b/graph/iterator/regex.go index f1999dec6..f9475ffc6 100644 --- a/graph/iterator/regex.go +++ b/graph/iterator/regex.go @@ -70,8 +70,6 @@ func (it *Regex) testRegex(val graph.Value) bool { // Type switch to avoid coercing and testing numeric types v := it.qs.NameOf(val) switch v := v.(type) { - case quad.Raw: - return it.re.MatchString(string(v)) case quad.String: return it.re.MatchString(string(v)) case quad.TypedString: diff --git a/graph/iterator/value_comparison.go b/graph/iterator/value_comparison.go index b42447d0c..03da10609 100644 --- a/graph/iterator/value_comparison.go +++ b/graph/iterator/value_comparison.go @@ -80,8 +80,6 @@ func (it *Comparison) Operator() Operator { return it.op } func (it *Comparison) doComparison(val graph.Value) bool { qval := it.qs.NameOf(val) switch cVal := it.val.(type) { - case quad.Raw: - return RunStrOp(quad.StringOf(qval), it.op, string(cVal)) case quad.Int: if cVal2, ok := qval.(quad.Int); ok { return RunIntOp(cVal2, it.op, cVal) diff --git a/graph/leveldb/leveldb_test.go b/graph/leveldb/leveldb_test.go index df26700d2..5d60dc697 100644 --- a/graph/leveldb/leveldb_test.go +++ b/graph/leveldb/leveldb_test.go @@ -109,7 +109,7 @@ func TestLoadDatabase(t *testing.T) { t.Fatal("Failed to add quad:", err) } for _, pq := range []string{"Something", "points_to", "Something Else", "context"} { - if got := quad.StringOf(qs.NameOf(qs.ValueOf(quad.Raw(pq)))); got != pq { + if got := quad.ToString(qs.NameOf(qs.ValueOf(quad.Raw(pq)))); got != pq { t.Errorf("Failed to roundtrip %q, got:%q expect:%q", pq, got, pq) } } diff --git a/graph/memstore/quadstore_test.go b/graph/memstore/quadstore_test.go index 6296b26f6..cc9113341 100644 --- a/graph/memstore/quadstore_test.go +++ b/graph/memstore/quadstore_test.go @@ -140,7 +140,7 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) { expect = []string{"B", "D"} ) for { - got = append(got, quad.StringOf(qs.NameOf(all.Result()))) + got = append(got, quad.ToString(qs.NameOf(all.Result()))) if !outerAnd.NextPath(ctx) { break } @@ -191,11 +191,11 @@ func TestRemoveQuad(t *testing.T) { ctx := context.TODO() qs, w, _ := makeTestStore(simpleGraph) - err := w.RemoveQuad(quad.MakeRaw( + err := w.RemoveQuad(quad.Make( "E", "follows", "F", - "", + nil, )) if err != nil { @@ -226,16 +226,16 @@ func TestTransaction(t *testing.T) { size := qs.Size() tx := graph.NewTransaction() - tx.AddQuad(quad.MakeRaw( + tx.AddQuad(quad.Make( "E", "follows", "G", - "")) - tx.RemoveQuad(quad.MakeRaw( + nil)) + tx.RemoveQuad(quad.Make( "Non", "existent", "quad", - "")) + nil)) err := w.ApplyTransaction(tx) if err == nil { diff --git a/graph/mongo/quadstore.go b/graph/mongo/quadstore.go index 4a1532de3..e9a60c6a6 100644 --- a/graph/mongo/quadstore.go +++ b/graph/mongo/quadstore.go @@ -378,8 +378,6 @@ func toMongoValue(v quad.Value) value { return nil } switch d := v.(type) { - case quad.Raw: - return string(d) // compatibility case quad.String: return mongoString{Value: string(d)} case quad.IRI: diff --git a/graph/nosql/quadstore.go b/graph/nosql/quadstore.go index dfd3299f0..7a9e7a0a8 100644 --- a/graph/nosql/quadstore.go +++ b/graph/nosql/quadstore.go @@ -136,7 +136,6 @@ const ( fldBNode = "bnode" fldType = "type" fldLang = "lang" - fldRaw = "raw" fldValInt = "int" fldValFloat = "float" fldValBool = "bool" @@ -386,8 +385,6 @@ func toDocumentValue(v quad.Value) Document { switch d := v.(type) { case quad.String: doc = Document{fldValData: String(d)} - case quad.Raw: - doc = Document{fldValData: String(d), fldRaw: Bool(true)} case quad.IRI: doc = Document{fldValData: String(d), fldIRI: Bool(true)} case quad.BNode: @@ -496,8 +493,6 @@ func toQuadValue(d Document) (quad.Value, error) { return quad.IRI(vs), nil } else if ok, _ := d[fldBNode].(Bool); ok { return quad.BNode(vs), nil - } else if ok, _ := d[fldRaw].(Bool); ok { - return quad.Raw(vs), nil } else if typ, ok := d[fldType].(String); ok { return quad.TypedString{Value: quad.String(vs), Type: quad.IRI(typ)}, nil } else if typ, ok := d[fldLang].(String); ok { diff --git a/graph/nosql/shapes.go b/graph/nosql/shapes.go index b1c7ab0cd..af582f534 100644 --- a/graph/nosql/shapes.go +++ b/graph/nosql/shapes.go @@ -93,7 +93,6 @@ func toFieldFilter(c shape.Comparison) ([]FieldFilter, bool) { {Path: fieldPath(fldValData), Filter: op, Value: String(v)}, {Path: fieldPath(fldIRI), Filter: NotEqual, Value: Bool(true)}, {Path: fieldPath(fldBNode), Filter: NotEqual, Value: Bool(true)}, - {Path: fieldPath(fldRaw), Filter: NotEqual, Value: Bool(true)}, } case quad.IRI: filters = []FieldFilter{ diff --git a/graph/transaction_test.go b/graph/transaction_test.go index 7c5eb05f2..e66c01e3d 100644 --- a/graph/transaction_test.go +++ b/graph/transaction_test.go @@ -12,50 +12,50 @@ func TestTransaction(t *testing.T) { // simples adds / removes tx = NewTransaction() - tx.AddQuad(quad.MakeRaw("E", "follows", "F", "")) - tx.AddQuad(quad.MakeRaw("F", "follows", "G", "")) - tx.RemoveQuad(quad.MakeRaw("A", "follows", "Z", "")) + tx.AddQuad(quad.Make("E", "follows", "F", nil)) + tx.AddQuad(quad.Make("F", "follows", "G", nil)) + tx.RemoveQuad(quad.Make("A", "follows", "Z", nil)) if len(tx.Deltas) != 3 { t.Errorf("Expected 3 Deltas, have %d delta(s)", len(tx.Deltas)) } // add, remove -> nothing tx = NewTransaction() - tx.AddQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) + tx.AddQuad(quad.Make("E", "follows", "G", nil)) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) if len(tx.Deltas) != 0 { t.Errorf("Expected [add, remove]->[], have %d Deltas", len(tx.Deltas)) } // remove, add -> nothing tx = NewTransaction() - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.AddQuad(quad.MakeRaw("E", "follows", "G", "")) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) + tx.AddQuad(quad.Make("E", "follows", "G", nil)) if len(tx.Deltas) != 0 { t.Errorf("Expected [add, remove]->[], have %d delta(s)", len(tx.Deltas)) } // add x2 -> add x1 tx = NewTransaction() - tx.AddQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.AddQuad(quad.MakeRaw("E", "follows", "G", "")) + tx.AddQuad(quad.Make("E", "follows", "G", nil)) + tx.AddQuad(quad.Make("E", "follows", "G", nil)) if len(tx.Deltas) != 1 { t.Errorf("Expected [add, add]->[add], have %d delta(s)", len(tx.Deltas)) } // remove x2 -> remove x1 tx = NewTransaction() - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) if len(tx.Deltas) != 1 { t.Errorf("Expected [remove, remove]->[remove], have %d delta(s)", len(tx.Deltas)) } // add, remove x2 -> remove x1 tx = NewTransaction() - tx.AddQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) - tx.RemoveQuad(quad.MakeRaw("E", "follows", "G", "")) + tx.AddQuad(quad.Make("E", "follows", "G", nil)) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) + tx.RemoveQuad(quad.Make("E", "follows", "G", nil)) if len(tx.Deltas) != 1 { t.Errorf("Expected [add, remove, remove]->[remove], have %d delta(s)", len(tx.Deltas)) } diff --git a/quad/json/json_test.go b/quad/json/json_test.go index 63dcef0dc..662c98c26 100644 --- a/quad/json/json_test.go +++ b/quad/json/json_test.go @@ -121,7 +121,7 @@ var writeTests = []struct { quad.MakeRaw("foo", "bar", `"baz"`, ""), }, expect: `[ - {"subject":"foo","predicate":"bar","object":"\"baz\""} + {"subject":"foo","predicate":"bar","object":"baz"} ] `, err: nil, diff --git a/quad/nquads/nquads.go b/quad/nquads/nquads.go index b54e28a18..39e12e69e 100644 --- a/quad/nquads/nquads.go +++ b/quad/nquads/nquads.go @@ -185,7 +185,7 @@ func unEscape(r []rune, spec int, isQuoted, isEscaped bool) quad.Value { if isQuoted { return quad.String(val) } - return quad.Raw(val) + return quad.Raw(string(val)) } if sp[0] == '@' { return quad.LangString{ @@ -205,7 +205,7 @@ func unEscape(r []rune, spec int, isQuoted, isEscaped bool) quad.Value { } return v } - return quad.Raw(raw) + return quad.Raw(string(raw)) } func unEscapeRaw(r []rune, isEscaped bool) quad.Value { diff --git a/quad/nquads/raw_test.go b/quad/nquads/raw_test.go index facc11a0c..f6a77ec4b 100644 --- a/quad/nquads/raw_test.go +++ b/quad/nquads/raw_test.go @@ -537,7 +537,7 @@ func TestRDFWorkingGroupSuitRaw(t *testing.T) { func TestUnescapeRaw(t *testing.T) { for _, test := range escapeSequenceTests { got := unEscapeRaw([]rune(test.input), true) - if got == nil || got.String() != test.expect { + if got == nil || quad.ToString(got) != test.expect { t.Errorf("Failed to properly unescape %q, got:%q expect:%q", test.input, got, test.expect) } } diff --git a/quad/nquads/typed_test.go b/quad/nquads/typed_test.go index 9c8c8c445..08cb60271 100644 --- a/quad/nquads/typed_test.go +++ b/quad/nquads/typed_test.go @@ -828,7 +828,7 @@ var escapeSequenceTests = []struct { func TestUnescape(t *testing.T) { for _, test := range escapeSequenceTests { got := unEscape([]rune(test.input), -1, false, true) - if got == nil || got.String() != test.expect { + if got == nil || quad.ToString(got) != test.expect { t.Errorf("Failed to properly unescape %q, got:%q expect:%q", test.input, got, test.expect) } } diff --git a/quad/pquads/quads.go b/quad/pquads/quads.go index bfff1e65c..599c89fd7 100644 --- a/quad/pquads/quads.go +++ b/quad/pquads/quads.go @@ -15,8 +15,8 @@ func MakeValue(qv quad.Value) *Value { return nil } switch v := qv.(type) { - case quad.Raw: - return &Value{&Value_Raw{[]byte(v)}} + //case quad.Raw: + // return &Value{&Value_Raw{[]byte(v)}} case quad.String: return &Value{&Value_Str{string(v)}} case quad.IRI: @@ -79,7 +79,7 @@ func (m *Value) ToNative() (qv quad.Value) { } switch v := m.Value.(type) { case *Value_Raw: - return quad.Raw(v.Raw) + return quad.StringToValue(string(v.Raw)) case *Value_Str: return quad.String(v.Str) case *Value_Iri: @@ -188,22 +188,22 @@ func (m *Quad) ToNative() (q quad.Quad) { if m.SubjectValue != nil { q.Subject = m.SubjectValue.ToNative() } else if m.Subject != "" { - q.Subject = quad.Raw(m.Subject) + q.Subject = quad.StringToValue(m.Subject) } if m.PredicateValue != nil { q.Predicate = m.PredicateValue.ToNative() } else if m.Predicate != "" { - q.Predicate = quad.Raw(m.Predicate) + q.Predicate = quad.StringToValue(m.Predicate) } if m.ObjectValue != nil { q.Object = m.ObjectValue.ToNative() } else if m.Object != "" { - q.Object = quad.Raw(m.Object) + q.Object = quad.StringToValue(m.Object) } if m.LabelValue != nil { q.Label = m.LabelValue.ToNative() } else if m.Label != "" { - q.Label = quad.Raw(m.Label) + q.Label = quad.StringToValue(m.Label) } return } @@ -250,19 +250,19 @@ func (m *WireQuad) ToNative() (q quad.Quad) { func (m *Quad) Upgrade() { if m.SubjectValue == nil { - m.SubjectValue = MakeValue(quad.Raw(m.Subject)) + m.SubjectValue = MakeValue(quad.StringToValue(m.Subject)) m.Subject = "" } if m.PredicateValue == nil { - m.PredicateValue = MakeValue(quad.Raw(m.Predicate)) + m.PredicateValue = MakeValue(quad.StringToValue(m.Predicate)) m.Predicate = "" } if m.ObjectValue == nil { - m.ObjectValue = MakeValue(quad.Raw(m.Object)) + m.ObjectValue = MakeValue(quad.StringToValue(m.Object)) m.Object = "" } if m.LabelValue == nil && m.Label != "" { - m.LabelValue = MakeValue(quad.Raw(m.Label)) + m.LabelValue = MakeValue(quad.StringToValue(m.Label)) m.Label = "" } } diff --git a/quad/quad.go b/quad/quad.go index ef212d0b0..0b6861e43 100644 --- a/quad/quad.go +++ b/quad/quad.go @@ -66,18 +66,20 @@ func Make(subject, predicate, object, label interface{}) (q Quad) { } // MakeRaw creates a quad with provided raw values (nquads-escaped). +// +// Deprecated: use Make pr MakeIRI instead. func MakeRaw(subject, predicate, object, label string) (q Quad) { if subject != "" { - q.Subject = Raw(subject) + q.Subject = StringToValue(subject) } if predicate != "" { - q.Predicate = Raw(predicate) + q.Predicate = StringToValue(predicate) } if object != "" { - q.Object = Raw(object) + q.Object = StringToValue(object) } if label != "" { - q.Label = Raw(label) + q.Label = StringToValue(label) } return } @@ -121,12 +123,12 @@ type rawQuad struct { func (q Quad) MarshalJSON() ([]byte, error) { rq := rawQuad{ - Subject: q.Subject.String(), - Predicate: q.Predicate.String(), - Object: q.Object.String(), + Subject: ToString(q.Subject), + Predicate: ToString(q.Predicate), + Object: ToString(q.Object), } if q.Label != nil { - rq.Label = q.Label.String() + rq.Label = ToString(q.Label) } return json.Marshal(rq) } diff --git a/quad/value.go b/quad/value.go index e6dc8f948..14d28da01 100644 --- a/quad/value.go +++ b/quad/value.go @@ -16,8 +16,7 @@ import ( ) func IsValidValue(v Value) bool { - rv, ok := v.(Raw) - return v != nil && (!ok || rv != "") + return v != nil } // Value is a type used by all quad directions. @@ -125,6 +124,8 @@ func StringToValue(v string) Value { if len(v) > 2 { if v[0] == '<' && v[len(v)-1] == '>' { return IRI(v[1 : len(v)-1]) + } else if v[0] == '"' && v[len(v)-1] == '"' { + return String(v[1 : len(v)-1]) } else if v[:2] == "_:" { return BNode(v[2:]) } @@ -132,11 +133,20 @@ func StringToValue(v string) Value { return String(v) } -// Raw is a Turtle/NQuads-encoded value. -type Raw string +// ToString casts a values to String or falls back to StringOf. +func ToString(v Value) string { + if s, ok := v.(String); ok { + return string(s) + } + return StringOf(v) +} -func (s Raw) String() string { return string(s) } -func (s Raw) Native() interface{} { return s } +// Raw is a Turtle/NQuads-encoded value. +// +// Deprecated: use IRI or String instead. +func Raw(s string) Value { + return StringToValue(s) +} // String is an RDF string value (ex: "name"). type String string diff --git a/quad/value_test.go b/quad/value_test.go index 86f54b429..7275feb79 100644 --- a/quad/value_test.go +++ b/quad/value_test.go @@ -9,7 +9,6 @@ var hashCases = []struct { val Value hash string }{ - {Raw(`abc`), "a9993e364706816aba3e25717850c26c9cd0d89d"}, {String(`abc`), "b87f4bf9b7b07f594430548b653b4998e4b40402"}, {Raw(`"abc"`), "b87f4bf9b7b07f594430548b653b4998e4b40402"}, {BNode(`abc`), "3603f98d3203a037ffa6b8780b97ef8bc964fd94"}, diff --git a/query/sexp/parser_test.go b/query/sexp/parser_test.go index 29475305b..6fd679f8c 100644 --- a/query/sexp/parser_test.go +++ b/query/sexp/parser_test.go @@ -120,7 +120,7 @@ func TestTreeConstraintTagParse(t *testing.T) { } tags := make(map[string]graph.Value) it.TagResults(tags) - if qs.NameOf(tags["$a"]).String() != "food" { + if quad.ToString(qs.NameOf(tags["$a"])) != "food" { t.Errorf("Got %s, expected food", qs.NameOf(tags["$a"])) }