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(Query): Fix incorrect RDF response. #7017

Merged
merged 7 commits into from
Dec 7, 2020
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
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