Skip to content

Commit

Permalink
improves numeric literal stringer impl (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Sep 23, 2020
1 parent 5729d88 commit 89b8ae4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/logql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func mustNewLiteralExpr(s string, invert bool) *literalExpr {
}

func (e *literalExpr) String() string {
return fmt.Sprintf("%f", e.value)
return fmt.Sprint(e.value)
}

// literlExpr impls SampleExpr & LogSelectorExpr mainly to reduce the need for more complicated typings
Expand Down
16 changes: 10 additions & 6 deletions pkg/logql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,28 @@ func TestStringer(t *testing.T) {
}{
{
in: `1 > 1 > 1`,
out: `0.000000`,
out: `0`,
},
{
in: `1.6`,
out: `1.6`,
},
{
in: `1 > 1 > bool 1`,
out: `0.000000`,
out: `0`,
},
{
in: `1 > bool 1 > count_over_time({foo="bar"}[1m])`,
out: `0.000000 > count_over_time({foo="bar"}[1m])`,
out: `0 > count_over_time({foo="bar"}[1m])`,
},
{
in: `1 > bool 1 > bool count_over_time({foo="bar"}[1m])`,
out: `0.000000 > bool count_over_time({foo="bar"}[1m])`,
out: `0 > bool count_over_time({foo="bar"}[1m])`,
},
{

in: `0.000000 > count_over_time({foo="bar"}[1m])`,
out: `0.000000 > count_over_time({foo="bar"}[1m])`,
in: `0 > count_over_time({foo="bar"}[1m])`,
out: `0 > count_over_time({foo="bar"}[1m])`,
},
} {
t.Run(tc.in, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/shardmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestMappingStrings(t *testing.T) {
},
{
in: `max(count(rate({foo="bar"}[5m]))) / 2`,
out: `max(sum(downstream<count(rate({foo="bar"}[5m])), shard=0_of_2> ++ downstream<count(rate({foo="bar"}[5m])), shard=1_of_2>)) / 2.000000`,
out: `max(sum(downstream<count(rate({foo="bar"}[5m])), shard=0_of_2> ++ downstream<count(rate({foo="bar"}[5m])), shard=1_of_2>)) / 2`,
},
{
in: `topk(3, rate({foo="bar"}[5m]))`,
Expand Down

0 comments on commit 89b8ae4

Please sign in to comment.