Skip to content

Commit 1f23a30

Browse files
added test fixed review
1 parent 6d4e2bd commit 1f23a30

7 files changed

Lines changed: 72 additions & 12 deletions

File tree

dql/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ func validKeyAtRoot(k string) bool {
26912691
switch k {
26922692
case "func", "orderasc", "orderdesc", "first", "offset", "after":
26932693
return true
2694-
case "from", "to", "numpaths", "minweight", "maxweight", "maxheapsize":
2694+
case "from", "to", "numpaths", "minweight", "maxweight", "maxfrontiersize":
26952695
// Specific to shortest path
26962696
return true
26972697
case "depth":

dql/parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ func TestParseQueryWithMultipleVar(t *testing.T) {
13021302
func TestParseShortestPath(t *testing.T) {
13031303
query := `
13041304
{
1305-
shortest(from:0x0a, to:0x0b, numpaths: 3, minweight: 3, maxweight: 6, maxheapsize: 1) {
1305+
shortest(from:0x0a, to:0x0b, numpaths: 3, minweight: 3, maxweight: 6, maxfrontiersize: 1) {
13061306
friends
13071307
name
13081308
}
@@ -1317,7 +1317,7 @@ func TestParseShortestPath(t *testing.T) {
13171317
require.Equal(t, "3", res.Query[0].Args["numpaths"])
13181318
require.Equal(t, "3", res.Query[0].Args["minweight"])
13191319
require.Equal(t, "6", res.Query[0].Args["maxweight"])
1320-
require.Equal(t, "1", res.Query[0].Args["maxheapsize"])
1320+
require.Equal(t, "1", res.Query[0].Args["maxfrontiersize"])
13211321
}
13221322

13231323
func TestParseShortestPathWithUidVars(t *testing.T) {

query/query.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ type params struct {
165165
MaxWeight float64
166166
// MinWeight is the min weight allowed in a path returned by the shortest path algorithm.
167167
MinWeight float64
168-
// MaxHeapSize is the maximum size of the heap that can be made while querying shortest path
169-
MaxHeapSize int
168+
// MaxFrontierSize is the maximum size of the frontier that can be made while querying shortest path
169+
MaxFrontierSize int64
170170

171171
// ExploreDepth is used by recurse and shortest path queries to specify the maximum graph
172172
// depth to explore.
@@ -716,14 +716,14 @@ func (args *params) fill(gq *dql.GraphQuery) error {
716716
args.MinWeight = -math.MaxFloat64
717717
}
718718

719-
if v, ok := gq.Args["maxheapsize"]; ok {
720-
maxHeapSize, err := strconv.ParseInt(v, 0, 64)
719+
if v, ok := gq.Args["maxfrontiersize"]; ok {
720+
maxfrontiersize, err := strconv.ParseInt(v, 0, 64)
721721
if err != nil {
722722
return err
723723
}
724-
args.MaxHeapSize = int(maxHeapSize)
724+
args.MaxFrontierSize = maxfrontiersize
725725
} else if !ok {
726-
args.MaxHeapSize = math.MaxInt64
726+
args.MaxFrontierSize = math.MaxInt64
727727
}
728728

729729
if gq.ShortestPathArgs.From == nil || gq.ShortestPathArgs.To == nil {
@@ -2652,7 +2652,7 @@ func (sg *SubGraph) sortAndPaginateUsingVar(ctx context.Context) error {
26522652
func isValidArg(a string) bool {
26532653
switch a {
26542654
case "numpaths", "from", "to", "orderasc", "orderdesc", "first", "offset", "after", "depth",
2655-
"minweight", "maxweight", "maxheapsize":
2655+
"minweight", "maxweight", "maxfrontiersize":
26562656
return true
26572657
}
26582658
return false

query/shortest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func runKShortestPaths(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
405405
hop: item.hop + 1,
406406
path: route{route: curPath},
407407
}
408-
if pq.Len() > sg.Params.MaxHeapSize {
408+
if int64(pq.Len()) > sg.Params.MaxFrontierSize {
409409
pq.Pop()
410410
}
411411
heap.Push(&pq, node)
@@ -561,7 +561,7 @@ func shortestPath(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
561561
cost: nodeCost,
562562
hop: item.hop + 1,
563563
}
564-
if pq.Len() > sg.Params.MaxHeapSize {
564+
if int64(pq.Len()) > sg.Params.MaxFrontierSize {
565565
pq.Pop()
566566
}
567567
heap.Push(&pq, node)

systest/shortest-path/graph.rdf.gz

3.7 MB
Binary file not shown.
81 Bytes
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//go:build integration
2+
3+
/*
4+
* SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
package main
9+
10+
import (
11+
"context"
12+
"testing"
13+
"time"
14+
15+
"github.com/hypermodeinc/dgraph/v25/dgraphapi"
16+
"github.com/hypermodeinc/dgraph/v25/dgraphtest"
17+
"github.com/hypermodeinc/dgraph/v25/x"
18+
"github.com/stretchr/testify/require"
19+
)
20+
21+
func TestShortestPath(t *testing.T) {
22+
conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour)
23+
c, err := dgraphtest.NewLocalCluster(conf)
24+
require.NoError(t, err)
25+
defer func() { c.Cleanup(t.Failed()) }()
26+
require.NoError(t, c.Start())
27+
28+
err = c.LiveLoad(dgraphtest.LiveOpts{
29+
DataFiles: []string{"graph.rdf.gz"},
30+
SchemaFiles: []string{"graph.schema.gz"},
31+
GqlSchemaFiles: []string{},
32+
})
33+
require.NoError(t, err)
34+
35+
gc, cleanup, err := c.Client()
36+
require.NoError(t, err)
37+
defer cleanup()
38+
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
39+
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))
40+
41+
_, err = gc.Query(`
42+
{
43+
q(func: eq(guid, "85270d10-560e-4cc8-8703-4b4c563a2f4e")) {
44+
a as uid
45+
}
46+
q1(func: eq(guid, "4a520068-80b6-42f2-9019-4e6ef8a02bb3")) {
47+
b as uid
48+
}
49+
50+
path as shortest(from: uid(a), to: uid(b), numpaths: 5, maxfrontiersize: 10000) {
51+
connected_to @facets(weight)
52+
}
53+
54+
path(func: uid(path)) {
55+
uid
56+
}
57+
}
58+
`)
59+
require.NoError(t, err)
60+
}

0 commit comments

Comments
 (0)