Skip to content

Commit

Permalink
fix(Query): Fix incorrect RDF response. (#7017)
Browse files Browse the repository at this point in the history
* remove <X> <uid> <X> type of triplets from the output

* fix output for recurse queries

* fix for recurse queries

* fix test

* add Test for ignoring uid

* minor modification

* fix solution for recurse
  • Loading branch information
minhaj-shakeel authored Dec 7, 2020
1 parent 294ff8a commit 17df3f5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
20 changes: 15 additions & 5 deletions query/outputrdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ func (b *rdfBuilder) castToRDF(sg *SubGraph) error {

// rdfForSubgraph generates RDF and appends to the output parameter.
func (b *rdfBuilder) rdfForSubgraph(sg *SubGraph) error {
// handle the case of recurse queries
// Do not generate RDF if all the children of sg null uidMatrix
nonNullChild := false
for _, ch := range sg.Children {
if len(ch.uidMatrix) != 0 {
nonNullChild = true
}
}

if len(sg.Children) > 0 && !nonNullChild {
return nil
}

for i, uid := range sg.SrcUIDs.Uids {
if sg.Params.IgnoreResult {
// Skip ignored values.
Expand All @@ -101,7 +114,7 @@ func (b *rdfBuilder) rdfForSubgraph(sg *SubGraph) error {
case len(sg.counts) > 0:
// Add count rdf.
b.rdfForCount(uid, sg.counts[i], sg)
case i < len(sg.uidMatrix) && len(sg.uidMatrix[i].Uids) != 0:
case i < len(sg.uidMatrix) && len(sg.uidMatrix[i].Uids) != 0 && len(sg.Children) > 0:
// Add posting list relation.
b.rdfForUIDList(uid, sg.uidMatrix[i], sg)
case i < len(sg.valueMatrix):
Expand Down Expand Up @@ -154,11 +167,8 @@ func (b *rdfBuilder) rdfForUIDList(subject uint64, list *pb.List, sg *SubGraph)
}

// rdfForValueList returns rdf for the value list.
// Ignore RDF's for the attirbute `uid`.
func (b *rdfBuilder) rdfForValueList(subject uint64, valueList *pb.ValueList, attr string) {
if attr == "uid" {
b.writeRDF(subject, []byte(attr), x.ToHex(subject, true))
return
}
for _, destValue := range valueList.Values {
val, err := convertWithBestEffort(destValue, attr)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions query/rdf_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,38 @@ func TestRDFIngoreReflex(t *testing.T) {
"ignorereflex directive is not supported in the rdf output format")
}

func TestRDFRecurse(t *testing.T) {
query := `
{
me(func: anyofterms(name, "Michonne Rick Daryl")) @recurse(depth: 1, loop: true) {
name
friend
}
}`
rdf, err := processQueryRDF(context.Background(), t, query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x19> <name> "Daryl Dixon" .
`)
}

func TestRDFIgnoreUid(t *testing.T) {
query := `
{
me(func: anyofterms(name, "Michonne Rick Daryl")) {
uid
name
}
}`
rdf, err := processQueryRDF(context.Background(), t, query)
require.NoError(t, err)
require.Equal(t, rdf, `<0x1> <name> "Michonne" .
<0x17> <name> "Rick Grimes" .
<0x19> <name> "Daryl Dixon" .
`)
}

func TestRDFCheckPwd(t *testing.T) {
query := `
{
Expand Down

0 comments on commit 17df3f5

Please sign in to comment.