improves numeric literal stringer impl (#2663)

pull/2656/head
Owen Diehl 5 years ago committed by GitHub
parent 5729d88302
commit 89b8ae4b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pkg/logql/ast.go
  2. 16
      pkg/logql/ast_test.go
  3. 2
      pkg/logql/shardmapper_test.go

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

@ -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) {

@ -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]))`,

Loading…
Cancel
Save