fix subquery with offset conversion to string (#6373)

Signed-off-by: Bartosz Jakubski <b.jakubski@gmail.com>
This commit is contained in:
Bartosz Jakubski 2019-11-26 07:45:51 +01:00 committed by Brian Brazil
parent c2cb1e4103
commit 80ba03c67d
2 changed files with 8 additions and 1 deletions

View File

@ -128,7 +128,11 @@ func (node *SubqueryExpr) String() string {
if node.Step != 0 { if node.Step != 0 {
step = model.Duration(node.Step).String() step = model.Duration(node.Step).String()
} }
return fmt.Sprintf("%s[%s:%s]", node.Expr.String(), model.Duration(node.Range), step) offset := ""
if node.Offset != time.Duration(0) {
offset = fmt.Sprintf(" offset %s", model.Duration(node.Offset))
}
return fmt.Sprintf("%s[%s:%s]%s", node.Expr.String(), model.Duration(node.Range), step, offset)
} }
func (node *NumberLiteral) String() string { func (node *NumberLiteral) String() string {

View File

@ -83,6 +83,9 @@ func TestExprString(t *testing.T) {
{ {
in: `a[5m] offset 1m`, in: `a[5m] offset 1m`,
}, },
{
in: `a[1h:5m] offset 1m`,
},
{ {
in: `{__name__="a"}`, in: `{__name__="a"}`,
}, },