-
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
[BREAKING] New Facets format #5424
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for storing facets for scalar list and then confirming that a follow on query returns result in the same format in systest or http_test.go.
Reviewed 8 of 8 files at r1.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ashish-goswami and @manishrjain)
chunker/json_parser.go, line 49 at r1 (raw file):
} func handleBasicFacetsType(fname, prefix string, facetVal interface{}) (*api.Facet, error) {
Mention that this is only called when fname
has prefix
and from where all this is called.
chunker/json_parser.go, line 50 at r1 (raw file):
func handleBasicFacetsType(fname, prefix string, facetVal interface{}) (*api.Facet, error) { key := fname[len(prefix):]
Can we just pass this to the function instead of passing fname
.
chunker/json_parser.go, line 103 at r1 (raw file):
// parseMapFacets parses facets which are of map type. Facets for scalar list predicates are // specifed in map format. For example below prdicate nickname and kind facet associated with it.
specified
predicate
chunker/json_parser.go, line 112 at r1 (raw file):
// } // } // Parsed response would a slice of maps[int]*api.Facet, one map for each facet json.
one map for each facet
chunker/json_parser.go, line 132 at r1 (raw file):
if !ok { return nil, errors.Errorf("facets format should be of type map for scalar list predicates")
errors.Errorf("facets format should be of type map for scalar list predicates, found: %v for facet: %v", facetVal, fname)
chunker/json_parser.go, line 139 at r1 (raw file):
facet, err := handleBasicFacetsType(fname, prefix, val) if err != nil { return nil, errors.Wrapf(err, "Index: %s", sidx)
index
chunker/json_parser.go, line 143 at r1 (raw file):
idx, err := strconv.Atoi(sidx) if err != nil { return nil, errors.Wrapf(err, "Index: %s", sidx)
index
chunker/json_parser.go, line 455 at r1 (raw file):
// TODO - Maybe do an initial pass and build facets for all predicates. Then we don't have // to call parseFacets everytime. // Only call parseBasicFacets when value type is not list.
value type is scalar but not a list
chunker/json_parser.go, line 520 at r1 (raw file):
return mr, err } // Also populate facets for it.
Populate all the facets for it by seeking the appropriate index across all entries in the map. Please add some comments here about example values.
chunker/json_parser_test.go, line 555 at r1 (raw file):
{ "name":"Alice", "friend": ["Joshua", "David", "Josh"],
- Test with friend being null but facets being there.
friend: null
- Friend being empty,
friend: []
but facets being there - Facet map being null but friends being there.
- Facet map being of wrong type ["school", "college"] but friends being there
- Facet map having index > len(friend)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ashish-goswami and @manishrjain)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ashish-goswami, @manishrjain, and @pawanrawal)
chunker/json_parser.go, line 50 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Can we just pass this to the function instead of passing
fname
.
Done.
chunker/json_parser.go, line 103 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
specified
predicate
Done.
chunker/json_parser.go, line 112 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
one map for each facet
Done.
chunker/json_parser.go, line 132 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
errors.Errorf("facets format should be of type map for scalar list predicates, found: %v for facet: %v", facetVal, fname)
Done.
chunker/json_parser.go, line 139 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
index
Done.
chunker/json_parser.go, line 143 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
index
Done.
chunker/json_parser.go, line 455 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
value type is scalar but not a list
Done.
chunker/json_parser.go, line 520 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Populate all the facets for it by seeking the appropriate index across all entries in the map. Please add some comments here about example values.
Done.
chunker/json_parser_test.go, line 555 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
- Test with friend being null but facets being there.
friend: null
- Friend being empty,
friend: []
but facets being there- Facet map being null but friends being there.
- Facet map being of wrong type ["school", "college"] but friends being there
- Facet map having index > len(friend)
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small renames, but approved
chunker/json_parser.go
Outdated
@@ -475,7 +574,7 @@ func (buf *NQuadBuffer) mapToNquads(m map[string]interface{}, op int, parentPred | |||
} | |||
} | |||
|
|||
fts, err := parseFacetsJSON(m, parentPred+x.FacetDelimeter) | |||
fts, err := parseBasicFacets(m, parentPred+x.FacetDelimeter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseScalarFacets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 8 files at r1, 3 of 3 files at r2.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @ashish-goswami and @pawanrawal)
chunker/json_parser.go, line 49 at r1 (raw file):
Previously, pawanrawal (Pawan Rawal) wrote…
Mention that this is only called when
fname
hasprefix
and from where all this is called.
Not sure what's the point of "Basic". What is not basic?
chunker/json_parser.go, line 154 at r2 (raw file):
// parseBasicFacets parses facets which should be of type string/json.Number/bool. // It returns []*api.Facet, one *api.Facet for each facet. func parseBasicFacets(m map[string]interface{}, prefix string) ([]*api.Facet, error) {
same here. Basic?
This reverts commit ae8af64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 6 of 8 files reviewed, 13 unresolved discussions (waiting on @ashish-goswami, @gja, @manishrjain, @pawanrawal, and @vvbalaji-dgraph)
chunker/json_parser.go, line 49 at r1 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Not sure what's the point of "Basic". What is not basic?
I have written a comment explaining what handleBasicFacetsType
does.
chunker/json_parser.go, line 88 at r2 (raw file):
Previously, gja (Tejas Dinkar) wrote…
not float64, it should be number
Done.
chunker/json_parser.go, line 154 at r2 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
same here. Basic?
renamed it to parseScalarFacets
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.
It looks like the format for mutating uid lists with facets was not changed -- is that correct and is it intentional? A mutation that creates facets on uid lists and on scalar lists will look like this?
{
"set": {
"uid_list": [{
"uid": "0xdeadbeef",
"uid_list|facet_name": 123
}],
"scalar_list": [
"scalar_1"
],
"scalar_list|facet_name": {
"0": 123
}
}
} |
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:
New UID predicate facets query response:
Current UID list predicate facets query response:
New UID list predicate facets query response:
Current scalar list predicate facets mutation request:
New scalar list predicate facets mutation request:
NOTE: there is no change in the request/response facets format for scalar predicate type.
This change is
Docs Preview: