BUG: facets returning array

Moved from GitHub dgraph/3582

Posted by pjebs:

This bug report may or may not be related to the supposed fix: https://github.com/dgraph-io/dgraph/pull/3190
https://github.com/dgraph-io/dgraph/issues/3163

Schema:

	op.Schema = `
		user: bool .
		user.name: string @index(hash) .
		user.email: string @index(hash) .
		user.password: password .
		user.code: string . 
		user.created_at: dateTime .
		user.validated: bool @index(bool) .
		node: bool .
		node.hashid: string @index(hash) . 
		node.owner: uid @reverse . 
		node.parent: uid . 
		node.xdata: string . 
		node.searchable: bool @index(bool) . 
		node.search_title: string @index(term) .
		node.search_synopsis: string @index(fulltext) .
		node.created_at: dateTime .
	`

pjebs commented :

query:


q = `
		query withvar($hashid: string) {
			chain(func: eq(node.hashid, $hashid)) @recurse(loop:false) {
				uid
				node.owner
				user.name
				node.hashid
				node.xdata
				node.parent @facets @facets(%s)
			}
		}
	`

pjebs commented :

json result:

{
  "chain": [
    {
      "uid": "0x4e27",
      "node.owner": [
        {
          "uid": "0x1",
          "user.name": "alpha"
        }
      ],
      "node.hashid": "jjtn4cdirv",
      "node.xdata": "",
      "node.parent": [
        {
          "uid": "0x4e23",
          "node.owner": [
            {
              "uid": "0x1",
              "user.name": "alpha"
            }
          ],
          "node.hashid": "17t8kc5ig",
          "node.xdata": "",
          "node.parent|facet": "recommended"
        },
        {
          "uid": "0x4e25",
          "node.owner": [
            {
              "uid": "0x1",
              "user.name": "alpha"
            }
          ],
          "node.hashid": "r9t9rc4ip",
          "node.xdata": "",
          "node.parent": [
            {
              "uid": "0x4e23",
              "node.hashid": "17t8kc5ig",
              "node.xdata": "",
              "node.parent|facet": "recommended"
            }
          ],
          "node.parent|facet": "recommended"
        },
        {
          "uid": "0x4e26",
          "node.owner": [
            {
              "uid": "0x1",
              "user.name": "alpha"
            }
          ],
          "node.hashid": "35t8qc8i5",
          "node.xdata": "",
          "node.parent": [
            {
              "uid": "0x4e23",
              "node.hashid": "17t8kc5ig",
              "node.xdata": "",
              "node.parent|facet": "required"
            },
            {
              "uid": "0x4e25",
              "node.hashid": "r9t9rc4ip",
              "node.xdata": "",
              "node.parent|facet": [
                "recommended",
                "recommended"
              ]
            }
          ],
          "node.parent|facet": "required"
        }
      ]
    }
  ]
}

pjebs commented :

  • This is a recursive query
  • You can see "node.parent|facet" should return a string.

The BUG:

The second last "node.parent|facet" returns an array which should not be the case.

pjebs commented :

You can see the full query here: https://github.com/thehonestscoop/lemma-chain/blob/master/find_chain.go

pjebs commented :

@martinmr, was this bug a side effect of your PR?

martinmr commented :

It doesn’t seem related. It only affects one of the nodes at the end of the chain. The PR you mentioned affects all of them Can you query the facet on that node directly to see what you get?

pjebs commented :

Can you query the facet on that node directly

What does that mean? You mean query that node (eg. "uid": "0x4e25")

pjebs commented :

In the meantime, is it safe for me (as a temporary fix) to get the first item from array?

martinmr commented :

Yes, that’s what I mean. It should be safe to check if you have an array and just get the first one.

martinmr commented :

Also, there shouldn’t be two @facets directives in your query. At least when I run a similar query using https://docs.dgraph.io/query-language/#facets-on-scalar-predicates I get an error message saying multiple @facets are not allowed. Either you get all the facets or you only get one of them.

pjebs commented :

I believe there were good reasons why I had to add the @facets @facets(eq(facet, "required") or eq(facet, "recommended")). Either way it produces no dgraph errors and produces the expected results.

Let me investigate the @facets @facet(%s) issue further since you say it should not be permitted.

@power-f-GOD can you run the query with the ref r9t9rc4ip and 35t8qc8i5 to answer @martinmr’s question. You will need to fmt.Println( ) the response back from DGraph.

power-f-GOD commented :

Okay. Do you mean to run the query that produced the error again?

pjebs commented :

I investigated it further.

When I ran the query for the earlier nodes, the results were a string (not an array) for "node.parent|facet"

Something is clearly wrong with the array being returned.

martinmr commented :

Sorry for the late reply. What are the triples you inserted for this node (triples where this node is the subject) and how do they compare against a node where you can get the right result? I don’t need the data but I think this comparison could enlighten us on what’s different about this node.

If you insert those triples into a clean instance of Dgraph and run the query, is the result still showing the facet as an array or as a string?

I am beginning to think this issue might not be related with the query code given how other nodes return properly formatted data.

pjebs commented :

what’s a triple?

what should I do to investigate (in simpler terms)?

pjebs commented :

My query contains: @facets @facets(eq(facet, "required") or eq(facet, "recommended")).

You said to remove the first @facets. I then doesn’t return any facets.

martinmr commented :

Ok. I guess I didn’t understand why the two @facets are needed.

Triples: https://docs.dgraph.io/mutations/#triples

Since you don’t know what these are I am guessing you are using JSON to insert data into dgraph but what I meant was to add the data for this node into a new cluster, run the query (or a similar query checking the facets) and check if the query still returns an array.

campoy commented :

Hi there, @pjebs

I’m trying to understand your issue here but I don’t see how you could have been able to run the query you gave on the issue.

You are requesting @facets twice on the same predicate, which is not allowed.

Could you confirm what’s your real query and give a sample of your dataset so we can try it out?

Thanks

pjebs commented :

It definitely works pre v1.1. Maybe it’s been corrected v1.

The full query is: https://github.com/thehonestscoop/lemma-chain/blob/master/find_chain.go#L202