Skip to content

Commit

Permalink
fix(Mutation): Deeply-nested uid facets (#7455)
Browse files Browse the repository at this point in the history
* only run `parseMapFacets` for JSON scalar arrays
  • Loading branch information
nelsonpecora authored Feb 18, 2021
1 parent 160e922 commit 5049092
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
20 changes: 14 additions & 6 deletions chunker/json_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,22 @@ func (buf *NQuadBuffer) mapToNquads(m map[string]interface{}, op int, parentPred
buf.PushPredHint(pred, pb.Metadata_SINGLE)
case []interface{}:
buf.PushPredHint(pred, pb.Metadata_LIST)
// TODO(Ashish): We need to call this only in case of scalarlist, for other lists
// this can be avoided.
facetsMapSlice, err := parseMapFacets(mf, prefix)
if err != nil {
return mr, err
}

// NOTE: facetsMapSlice should be empty unless this is a scalar list
var facetsMapSlice []map[int]*api.Facet
for idx, item := range v {
if idx == 0 {
switch item.(type) {
case string, float64, json.Number, int64:
var err error
facetsMapSlice, err = parseMapFacets(mf, prefix)
if err != nil {
return mr, err
}
default:
}
}

nq := api.NQuad{
Subject: mr.uid,
Predicate: pred,
Expand Down
32 changes: 32 additions & 0 deletions chunker/json_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,38 @@ func TestNquadsFromJsonFacets4(t *testing.T) {
}
}

func TestNquadsFromJsonFacets5(t *testing.T) {
// Dave has uid facets which should go on the edge between Alice and Dave,
// AND Emily has uid facets which should go on the edge between Dave and Emily
json := `[
{
"name": "Alice",
"friend": [
{
"name": "Dave",
"friend|close": true,
"friend": [
{
"name": "Emily",
"friend|close": true
}
]
}
]
}
]`

nq, err := Parse([]byte(json), SetNquads)
require.NoError(t, err)
require.Equal(t, 5, len(nq))
checkCount(t, nq, "friend", 1)

fastNQ, err := FastParse([]byte(json), SetNquads)
require.NoError(t, err)
require.Equal(t, 5, len(fastNQ))
checkCount(t, fastNQ, "friend", 1)
}

func TestNquadsFromJsonError1(t *testing.T) {
p := Person{
Name: "Alice",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ require (
gopkg.in/DataDog/dd-trace-go.v1 v1.13.1 // indirect
gopkg.in/square/go-jose.v2 v2.3.1
gopkg.in/yaml.v2 v2.2.4
src.techknowlogick.com/xgo v1.0.1-0.20200714173810-96de19c19b14
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -893,5 +893,3 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
sourcegraph.com/sourcegraph/appdash v0.0.0-20180110180208-2cc67fd64755/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k=
src.techknowlogick.com/xgo v1.0.1-0.20200714173810-96de19c19b14 h1:e8P02bjvCTmi33s1MoinoTwMwrCq7+omCS3/3+GZWXA=
src.techknowlogick.com/xgo v1.0.1-0.20200714173810-96de19c19b14/go.mod h1:31CE1YKtDOrKTk9PSnjTpe6YbO6W/0LTYZ1VskL09oU=

0 comments on commit 5049092

Please sign in to comment.