-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support fetching facets from value edge lists #4081
Comments
Yes, this is indeed the part that I mentioned would not be necessarily fixed as part of #4034. The hard part here is basically agreeing on how it should be formatted. One option would be: {
"data": {
"query": [
{
"name": [
"Alice Smith",
"Alice Baker"
],
"name|since": [
"1990-01-01",
"2019-01-01",
]
}
]
}
} This approach breaks if some of the edges are missing that facet. Another option: {
"data": {
"query": [
{
"name": [
{
"@value": "Alice Smith",
"since": "1990-01-01"
},
{
"@value": "Alice Baker",
"since": "2019-01-01"
}
]
}
]
}
} This one has the slight issue that when you ask for facets, even if none are returned, strings are reified into objects. Also, we'll need to find a field name for Do you have any opinions on this, @robsws ? |
For our particular use case, I think either approach would work. In my own opinion, the first approach is probably more in line with the current facet response format and I think you could solve the problem of facets missing by adding |
We could potentially encode the facets in the name itself.
Might get tricky if the facet value is also a string. Another approach is we allow data to be returned in RDF format. That would make this trivial. |
We've decided to fix this issue by unifying the way we support facets in Dgraph both for value and uid predicates. In the proposed solution, we will handle facets the same way no matter the type of predicate. Facets are returned in a different field with a name composed of predicate name, followed by pipe character ( Facets on a singular value predicateThis behavior remains unchanged with v1.1.0. Schema: <name>: string . Data: <0x1> <name> "Francesc" (kind="first") . Query:
Result: {
"data": {
"q": [
{
"name|kind": "first",
"name": "Francesc"
}
]
}
} Facets on lists of value predicatesThis behavior was not supported in v1.1.0, follows the same idea as the one above. Schema: <nickname>: [string] . Data: <0x1> <nickname> "Francesc" (kind="official") .
<0x1> <nickname> "Tete" .
<0x1> <nickname> "Cesc" (kind="friends") . Query:
Result: {
"data": {
"q": [
{
"nickname": [
"Cesc",
"Francesc",
"Tete"
],
"nickname|kind": {
"0": "friends",
"1": "official"
}
}
]
}
} This solution makes it so parsing Facets on a singular object predicateThis behavior will change to become more similar to the way we handle value predicates. Schema: <name>: string .
<state>: uid . Data: <0x1> <name> "San Francisco" .
<0x1> <state> <0x2> (capital=false) .
<0x2> <name> "California" . Query:
The current behavior moves the value of the facet into the object pointed by the predicate. {
"data": {
"q": [
{
"name": "San Francisco",
"state": [
{
"name": "California",
"state|capital": false
}
]
}
]
}
} Instead, we propose to keep the facet value at the same level as the predicate as we do for value predicates. {
"data": {
"q": [
{
"name": "San Francisco",
"state": [
{
"name": "California"
},
"state|capital": false
]
}
]
}
} Facets on a list of object predicatesThis behavior will also change to become more similar to the way we handle value predicates. Schema: <name>: string .
<speaks>: [uid] . Data: <0x1> <name> "Francesc" .
<0x1> <speaks> <0x2> (fluent=true) .
<0x1> <speaks> <0x3> (fluent=false) .
<0x2> <name> "Spanish" .
<0x3> <name> "Chinese" . Query:
The current behavior moves the value of the facet into the object pointed by the predicate. {
"data": {
"q": [
{
"name": "Francesc",
"speaks": [
{
"name": "Spanish",
"speaks|fluent": true
},
{
"name": "Chinese",
"speaks|fluent": false
}
]
}
]
}
} Instead, we propose to keep the facet value at the same level as the predicate as we do for value predicates. {
"data": {
"q": [
{
"name": "Francesc",
"speaks": [
{
"name": "Spanish"
},
{
"name": "Chinese"
}
],
"speaks|fluent": {
"0": true,
"1": false
}
}
]
}
} |
The result you’ve shared feels not ideal. The mutation you have a “order” (the kind is linked to the value) <0x1> <nickname> "Francesc" (kind="official") .
<0x1> <nickname> "Tete" .
<0x1> <nickname> "Cesc" (kind="friends") . but the response isn’t ordered. {
"data": {
"q": [
{
"nickname": [
"Cesc",
"Francesc",
"Tete"
],
"nickname|kind": {
"0": "friends",
"1": "official",
"2": "null"
}
}
]
}
} We need a way to know “who owns the facet”. Because the answer needs to be predictable. We could also apply index positioning to the values of the list. {
"data": {
"q": [
{
"nickname": {
"0": "Cesc",
"1": "Francesc",
"2": "Tete"
},
"nickname|kind": {
"0": "friends",
"1": "official",
"2": "null"
}
}
]
}
} Or {
"data": {
"q": [
{
"nickname": {
"0": "Cesc",
"0|kind": "friends",
"1": "Francesc",
"1|kind": "official",
"2": "Tete"
},
}
]
}
} |
There is no order in the data, but there's an order in the result we send back since it's an array. That is exactly why we use a map, not an array, for the facet results. It allows us to keep it in sync while avoiding having potentially many nulls. |
So, by the response, you've shared. How do we can tell what belongs to what? There's no relation with the name and its facet in that response. I would assume that If facets come unsorted, there's no point in using it. But I can assume now after your response that the response example is slightly wrong. And everything should be alright. Only the example took my attention. BTW, I think we should use |
I think the misunderstanding was based on my typos, sorry about that! The actual response should be: {
"data": {
"q": [
{
"nickname": [
"Cesc",
"Francesc",
"Tete"
],
"nickname|kind": {
"0": "friends",
"1": "official"
}
}
]
}
} Note that indeed the field name with the facets is |
In case of Facets on lists of value predicates we are putting all the facets for all the values into the same
mutatoin
query
Right now on master the query doesn't return any facet, but we can look into facetmatrix to verify this. |
In case of Facets on a list of object predicates , we return the facet even in case of empty node.
sample response according to current behaviour
but if we try to index facets with values we will have the following response
The response above is incorrect because the empty node now has been discarded in values. I think we should eliminate all the empty nodes and their facets in response. A facet without any value anyway doesn't make sense. |
Yes, agreed. Only the facets for the nodes that appear in the response should be encoded. |
Hi @campoy, this actually breaks our whole strategy 😟. Without access to the facets of a list of predicates, for us, it's not possible to reconstruct the persisted data. Is there a way to get around this issue and somehow get the facet values? I mean, in the meanwhile, until this new feature is released? |
Wait, so this will help you with your problem. Right, @pepoospina? I just want to make sure I understand correctly. |
Fixes #4081 This PR covers following things: * Support for fetching facets from value edge list. * Response format change in case of facets to have uniform response format across uid/value/list edges. Co-authored-by: Animesh Chandra Pathak <animesh@dgraph.io>
Hi all, The fix will be delivered in v1.2 Please comment if more help is needed, and we will reopen Many thanks, |
It seems that currently, if facets are added on value edge lists (with type [string] for example), it is impossible to retrieve any facets added on edges within the list. Here is a toy example where I have two
name
s recorded for Alice, each with it's ownsince
facet associated:The response for this mutation shows a success, so one can assume that the facets were added successfully:
If you try and query the facet data, only the values of the edges are returned and not their facets:
Response:
Would it be possible to implement the ability to fetch these facets?
Secondly, it would be good to combine this with issue #4034 and allow filtering on these facets as well.
The text was updated successfully, but these errors were encountered: