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

Add ability to delete triples of scalar non-list predicates. #2899

Merged
merged 8 commits into from
Jan 19, 2019

Conversation

martinmr
Copy link
Contributor

@martinmr martinmr commented Jan 15, 2019

Currently, only using * works to delete this type of triples. This change allows setting a value and the triple will be deleted if the existing value matches the value in the delete triple (or there is no existing value).

Fixes #2419


This change is Reviewable

@martinmr martinmr self-assigned this Jan 15, 2019
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.

Reviewed 4 of 4 files at r1.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @martinmr)


posting/index.go, line 321 at r1 (raw file):

	}

	// Check original value BEFORE any mutation actually happens.

You can keep the if above, and add another if about del star. That way, you only retrieve the value if any of these if conds are met.


posting/index.go, line 322 at r1 (raw file):

	// Check original value BEFORE any mutation actually happens.
	val, found, err = l.findValue(txn.StartTs, fingerprintEdge(t))

I think we might be able to get rid of the findValue, and just use findPosting directly. And as needed, convert it over to valType.


posting/index.go, line 333 at r1 (raw file):

		newVal := valueToTypesVal(mpost)

		if found && !reflect.DeepEqual(val, newVal) {

Not a fan of reflect package. We have been able to not use it directly in Dgraph so far. Possible to do this equality comparison otherwise? In fact, you could just write an equality func for val.

val.IsEqual(newVal), where you can check their types, and do comparisons accordingly? Seems like a bit of extra work, but would avoid future devs from using reflect pkg.

Update: Looks like if you get the posting, then you can just compare the postings directly, without any issues.

Copy link
Contributor Author

@martinmr martinmr 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, 3 unresolved discussions (waiting on @manishrjain)


posting/index.go, line 321 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

You can keep the if above, and add another if about del star. That way, you only retrieve the value if any of these if conds are met.

Done.


posting/index.go, line 322 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

I think we might be able to get rid of the findValue, and just use findPosting directly. And as needed, convert it over to valType.

Done.


posting/index.go, line 333 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

Not a fan of reflect package. We have been able to not use it directly in Dgraph so far. Possible to do this equality comparison otherwise? In fact, you could just write an equality func for val.

val.IsEqual(newVal), where you can check their types, and do comparisons accordingly? Seems like a bit of extra work, but would avoid future devs from using reflect pkg.

Update: Looks like if you get the posting, then you can just compare the postings directly, without any issues.

Done.

@martinmr
Copy link
Contributor Author

Addressed all the comments. PR is ready for another round of review.

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: Got one very important comment. Do address that before merging.

Reviewed 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @martinmr)


posting/index.go, line 332 at r2 (raw file):

	if !schema.State().IsList(t.Attr) && t.Op == pb.DirectedEdge_DEL && string(t.Value) != x.Star {
		newPost := NewPosting(t)
		pFound, currPost, _ := l.findPosting(txn.StartTs, fingerprintEdge(t))

You're not checking error? Always handle errors. They should be returned.

@martinmr martinmr merged commit 9e05aaa into master Jan 19, 2019
@martinmr martinmr deleted the martinmr/single-pred-deletion branch January 19, 2019 02:15
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.

2 participants