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

[BREAKING] New Facets format #5424

Merged
merged 11 commits into from
May 20, 2020
Merged

[BREAKING] New Facets format #5424

merged 11 commits into from
May 20, 2020

Conversation

ashish-goswami
Copy link
Contributor

@ashish-goswami ashish-goswami commented May 12, 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.


This change is Reviewable

Docs Preview: Dgraph Preview

Copy link
Contributor

@pawanrawal pawanrawal left a 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"],
  1. Test with friend being null but facets being there. friend: null
  2. Friend being empty, friend: [] but facets being there
  3. Facet map being null but friends being there.
  4. Facet map being of wrong type ["school", "college"] but friends being there
  5. Facet map having index > len(friend)

Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Once comments are addressed

Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ashish-goswami and @manishrjain)

Copy link
Contributor Author

@ashish-goswami ashish-goswami left a 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…
  1. Test with friend being null but facets being there. friend: null
  2. Friend being empty, friend: [] but facets being there
  3. Facet map being null but friends being there.
  4. Facet map being of wrong type ["school", "college"] but friends being there
  5. Facet map having index > len(friend)

Done.

Copy link
Contributor

@gja gja left a 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 Show resolved Hide resolved
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseScalarFacets

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

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 has prefix 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?

Copy link
Contributor Author

@ashish-goswami ashish-goswami left a 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

@ashish-goswami ashish-goswami changed the title New Facets format [BREAKING] New Facets format May 19, 2020
@ashish-goswami ashish-goswami merged commit b16b611 into master May 20, 2020
@ashish-goswami ashish-goswami deleted the ashish/newfacets branch May 20, 2020 13:09
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request 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.
@dpkirchner
Copy link

dpkirchner commented Jan 7, 2021

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?

uid_list: [uid] .
scalar_list: [string] .
{
  "set": {
    "uid_list": [{
      "uid": "0xdeadbeef",
      "uid_list|facet_name": 123
    }],
    "scalar_list": [
      "scalar_1"
    ],
    "scalar_list|facet_name": {
      "0": 123
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

New JSON facets response format cannot be unserialized back into client structures
5 participants