From 1f3a6c4fd6f25292f500195de555c4e195759a5d Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Mon, 30 Nov 2020 18:24:57 +0530 Subject: [PATCH 1/7] remove type of triplets from the output --- query/outputrdf.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/query/outputrdf.go b/query/outputrdf.go index d39834681b9..3d915acffc8 100644 --- a/query/outputrdf.go +++ b/query/outputrdf.go @@ -154,11 +154,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 { From 005a26bc15fbe07af111930ed3a01e328f5cf6b2 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Tue, 1 Dec 2020 10:44:20 +0530 Subject: [PATCH 2/7] fix output for recurse queries --- query/outputrdf.go | 2 +- query/rdf_result_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/query/outputrdf.go b/query/outputrdf.go index 3d915acffc8..9881c348328 100644 --- a/query/outputrdf.go +++ b/query/outputrdf.go @@ -101,7 +101,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): diff --git a/query/rdf_result_test.go b/query/rdf_result_test.go index e91b5effff6..1808f25a242 100644 --- a/query/rdf_result_test.go +++ b/query/rdf_result_test.go @@ -111,6 +111,21 @@ 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> "Michonne" . + <0x17> "Rick Grimes" . + <0x19> "Daryl Dixon" . +`) +} func TestRDFCheckPwd(t *testing.T) { query := ` { From 99705f3a60ae91237c2d856d6836528c2b30c62f Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Tue, 1 Dec 2020 17:15:02 +0530 Subject: [PATCH 3/7] fix for recurse queries --- query/outputrdf.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/query/outputrdf.go b/query/outputrdf.go index 9881c348328..d311c908f18 100644 --- a/query/outputrdf.go +++ b/query/outputrdf.go @@ -75,6 +75,13 @@ 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 + for _, ch := range sg.Children { + if len(ch.uidMatrix) == 0 { + return nil + } + } + for i, uid := range sg.SrcUIDs.Uids { if sg.Params.IgnoreResult { // Skip ignored values. From 4741b0d0cc290d8a9f8e6e2d702d56d34dd0fcb9 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Tue, 1 Dec 2020 18:08:46 +0530 Subject: [PATCH 4/7] fix test --- query/rdf_result_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/query/rdf_result_test.go b/query/rdf_result_test.go index 1808f25a242..aedefb03bb7 100644 --- a/query/rdf_result_test.go +++ b/query/rdf_result_test.go @@ -122,8 +122,8 @@ func TestRDFRecurse(t *testing.T) { rdf, err := processQueryRDF(context.Background(), t, query) require.NoError(t, err) require.Equal(t, rdf, `<0x1> "Michonne" . - <0x17> "Rick Grimes" . - <0x19> "Daryl Dixon" . +<0x17> "Rick Grimes" . +<0x19> "Daryl Dixon" . `) } func TestRDFCheckPwd(t *testing.T) { From 1745aad55b866d33ec05332520dfca02864be036 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Tue, 1 Dec 2020 18:13:50 +0530 Subject: [PATCH 5/7] add Test for ignoring uid --- query/rdf_result_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/query/rdf_result_test.go b/query/rdf_result_test.go index aedefb03bb7..eb908b423c0 100644 --- a/query/rdf_result_test.go +++ b/query/rdf_result_test.go @@ -126,6 +126,23 @@ func TestRDFRecurse(t *testing.T) { <0x19> "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> "Michonne" . +<0x17> "Rick Grimes" . +<0x19> "Daryl Dixon" . +`) +} + func TestRDFCheckPwd(t *testing.T) { query := ` { From 8ddefd674351ced25918d21d89158abb7825559b Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 2 Dec 2020 10:57:33 +0530 Subject: [PATCH 6/7] minor modification --- query/outputrdf.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/query/outputrdf.go b/query/outputrdf.go index d311c908f18..3212e18fe51 100644 --- a/query/outputrdf.go +++ b/query/outputrdf.go @@ -76,12 +76,18 @@ 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 { - return nil + if len(ch.uidMatrix) != 0 { + nonNullChild = true } } + if nonNullChild { + return nil + } + for i, uid := range sg.SrcUIDs.Uids { if sg.Params.IgnoreResult { // Skip ignored values. From 469866f0d54084c6c40c59fef86893a77f66e517 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 2 Dec 2020 15:44:04 +0530 Subject: [PATCH 7/7] fix solution for recurse --- query/outputrdf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query/outputrdf.go b/query/outputrdf.go index 3212e18fe51..7d07ecfb332 100644 --- a/query/outputrdf.go +++ b/query/outputrdf.go @@ -84,7 +84,7 @@ func (b *rdfBuilder) rdfForSubgraph(sg *SubGraph) error { } } - if nonNullChild { + if len(sg.Children) > 0 && !nonNullChild { return nil }