Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when exporting a predicate to the schema. #3700

Merged
merged 3 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions worker/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"path/filepath"
"strings"
"time"
"unicode"

"github.com/golang/glog"
"github.com/pkg/errors"
Expand Down Expand Up @@ -88,20 +87,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\""
Expand Down Expand Up @@ -293,16 +278,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('[')
Expand Down
6 changes: 3 additions & 3 deletions worker/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestToSchema(t *testing.T) {
Lang: true,
},
},
expected: "Alice:string @reverse @count @lang @upsert . \n",
expected: "<Alice>:string @reverse @count @lang @upsert . \n",
},
{
skv: &skv{
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestToSchema(t *testing.T) {
Lang: true,
},
},
expected: "data_base:string @lang . \n",
expected: "<data_base>:string @lang . \n",
},
{
skv: &skv{
Expand All @@ -460,7 +460,7 @@ func TestToSchema(t *testing.T) {
Lang: true,
},
},
expected: "data.base:string @lang . \n",
expected: "<data.base>:string @lang . \n",
},
}
for _, testCase := range testCases {
Expand Down