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

Fix handling of depth parameter for shortest path query. #4347

Merged
merged 18 commits into from
Dec 11, 2019

Conversation

pawanrawal
Copy link
Contributor

@pawanrawal pawanrawal commented Dec 4, 2019

Fixes #4169. This change doesn't fix handling of depth for k-shortest path query, it only does so for shortest path query with numpaths as 1. A separate change is required for fixing depth for shortest path queries with numpaths > 1.


This change is Reviewable

@pawanrawal pawanrawal marked this pull request as ready for review December 4, 2019 08:03
Copy link
Contributor

@animesh2049 animesh2049 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: 0 of 6 files reviewed, 7 unresolved discussions (waiting on @animesh2049 and @pawanrawal)

a discussion (no related file):
Djikstra logic seems okay to me. Just have some minor comment.



query/shortest.go, line 299 at r1 (raw file):

	heap.Push(&pq, srcNode)

	numHops := -1

Don't we want numHops to be initialized with 0? But I guess runKShortestPaths will be fixed in another PR.


query/shortest.go, line 462 at r1 (raw file):

	}
	pq := make(priorityQueue, 0)
	heap.Init(&pq)

Queue is empty. Do we really need to call heap.Init ?


query/shortest.go, line 468 at r1 (raw file):

		uid:  sg.Params.From,
		cost: 0,
		hop:  0,

Just a question, what does node.hop mean?


query/shortest.go, line 574 at r1 (raw file):

						attr:  neighbour.attr,
						facet: neighbour.facet,
					},

Can we update map entry outside if-else block? Code will look like this

var node *queueItem
if !ok {
	// This is the first time we're seeing this node. So
	// create a new node and add it to the heap and map.
	node := &queueItem{
		uid:  toUID,
		cost: nodeCost,
	}
	heap.Push(&pq, node)
} else {
	// We've already seen this node. So, just update the cost
	// and fix the priority in the heap and map.
	node := dist[toUID].node
	node.cost = nodeCost
	heap.Fix(&pq, node.index)
}

dist[toUID] = nodeInfo{
	parent: item.uid,
	node:   node,
	mapItem: mapItem{
		cost:  nodeCost,
		attr:  neighbour.attr,
		facet: neighbour.facet,
	},
}

query/shortest.go, line 586 at r1 (raw file):

	cur := sg.Params.To
	totalWeight = dist[cur].cost
	for i := 0; cur != sg.Params.From && i < len(dist); i++ {

Can we iterate for numHops times and check?
Loop will look something like

for i := numHops; i >= 0; i-- 

query/shortest.go, line 595 at r1 (raw file):

	}

	result = append(result, cur)

After above changes, we probably won't need this line.

@pawanrawal pawanrawal requested a review from martinmr December 4, 2019 13:58
Copy link
Contributor

@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.

Make sure you track the issue for numpaths > 1 either in github or JIRA.

Reviewed 2 of 6 files at r1, 4 of 4 files at r2.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @animesh2049 and @pawanrawal)


query/query.go, line 182 at r2 (raw file):

ExploreDepth *uint64

Will the value of this pointer be accessed concurrently at all?


query/query3_test.go, line 707 at r2 (raw file):

`{"data":{"path":[]}}`,

you use this multiple times so you could use a var called emptyPath or similar.


query/query3_test.go, line 747 at r2 (raw file):

Quoted 20 lines of code…
		// {
		// 	"1",
		// 	"10",
		// 	directPath,
		// },
		// {
		// 	"2",
		// 	"10",
		// 	directPath,
		// },
		// {
		// 	"3",
		// 	"10",
		// 	shortestPath,
		// },
		// {
		// 	"10",
		// 	"10",
		// 	shortestPath,
		// },

Why is this commented out?


query/shortest.go, line 468 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Just a question, what does node.hop mean?

I think it's the number of hops from the source node.

Copy link
Contributor Author

@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.

Sure, created a JIRA ticket for it @martinmr.

Reviewable status: 4 of 6 files reviewed, 10 unresolved discussions (waiting on @animesh2049 and @martinmr)

a discussion (no related file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Djikstra logic seems okay to me. Just have some minor comment.

Done.



query/query.go, line 182 at r2 (raw file):

Previously, martinmr (Martin Martinez Rivera) wrote…
ExploreDepth *uint64

Will the value of this pointer be accessed concurrently at all?

Nope, I don't see it being accessed concurrently for the same subgraph.


query/query3_test.go, line 707 at r2 (raw file):

Previously, martinmr (Martin Martinez Rivera) wrote…
`{"data":{"path":[]}}`,

you use this multiple times so you could use a var called emptyPath or similar.

Done.


query/query3_test.go, line 747 at r2 (raw file):

Previously, martinmr (Martin Martinez Rivera) wrote…
		// {
		// 	"1",
		// 	"10",
		// 	directPath,
		// },
		// {
		// 	"2",
		// 	"10",
		// 	directPath,
		// },
		// {
		// 	"3",
		// 	"10",
		// 	shortestPath,
		// },
		// {
		// 	"10",
		// 	"10",
		// 	shortestPath,
		// },

Why is this commented out?

These are test cases for k-shortest path as the second parameter is numpaths here... Will un-comment them when I have a fix for them. Added a comment.


query/shortest.go, line 299 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Don't we want numHops to be initialized with 0? But I guess runKShortestPaths will be fixed in another PR.

Yes, will fix k-shortest path in another PR.


query/shortest.go, line 462 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Queue is empty. Do we really need to call heap.Init ?

Nope, good point. Removed.


query/shortest.go, line 468 at r1 (raw file):

Previously, martinmr (Martin Martinez Rivera) wrote…

I think it's the number of hops from the source node.

Added a comment to the struct definition.


query/shortest.go, line 574 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Can we update map entry outside if-else block? Code will look like this

var node *queueItem
if !ok {
	// This is the first time we're seeing this node. So
	// create a new node and add it to the heap and map.
	node := &queueItem{
		uid:  toUID,
		cost: nodeCost,
	}
	heap.Push(&pq, node)
} else {
	// We've already seen this node. So, just update the cost
	// and fix the priority in the heap and map.
	node := dist[toUID].node
	node.cost = nodeCost
	heap.Fix(&pq, node.index)
}

dist[toUID] = nodeInfo{
	parent: item.uid,
	node:   node,
	mapItem: mapItem{
		cost:  nodeCost,
		attr:  neighbour.attr,
		facet: neighbour.facet,
	},
}

done


query/shortest.go, line 586 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

Can we iterate for numHops times and check?
Loop will look something like

for i := numHops; i >= 0; i-- 

Done.


query/shortest.go, line 595 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

After above changes, we probably won't need this line.

Done.

Copy link
Contributor Author

@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.

Reviewable status: 4 of 6 files reviewed, 10 unresolved discussions (waiting on @animesh2049 and @martinmr)


query/shortest.go, line 586 at r1 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Done.

Actually reverted because it won't be correct. Length of the shortest path could be greater than number of hops. So if we expandOut only twice (i.e. call processGraph twice), the shortest path be of length 3.

Copy link
Contributor

@animesh2049 animesh2049 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: 4 of 6 files reviewed, 4 unresolved discussions (waiting on @martinmr and @pawanrawal)


query/shortest.go, line 595 at r1 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Done.

With the current logic, source node (sg.Params.From won't be included in result). Is that the desired behavior?


query/shortest.go, line 510 at r3 (raw file):

		item := heap.Pop(&pq).(*queueItem)
		if item.uid == sg.Params.To {
			totalWeight = item.cost

I think we are not using this value of totalWeight. Deep source also points this out.

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 2 of 6 files at r1, 2 of 4 files at r2, 1 of 2 files at r3, 1 of 1 files at r4.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @martinmr and @pawanrawal)


query/shortest.go, line 557 at r4 (raw file):

				// We've already seen this node. So, just update the cost
				// and fix the priority in the heap and map.
				node = dist[toUID].node

We don't enforce capital ID in Dgraph.

Copy link
Contributor

@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.

There's a comment from Animesh that hasn't been marked as done but once that is done it :lgtm:

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pawanrawal)

Copy link
Contributor Author

@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.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @animesh2049 and @manishrjain)


query/shortest.go, line 595 at r1 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

With the current logic, source node (sg.Params.From won't be included in result). Is that the desired behavior?

It is included because we break out of loop after.


query/shortest.go, line 510 at r3 (raw file):

Previously, animesh2049 (Animesh Chandra Pathak) wrote…

I think we are not using this value of totalWeight. Deep source also points this out.

Changed it


query/shortest.go, line 557 at r4 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

We don't enforce capital ID in Dgraph.

Done.

@pawanrawal pawanrawal merged commit 50802e1 into master Dec 11, 2019
@pawanrawal pawanrawal deleted the pawanrawal/fix-4169 branch December 11, 2019 09:23
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.

Shortest path computes wrong path
4 participants