From 02a722bd4ff8097368929637148de948039e7fef Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Mon, 22 Jul 2019 15:00:59 -0700 Subject: [PATCH 1/3] Fix error when importing a predicate to the schema. The current logic only adds the '<' and '>' characters around the predicate list if it has something other than numbers and letters. However, this logic is faulty since a predicate consisting of only numbers needs to have the surrounding brackets to be properly parsed. This change removes that logic and adds the surrounding brackets to all predicates for simplicity and correctness. --- worker/export.go | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/worker/export.go b/worker/export.go index 94077e0255b..858b3268168 100644 --- a/worker/export.go +++ b/worker/export.go @@ -88,20 +88,6 @@ var rdfTypeMap = map[types.TypeID]string{ types.PasswordID: "xs:password", } -// Having '<' and '>' around all predicates makes the exported schema harder -// for humans to look at, so only put them on predicates containing "exotic" -// characters (i.e. ones not in this list). -var predNonSpecialChars = unicode.RangeTable{ - R16: []unicode.Range16{ - // Ranges must be in order. - {'.', '.', 1}, - {'0', '9', 1}, - {'A', 'Z', 1}, - {'_', '_', 1}, - {'a', 'z', 1}, - }, -} - // UIDs like 0x1 look weird but 64-bit ones like 0x0000000000000001 are too long. var uidFmtStrRdf = "<0x%x>" var uidFmtStrJson = "\"0x%x\"" @@ -293,16 +279,9 @@ func (e *exporter) toRDF() (*bpb.KVList, error) { func toSchema(attr string, update pb.SchemaUpdate) (*bpb.KVList, error) { // bytes.Buffer never returns error for any of the writes. So, we don't need to check them. var buf bytes.Buffer - isSpecial := func(r rune) bool { - return !(unicode.In(r, &predNonSpecialChars)) - } - if strings.IndexFunc(attr, isSpecial) >= 0 { - buf.WriteRune('<') - buf.WriteString(attr) - buf.WriteRune('>') - } else { - buf.WriteString(attr) - } + buf.WriteRune('<') + buf.WriteString(attr) + buf.WriteRune('>') buf.WriteByte(':') if update.List { buf.WriteRune('[') From 09ea48dff9cf3c3c30abaa6be323f38ac51cd692 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Mon, 22 Jul 2019 15:08:46 -0700 Subject: [PATCH 2/3] Remove unused import. --- worker/export.go | 1 - 1 file changed, 1 deletion(-) diff --git a/worker/export.go b/worker/export.go index 858b3268168..230b9548bfd 100644 --- a/worker/export.go +++ b/worker/export.go @@ -27,7 +27,6 @@ import ( "path/filepath" "strings" "time" - "unicode" "github.com/golang/glog" "github.com/pkg/errors" From 32024a37cd48a4855c7fd33f79173aab1261dbea Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Mon, 22 Jul 2019 17:48:35 -0700 Subject: [PATCH 3/3] Fix tests --- worker/export_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker/export_test.go b/worker/export_test.go index 848ba70ba6d..c9d0cda0a0f 100644 --- a/worker/export_test.go +++ b/worker/export_test.go @@ -370,7 +370,7 @@ func TestToSchema(t *testing.T) { Lang: true, }, }, - expected: "Alice:string @reverse @count @lang @upsert . \n", + expected: ":string @reverse @count @lang @upsert . \n", }, { skv: &skv{ @@ -445,7 +445,7 @@ func TestToSchema(t *testing.T) { Lang: true, }, }, - expected: "data_base:string @lang . \n", + expected: ":string @lang . \n", }, { skv: &skv{ @@ -460,7 +460,7 @@ func TestToSchema(t *testing.T) { Lang: true, }, }, - expected: "data.base:string @lang . \n", + expected: ":string @lang . \n", }, } for _, testCase := range testCases {