Navigation Menu

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

JSON mutation, Support facets for value edge lists #4581

Closed
emile-tawfik opened this issue Jan 15, 2020 · 6 comments
Closed

JSON mutation, Support facets for value edge lists #4581

emile-tawfik opened this issue Jan 15, 2020 · 6 comments
Assignees
Labels
area/facets Issues related to face handling, querying, etc. area/mutations Related to mutations JSON or RDF. kind/bug Something is broken. kind/feature Something completely new we should consider. status/accepted We accept to investigate/work on it.

Comments

@emile-tawfik
Copy link

Hi,

This issue follows this one #4081 and this PR #4267.

#4267 changes the output format, but does not reflect thoses changes for the input JSON mutation format.

This cause 2 issues:

  • The JSON input and output are not permutable
  • This impossibility to add facets to a value edge lists

I think the JSON mutation format should be modified accordingly to the output format.

Below are some examples of the modified JSON input : (coming from #4081 (comment))

Facets on a singular value predicate

Schema:

<name>: string .

Old-Data:

{
    "name|kind": "first",
    "name": "Francesc"
}

Data:

{
    "name|kind": "first",
    "name": "Francesc"
}

Query:

{
   q(func: has(name)) {
      name @facets
   }
}

Result:

{
  "data": {
    "q": [
      {
        "name|kind": "first",
        "name": "Francesc"
      }
    ]
  }
}

Facets on lists of value predicates

Schema:

<nickname>: [string] .

Old-Data:

Impossible to write

Data:

{
    "nickname": [
      "Cesc",
      "Francesc",
      "Tete"
    ],
    "nickname|kind": {
      "0": "friends",
      "1": "official"
    }
}

Query:

{
   q(func: has(nickname)) {
      nickname @facets
   }
}

Result:

{
  "data": {
    "q": [
      {
        "nickname": [
          "Cesc",
          "Francesc",
          "Tete"
        ],
        "nickname|kind": {
          "0": "friends",
          "1": "official"
        }
      }
    ]
  }
}

Facets on a singular object predicate

Schema:

<name>: string .
<state>: uid .

Old-Data:

{
    "name": "San Francisco",
    "state": [
        {
            "name": "California",
            "state|capital": false
        }
    ]
}

Data:

{
    "name": "San Francisco",
    "state": [
      {
        "name": "California"
      },
      "state|capital": false
    ]
}

Query:

{
   q(func: has(state)) {
      name
      state @facets {
         name
      }
   }
}

Result:

{
  "data": {
    "q": [
      {
        "name": "San Francisco",
        "state": [
          {
            "name": "California"
          },
          "state|capital": false
        ]
      }
    ]
  }
}

Facets on a list of object predicates

Schema:

<name>: string .
<speaks>: [uid] .

Old-Data:

{
    "name": "Francesc",
    "speaks": [
      {
        "name": "Spanish",
        "speaks|fluent": true
      },
      {
        "name": "Chinese"
        "speaks|fluent": false
      }
    ]
}

Data:

{
    "name": "Francesc",
    "speaks": [
      {
        "name": "Spanish"
      },
      {
        "name": "Chinese"
      }
    ],
    "speaks|fluent": {
       "0": true,
       "1": false
    }
}

Query:

{
   q(func: has(state)) {
      name
      state @facets {
         name
      }
   }
}

Result:

{
  "data": {
    "q": [
      {
        "name": "Francesc",
        "speaks": [
          {
            "name": "Spanish"
          },
          {
            "name": "Chinese"
          }
        ],
        "speaks|fluent": {
           "0": true,
           "1": false
        }
      }
    ]
  }
}
@MichelDiz
Copy link
Contributor

The old way of doing facets between edges still works. So there are no changes to it. Just in the List Type.

For list-type facets I think it is pretty okay to be like this:

I will document this.

{
   q(func: has(nickname)) @filter(eq(name,"Julian")) {
      nickname @facets
   }
}

Result:

{
    "q": [
      {
        "nickname|kind": {
          "0": "first",
          "1": "official",
          "2": "CS-GO"
        },
        "nickname": [
          "Jay-Jay",
          "Jules",
          "JB"
        ]
      }
    ]
  }

The JSON mutation executed

{
  "set": [
    {
      "uid": "_:Julian",
      "name": "Julian",
      "nickname|kind": "first",
      "nickname": "Jay-Jay"
    },
    {
      "uid": "_:Julian",
      "nickname|kind": "official",
      "nickname": "Jules"
    },
    {
      "uid": "_:Julian",
      "nickname|kind": "CS-GO",
      "nickname": "JB"
    }
  ]
}

In RDF

{
  set {
    _:Blank <nickname> "Cesc" (kind="friends") .
    _:Blank <nickname> "Francesc" (kind="official") .
    _:Blank <nickname> "Tete" .
  }
}

@MichelDiz
Copy link
Contributor

Docs added, waiting for review. #4582

@MichelDiz MichelDiz added area/facets Issues related to face handling, querying, etc. area/mutations Related to mutations JSON or RDF. labels Jan 16, 2020
@emile-tawfik
Copy link
Author

I haven't thought about reusing the same blanknode multiple times.

Concerning the benefits of the JSON mutation format in the docs (Source: https://docs.dgraph.io/mutations/#json-mutation-format)

It also eliminates the need for apps to have custom serialisation code

This is not true because, at least for edge value lists, the serialization/deserialization format aren't the same.

@sleto-it sleto-it added kind/feature Something completely new we should consider. status/needs-attention This issue needs more eyes on it, more investigation might be required before accepting/rejecting it labels Feb 13, 2020
@hackintoshrao
Copy link
Contributor

Hey @emile-tawfik ,

Thanks for reporting this issue, only an avid Dgraph user could notice such tricky inconsistencies :)
Yes, I agree that least for edge value lists, the serialization/deserialization format aren't the same., this is an issue for sure, we'll take this up further and propose a solution.

@shekarm shekarm added kind/bug Something is broken. 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 Mar 23, 2020
@ashish-goswami ashish-goswami self-assigned this Mar 25, 2020
@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.
@lgalatin
Copy link
Contributor

Fixed in #5424

dna2github pushed a commit to dna2fork/dgraph that referenced this issue Jul 18, 2020
Fixes: dgraph-io#4798, dgraph-io#4581, dgraph-io#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. area/mutations Related to mutations JSON or RDF. kind/bug Something is broken. kind/feature Something completely new we should consider. status/accepted We accept to investigate/work on it.
Development

No branches or pull requests

7 participants