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

New JSON facets response format cannot be unserialized back into client structures #4798

Closed
mehdiym opened this issue Feb 18, 2020 · 4 comments · Fixed by #5424
Closed

New JSON facets response format cannot be unserialized back into client structures #4798

mehdiym opened this issue Feb 18, 2020 · 4 comments · Fixed by #5424
Assignees
Labels
area/facets Issues related to face handling, querying, etc. kind/bug Something is broken. status/accepted We accept to investigate/work on it.

Comments

@mehdiym
Copy link

mehdiym commented Feb 18, 2020

What version of Dgraph are you using?

1.2.1

Steps to reproduce the issue (command/config used to run Dgraph).

Query for UID facets, and then try to unmarshal them into a Go struct.

Expected behaviour and actual result.

Expected: Facet values properly set.
Actual: Zero values.

I realize the facets response format has recently changed, but I don't understand how I can now unserialize it into my data structures : facets are now independent objects attached to the parent node while my Go facet properties are defined into the child node.

In the go doc example, the result is not unserialized into a Person anymore but instead into a generic json.RawMessage: does it mean it is not possible anymore?

How can I get facets directly back into my data structures?

@MichelDiz MichelDiz added area/facets Issues related to face handling, querying, etc. status/needs-attention This issue needs more eyes on it, more investigation might be required before accepting/rejecting it labels Feb 18, 2020
@shekarm shekarm added status/accepted We accept to investigate/work on it. and removed status/needs-attention This issue needs more eyes on it, more investigation might be required before accepting/rejecting it labels Feb 18, 2020
@MichelDiz MichelDiz added the kind/bug Something is broken. label Feb 26, 2020
@mileung
Copy link

mileung commented Mar 7, 2020

I think I am having the same issue as @mehdiym
https://www.youtube.com/watch?v=9dMvEoYY9_E
Correct me if I'm wrong, but in my video example, I think I read @facets(read) should be in the query result since it's clearly there when using pings @facets(read) { ... }. How can I get the facet result inside its corresponding node and not outside of it?

@MichelDiz
Copy link
Contributor

@mileung the result is correct. This is the new facet's behavior.

@MichelDiz
Copy link
Contributor

@mileung please, share you experience in this issue #4907

This issue New JSON facets response format cannot be unserialized back into client structures #4798 is related to the new behavior. Even if we support both behaviors, this issue must be fixed.

@ashish-goswami
Copy link
Contributor

Hi all, we have discussed facets format internally and prepared one document with different possible formats. Please checks below discuss post and provide your feedback.
https://discuss.dgraph.io/t/facets-format-in-mutation-requests-and-query-responses/6416

ashish-goswami added a commit that referenced this issue May 20, 2020
Fixes: #4798, #4581, #4907
DGRAPH-1109, DGRAPH-1062, DGRAPH-1143

This is PR changes facets format as discussed in the post: https://discuss.dgraph.io/t/facets-format-in-mutation-requests-and-query-responses/6416

After this PR is merged response/requests formats will look like as below:
Current UID predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "San Francisco",
        "state": {
          "name": "California"
        },
        "state|capital": false
      }
    ]
  }
}
New UID predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "San Francisco",
        "state": {
          "name": "California",
          "state|capital": false
        }
      }
    ]
  }
}
Current UID list predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "Alice",
        "speaks": [
          {
            "name": "Spanish"
          },
          {
            "name": "Chinese"
          }
        ],
        "speaks|fluent": {
          "0": true,
          "1": false
        }
      }
    ]
  }
}
New UID list predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "Alice",
        "speaks": [
          {
            "name": "Spanish",
            "speaks|fluent": true
          },
          {
            "name": "Chinese",
            "speaks|fluent": false
          }
        ]
      }
    ]
  }
}
Current scalar list predicate facets mutation request:

{
  "set": [
    {
      "uid": "_:1",
      "nickname": "Joshua",
      "nickname|kind": "official"
    },
    {
      "uid": "_:1",
      "nickname": "David"
    },
    {
      "uid": "_:1",
      "nickname": "Josh",
      "nickname|kind": "friends"
    }
  ]
}
New scalar list predicate facets mutation request:

{
  "set": {
      "uid": "_:1",
      "nickname": ["Joshua", "David", "Josh"],
      "nickname|kind": {
         "0": "official",
         "2": "friends"
      }
   }
}
NOTE: there is no change in the request/response facets format for scalar predicate type.
dna2github pushed a commit to dna2fork/dgraph that referenced this issue Jul 18, 2020
Fixes: hypermodeinc#4798, hypermodeinc#4581, hypermodeinc#4907
DGRAPH-1109, DGRAPH-1062, DGRAPH-1143

This is PR changes facets format as discussed in the post: https://discuss.dgraph.io/t/facets-format-in-mutation-requests-and-query-responses/6416

After this PR is merged response/requests formats will look like as below:
Current UID predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "San Francisco",
        "state": {
          "name": "California"
        },
        "state|capital": false
      }
    ]
  }
}
New UID predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "San Francisco",
        "state": {
          "name": "California",
          "state|capital": false
        }
      }
    ]
  }
}
Current UID list predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "Alice",
        "speaks": [
          {
            "name": "Spanish"
          },
          {
            "name": "Chinese"
          }
        ],
        "speaks|fluent": {
          "0": true,
          "1": false
        }
      }
    ]
  }
}
New UID list predicate facets query response:

{
  "data": {
    "q": [
      {
        "name": "Alice",
        "speaks": [
          {
            "name": "Spanish",
            "speaks|fluent": true
          },
          {
            "name": "Chinese",
            "speaks|fluent": false
          }
        ]
      }
    ]
  }
}
Current scalar list predicate facets mutation request:

{
  "set": [
    {
      "uid": "_:1",
      "nickname": "Joshua",
      "nickname|kind": "official"
    },
    {
      "uid": "_:1",
      "nickname": "David"
    },
    {
      "uid": "_:1",
      "nickname": "Josh",
      "nickname|kind": "friends"
    }
  ]
}
New scalar list predicate facets mutation request:

{
  "set": {
      "uid": "_:1",
      "nickname": ["Joshua", "David", "Josh"],
      "nickname|kind": {
         "0": "official",
         "2": "friends"
      }
   }
}
NOTE: there is no change in the request/response facets format for scalar predicate type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/facets Issues related to face handling, querying, etc. kind/bug Something is broken. status/accepted We accept to investigate/work on it.
Development

Successfully merging a pull request may close this issue.

5 participants