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

Bug: Mutation issue with facets integer #3

Closed
dokudoki opened this issue Mar 29, 2018 · 1 comment
Closed

Bug: Mutation issue with facets integer #3

dokudoki opened this issue Mar 29, 2018 · 1 comment

Comments

@dokudoki
Copy link

dokudoki commented Mar 29, 2018

I apologize, if this is not the correct place to post this. When I set facets with int(1) value it stored as float (1.000000). It's perfectly fine if I post or query with HTTP

type GraphCollection struct {
	Uid           string      `json:"uid"`
	Weight        []GraphNode `json:"weight,omitempty"`
}

type GraphNode struct {
	Uid          string `json:"uid"`
	WeightFacets int64  `json:"weight|score,omitempty"`
}

data := GraphCollection{
		Uid: cuid,
		Weight: []GraphNode{
			{
				Uid:          muid,
				WeightFacets: 1,
			},
		},
	}

	ctx := context.Background()

	dg, conn := dgraph.NewClient()
	defer conn.Close()

	pb, err := json.Marshal(data)
	if err != nil {
		log.Fatal(err)
	}

	_, err = dg.NewTxn().Mutate(ctx, &api.Mutation{SetJson: pb, CommitNow: true})
	if err != nil {
		log.Error(err)
	}

marshal string:
{"uid":"0x9c6711","weight":[{"uid":"0x1053b2","weight|score":1}]}

	q := fmt.Sprintf(`{
	  me(func: uid(0x9c6711)) {
	    weight @facets {
	      uid
	    }
	  }
	}`)

	txn := dg.NewTxn()
	resp, err := txn.Query(ctx, q)

	if err != nil {
		log.Fatal(err)
	}

	log.Debug(string(resp.Json))

response:
{"me":[{"weight":[{"uid":"0x1053b2","weight|score":1.000000}]}]}
with error
json: cannot unmarshal number 1.000000 into Go struct field weight of type int

@pawanrawal pawanrawal self-assigned this Apr 5, 2018
@pawanrawal
Copy link
Contributor

pawanrawal commented Apr 5, 2018

Since the mutation input is in JSON format which doesn't differentiate between INT/FLOAT (everything is a number), the server gets a float and stores the facet as such. This is, unfortunately, a limitation of the JSON format and the fact that facets don't have a fixed type.

I would recommend setting a property on a node (instead of facet) if the type is important to you or using the RDF mutation format.

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

No branches or pull requests

3 participants