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

Always parse language tag. #3243

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 11 additions & 6 deletions chunker/json/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func handleBasicType(k string, v interface{}, op int, nq *api.NQuad) error {
nq.ObjectValue = &api.Value{Val: &api.Value_IntVal{IntVal: i}}

case string:
// Here we split predicate and lang directive (ex: "name@en"), if needed. With JSON
// mutations that's the only way to send language for a value.
nq.Predicate, nq.Lang = x.PredicateLang(k)

// Default value is considered as S P * deletion.
if v == "" && op == DeleteNquads {
nq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}
Expand Down Expand Up @@ -261,11 +257,16 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
if op == DeleteNquads {
// This corresponds to edge deletion.
if v == nil {
mr.nquads = append(mr.nquads, &api.NQuad{
nq := &api.NQuad{
Subject: mr.uid,
Predicate: pred,
ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}},
})
}
// Here we split predicate and lang directive (ex: "name@en"), if needed. With JSON
// mutations that's the only way to send language for a value.
nq.Predicate, nq.Lang = x.PredicateLang(nq.Predicate)

mr.nquads = append(mr.nquads, nq)
continue
}
}
Expand All @@ -284,6 +285,10 @@ func mapToNquads(m map[string]interface{}, idx *int, op int, parentPred string)
Facets: fts,
}

// Here we split predicate and lang directive (ex: "name@en"), if needed. With JSON
// mutations that's the only way to send language for a value.
nq.Predicate, nq.Lang = x.PredicateLang(nq.Predicate)

if v == nil {
if op == DeleteNquads {
nq.ObjectValue = &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}}
Expand Down
35 changes: 35 additions & 0 deletions chunker/json/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,38 @@ func TestNquadsFromJsonDelete(t *testing.T) {
require.NoError(t, err)
require.Equal(t, nq[0], makeNquadEdge("1000", "friend", "1001"))
}

func TestNquadsFromJsonDeleteStar(t *testing.T) {
json := `{"uid":1000,"name": null}`

nq, err := Parse([]byte(json), DeleteNquads)
require.NoError(t, err)
expected := &api.NQuad{
Subject: "1000",
Predicate: "name",
ObjectValue: &api.Value{
Val: &api.Value_DefaultVal{
DefaultVal: "_STAR_ALL",
},
},
}
require.Equal(t, expected, nq[0])
}

func TestNquadsFromJsonDeleteStarLang(t *testing.T) {
json := `{"uid":1000,"name@es": null}`

nq, err := Parse([]byte(json), DeleteNquads)
require.NoError(t, err)
expected := &api.NQuad{
Subject: "1000",
Predicate: "name",
ObjectValue: &api.Value{
Val: &api.Value_DefaultVal{
DefaultVal: "_STAR_ALL",
},
},
Lang: "es",
}
require.Equal(t, expected, nq[0])
}