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

anyofterms does not work for facet created by JSON mutation #2867

Closed
birdayz opened this issue Jan 4, 2019 · 5 comments · Fixed by #2885
Closed

anyofterms does not work for facet created by JSON mutation #2867

birdayz opened this issue Jan 4, 2019 · 5 comments · Fixed by #2885
Assignees
Labels
kind/bug Something is broken.

Comments

@birdayz
Copy link

birdayz commented Jan 4, 2019

If you suspect this could be a bug, follow the template.

  • What version of Dgraph are you using?
    tried latest "latest" @ dockerhub and v1.0.12-rc1

  • Have you tried reproducing the issue with latest release?
    Yes

  • What is the hardware spec (RAM, OS)?
    16gb, linux

  • Steps to reproduce the issue (command/config used to run Dgraph).
    Create any facet with a string value.

Query filter it with anyofterms

  • Expected behaviour and actual result.

Expected: i can filter with anyofterms, so e.g. if the value of the facet is "READ" and i filter for anyofterms(permission, "READ WRITE"), i will get a result

Actual:
well, anyofterms does not work. the value is not returned. i can only use eq.
BUT! This is only the case if i performed the mutation for this facet with the JSON API (from dgo). If i do it with the RDF syntax in ratel, it works!

@srfrog
Copy link
Contributor

srfrog commented Jan 4, 2019

Could you post a sample of the query you're trying to run? That will help determine if there's an issue. Thanks.

@birdayz
Copy link
Author

birdayz commented Jan 4, 2019

Qry:

{
  direct(func: uid(0x9c70)) @cascade {
    access.to  @filter(uid(0x9c7c) AND eq(type, "device")) @facets(anyofterms(permission, "READ WRITE"))  @facets(permission,inherit) {
      uid
    }
  }
}

-> no result

If i just use eq WRITE (which is the value set for the facet) it works:

{
  direct(func: uid(0x9c70)) @cascade {
    access.to  @filter(uid(0x9c7c) AND eq(type, "device")) @facets(eq(permission, WRITE))  @facets(permission,inherit) {
      uid
    }
  }
}

-> Result:

    "direct": [
      {
        "access.to": [
          {
            "uid": "0x9c7c",
            "access.to|inherit": true,
            "access.to|permission": "WRITE"
          }
        ],
        "uid": "0x9c70"
      }
    ],

And, still, the first query DOES work, but only if the mutation for the facet was done in ratel in RDF-style.

Code to create the mutation:

	in := User{
		Node: Node{
			UID: request.GetEntityUid(),
		},
		AccessTo: &Resource{
			Node: Node{
				UID: request.GetResourceUid(),
			},
			AccessToPermission: request.GetAction(),
			AccessToInherit:    request.GetInherit(),
		},
	}

	js, err := json.Marshal(&in)
	if err != nil {
		return nil, err
	}

	log.Debug("Run mutation", zap.Any("json", &in))

	_, err = txn.Mutate(ctx, &api.Mutation{
		SetJson:   js,
		CommitNow: true,
	})

Go structs:

type Resource struct {
	Node
	AccessToPermission string `json:"access.to|permission,omitempty"`
	AccessToInherit    bool   `json:"access.to|inherit"`
}
type User struct {
	Node
	Name       string      `json:"name,omitempty"`
	Credential *Credential `json:"credential,omitempty"`
	AccessTo   *Resource   `json:"access.to,omitempty"`
}

Code to create the mutation from ratel in RDF style:
<0x9c70> <access.to> <0x9c7c> (permission="WRITE",inherit=false) .

@danielmai
Copy link
Contributor

I'm able to reproduce this by running a JSON mutation and NQuad mutation in dgo.

Code: https://play.golang.org/p/k6DBNXuiuHu

Output:

2019/01/04 11:42:08 JSON mutation: {
  "access.to": {
    "access.to|inherit": false,
    "access.to|permission": "WRITE",
    "uid": "0x2"
  },
  "uid": "0x1"
}
2019/01/04 11:42:08 Query: {
  direct(func: uid(0x1)) {
    uid
    access.to @filter(uid(0x2)) @facets(anyofterms(permission, "READ WRITE")) @facets(permission,inherit) {
      uid
    }
  }
}
2019/01/04 11:42:08 Response: {
  "direct": [
    {
      "uid": "0x1"
    }
  ]
}
2019/01/04 11:42:08 NQuads mutation: <0x1> <access.to> <0x2> (permission="WRITE",inherit=false) .

2019/01/04 11:42:08 Query: {
  direct(func: uid(0x1)) {
    uid
    access.to @filter(uid(0x2)) @facets(anyofterms(permission, "READ WRITE")) @facets(permission,inherit) {
      uid
    }
  }
}
2019/01/04 11:42:08 Response: {
  "direct": [
    {
      "access.to": [
        {
          "access.to|inherit": false,
          "access.to|permission": "WRITE",
          "uid": "0x2"
        }
      ],
      "uid": "0x1"
    }
  ]
}

@srfrog srfrog added the investigate Requires further investigation label Jan 4, 2019
@srfrog srfrog self-assigned this Jan 4, 2019
@srfrog srfrog added kind/bug Something is broken. and removed investigate Requires further investigation labels Jan 7, 2019
@srfrog
Copy link
Contributor

srfrog commented Jan 7, 2019

It seems to be a bug in the JSON parser. You can test with your query:
RDF:

{set {
  _:x1 <access.to> _:x2 (permission="WRITE",inherit=false) .
}}

JSON:

{"set": {
  "uid": "_:x1",
    "access.to": {
      "uid": "_:x2",
      "access.to|inherit": false,
      "access.to|permission": "WRITE"
    }
}}

@manishrjain
Copy link
Contributor

@gitlw fixed a similar issue recently, where we were not parsing the facets correctly in one of the code paths. Lucas: Can you have a look?

@gitlw gitlw assigned gitlw and unassigned srfrog Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken.
Development

Successfully merging a pull request may close this issue.

5 participants