-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skipping floats that cannot be marshalled (#5163)
(cherry picked from commit d4cdf5e)
- Loading branch information
1 parent
6c2e711
commit 23a1072
Showing
4 changed files
with
172 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package query | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/dgraph-io/dgraph/protos/pb" | ||
"github.com/dgraph-io/dgraph/task" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func subgraphWithSingleResultAndSingleValue(val *pb.TaskValue) *SubGraph { | ||
return &SubGraph{ | ||
Params: params{Alias: "query"}, | ||
SrcUIDs: &pb.List{Uids: []uint64{1}}, | ||
DestUIDs: &pb.List{Uids: []uint64{1}}, | ||
uidMatrix: []*pb.List{&pb.List{Uids: []uint64{1}}}, | ||
Children: []*SubGraph{ | ||
&SubGraph{ | ||
Attr: "val", | ||
SrcUIDs: &pb.List{Uids: []uint64{1}}, | ||
uidMatrix: []*pb.List{&pb.List{}}, | ||
valueMatrix: []*pb.ValueList{ | ||
// UID 1 | ||
&pb.ValueList{ | ||
Values: []*pb.TaskValue{val}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func assertJSON(t *testing.T, expected string, sg *SubGraph) { | ||
buf, err := ToJson(&Latency{}, []*SubGraph{sg}) | ||
require.Nil(t, err) | ||
require.Equal(t, expected, string(buf)) | ||
} | ||
|
||
func TestSubgraphToFastJSON(t *testing.T) { | ||
t.Run("With a string result", func(t *testing.T) { | ||
sg := subgraphWithSingleResultAndSingleValue(task.FromString("ABC")) | ||
assertJSON(t, `{"query":[{"val":"ABC"}]}`, sg) | ||
}) | ||
|
||
t.Run("With an integer result", func(t *testing.T) { | ||
sg := subgraphWithSingleResultAndSingleValue(task.FromInt(42)) | ||
assertJSON(t, `{"query":[{"val":42}]}`, sg) | ||
}) | ||
|
||
t.Run("With a valid float result", func(t *testing.T) { | ||
sg := subgraphWithSingleResultAndSingleValue(task.FromFloat(42.0)) | ||
assertJSON(t, `{"query":[{"val":42.000000}]}`, sg) | ||
}) | ||
|
||
t.Run("With invalid floating points", func(t *testing.T) { | ||
assertJSON(t, `{"query":[]}`, subgraphWithSingleResultAndSingleValue(task.FromFloat(math.NaN()))) | ||
assertJSON(t, `{"query":[]}`, subgraphWithSingleResultAndSingleValue(task.FromFloat(math.Inf(1)))) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters