Merge pull request #6394 from influxdata/js-integer-literal-duration-math
Allow time math with integer timestampspull/6103/head
commit
f4ce20c92a
|
@ -8,6 +8,7 @@
|
||||||
- [#6292](https://github.com/influxdata/influxdb/issues/6292): Allow percentile to be used as a selector.
|
- [#6292](https://github.com/influxdata/influxdb/issues/6292): Allow percentile to be used as a selector.
|
||||||
- [#5707](https://github.com/influxdata/influxdb/issues/5707): Return a deprecated message when IF NOT EXISTS is used.
|
- [#5707](https://github.com/influxdata/influxdb/issues/5707): Return a deprecated message when IF NOT EXISTS is used.
|
||||||
- [#6334](https://github.com/influxdata/influxdb/pull/6334): Allow environment variables to be set per input type.
|
- [#6334](https://github.com/influxdata/influxdb/pull/6334): Allow environment variables to be set per input type.
|
||||||
|
- [#6394](https://github.com/influxdata/influxdb/pull/6394): Allow time math with integer timestamps.
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
|
|
@ -4087,6 +4087,14 @@ func reduceBinaryExprIntegerLHS(op Token, lhs *IntegerLiteral, rhs Expr) Expr {
|
||||||
case LTE:
|
case LTE:
|
||||||
return &BooleanLiteral{Val: lhs.Val <= rhs.Val}
|
return &BooleanLiteral{Val: lhs.Val <= rhs.Val}
|
||||||
}
|
}
|
||||||
|
case *DurationLiteral:
|
||||||
|
// Treat the integer as a timestamp.
|
||||||
|
switch op {
|
||||||
|
case ADD:
|
||||||
|
return &TimeLiteral{Val: time.Unix(0, lhs.Val).Add(rhs.Val)}
|
||||||
|
case SUB:
|
||||||
|
return &TimeLiteral{Val: time.Unix(0, lhs.Val).Add(-rhs.Val)}
|
||||||
|
}
|
||||||
case *nilLiteral:
|
case *nilLiteral:
|
||||||
return &BooleanLiteral{Val: false}
|
return &BooleanLiteral{Val: false}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1149,6 +1149,7 @@ func TestReduce(t *testing.T) {
|
||||||
{in: `now() - (now() - 60s)`, out: `1m`, data: map[string]interface{}{"now()": now}},
|
{in: `now() - (now() - 60s)`, out: `1m`, data: map[string]interface{}{"now()": now}},
|
||||||
{in: `now() AND now()`, out: `'2000-01-01T00:00:00Z' AND '2000-01-01T00:00:00Z'`, data: map[string]interface{}{"now()": now}},
|
{in: `now() AND now()`, out: `'2000-01-01T00:00:00Z' AND '2000-01-01T00:00:00Z'`, data: map[string]interface{}{"now()": now}},
|
||||||
{in: `now()`, out: `now()`},
|
{in: `now()`, out: `now()`},
|
||||||
|
{in: `946684800000000000 + 2h`, out: `'2000-01-01T02:00:00Z'`},
|
||||||
|
|
||||||
// Duration literals.
|
// Duration literals.
|
||||||
{in: `10m + 1h - 60s`, out: `69m`},
|
{in: `10m + 1h - 60s`, out: `69m`},
|
||||||
|
|
Loading…
Reference in New Issue