fix(query/influxql): have the transpiler use the _time column for the time
The spec says to use the `_time` column for the time in the output, but we were mapping `r._time` to `time` and using the `time` variable. This modifies the encoder to use the `_time` column and rename it to `time` for the column name.pull/10616/head
parent
f42fc81c71
commit
bcd0545728
|
@ -45,7 +45,7 @@ func (t *transpilerState) mapFields(in cursor) (cursor, error) {
|
|||
|
||||
properties := make([]*semantic.Property, 0, len(t.stmt.Fields)+2)
|
||||
properties = append(properties, &semantic.Property{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: execute.DefaultTimeColLabel},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/platform/query"
|
||||
"github.com/influxdata/platform/query/execute"
|
||||
"github.com/influxdata/platform/query/iocounter"
|
||||
)
|
||||
|
||||
|
@ -68,7 +69,7 @@ func (e *MultiResultEncoder) Encode(w io.Writer, results query.ResultIterator) (
|
|||
resultColMap := map[string]int{}
|
||||
j := 1
|
||||
for _, c := range b.Cols() {
|
||||
if c.Label == "time" {
|
||||
if c.Label == execute.DefaultTimeColLabel {
|
||||
resultColMap[c.Label] = 0
|
||||
} else if !b.Key().HasCol(c.Label) {
|
||||
resultColMap[c.Label] = j
|
||||
|
@ -78,6 +79,9 @@ func (e *MultiResultEncoder) Encode(w io.Writer, results query.ResultIterator) (
|
|||
|
||||
row.Columns = make([]string, len(resultColMap))
|
||||
for k, v := range resultColMap {
|
||||
if k == execute.DefaultTimeColLabel {
|
||||
k = "time"
|
||||
}
|
||||
row.Columns[v] = k
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestMultiResultEncoder_Encode(t *testing.T) {
|
|||
Blks: []*executetest.Block{{
|
||||
KeyCols: []string{"_measurement", "host"},
|
||||
ColMeta: []query.ColMeta{
|
||||
{Label: "time", Type: query.TTime},
|
||||
{Label: "_time", Type: query.TTime},
|
||||
{Label: "_measurement", Type: query.TString},
|
||||
{Label: "host", Type: query.TString},
|
||||
{Label: "value", Type: query.TFloat},
|
||||
|
|
|
@ -102,7 +102,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -220,7 +220,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -448,7 +448,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -668,7 +668,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -830,7 +830,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -959,7 +959,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -1070,7 +1070,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
@ -1194,7 +1194,7 @@ func TestTranspiler(t *testing.T) {
|
|||
Body: &semantic.ObjectExpression{
|
||||
Properties: []*semantic.Property{
|
||||
{
|
||||
Key: &semantic.Identifier{Name: "time"},
|
||||
Key: &semantic.Identifier{Name: "_time"},
|
||||
Value: &semantic.MemberExpression{
|
||||
Object: &semantic.IdentifierExpression{
|
||||
Name: "r",
|
||||
|
|
|
@ -2,5 +2,5 @@ from(db:"testdb")
|
|||
|> range(start: 2018-05-23T13:09:22.885021542Z)
|
||||
|> group(by: ["name"])
|
||||
|> group()
|
||||
|> map( mergeKey:false, fn: (r) => {_measurement:r._measurement,io_time:r._value,time: r._time})
|
||||
|> yield(name:"0")
|
||||
|> map( mergeKey:false, fn: (r) => {_measurement:r._measurement,io_time:r._value,_time: r._time})
|
||||
|> yield(name:"0")
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#datatype,string,long,string,long,dateTime:RFC3339
|
||||
#partition,false,false,false,false,false
|
||||
#default,0,,,,
|
||||
,result,table,_measurement,io_time,time
|
||||
,,0,diskio,15204688,2018-05-22T19:53:26Z
|
||||
,,0,diskio,15204894,2018-05-22T19:53:36Z
|
||||
,,0,diskio,15205102,2018-05-22T19:53:46Z
|
||||
,,0,diskio,15205226,2018-05-22T19:53:56Z
|
||||
,,0,diskio,15205499,2018-05-22T19:54:06Z
|
||||
,,0,diskio,15205755,2018-05-22T19:54:16Z
|
||||
,,0,diskio,648,2018-05-22T19:53:26Z
|
||||
,,0,diskio,648,2018-05-22T19:53:36Z
|
||||
,,0,diskio,648,2018-05-22T19:53:46Z
|
||||
,,0,diskio,648,2018-05-22T19:53:56Z
|
||||
,,0,diskio,648,2018-05-22T19:54:06Z
|
||||
,,0,diskio,648,2018-05-22T19:54:16Z
|
||||
,result,table,_measurement,_time,io_time
|
||||
,,0,diskio,2018-05-22T19:53:26Z,15204688
|
||||
,,0,diskio,2018-05-22T19:53:36Z,15204894
|
||||
,,0,diskio,2018-05-22T19:53:46Z,15205102
|
||||
,,0,diskio,2018-05-22T19:53:56Z,15205226
|
||||
,,0,diskio,2018-05-22T19:54:06Z,15205499
|
||||
,,0,diskio,2018-05-22T19:54:16Z,15205755
|
||||
,,0,diskio,2018-05-22T19:53:26Z,648
|
||||
,,0,diskio,2018-05-22T19:53:36Z,648
|
||||
,,0,diskio,2018-05-22T19:53:46Z,648
|
||||
,,0,diskio,2018-05-22T19:53:56Z,648
|
||||
,,0,diskio,2018-05-22T19:54:06Z,648
|
||||
,,0,diskio,2018-05-22T19:54:16Z,648
|
||||
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
from(db:"testdb")
|
||||
|> range(start: 2018-05-21T13:09:22.885021542Z)
|
||||
|> filter(fn: (r) => r._measurement == "swap")
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, time: r._time, used_percent:r._value})
|
||||
|> yield(name:"0")
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, _time: r._time, used_percent:r._value})
|
||||
|> yield(name:"0")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#datatype,string,long,string,dateTime:RFC3339,double
|
||||
#partition,false,false,true,false,false
|
||||
#default,0,,,,
|
||||
,result,table,_measurement,time,used_percent
|
||||
,result,table,_measurement,_time,used_percent
|
||||
,,0,swap,2018-05-22T19:53:26Z,82.9833984375
|
||||
,,0,swap,2018-05-22T19:53:36Z,82.598876953125
|
||||
,,0,swap,2018-05-22T19:53:46Z,82.598876953125
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
from(db:"testdb")
|
||||
|> range(start: 2018-05-23T13:09:22.885021542Z)
|
||||
|> filter(fn: (r) => r._measurement == "system" AND r._field == "load1")
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, load1:r._value, time: r._time})
|
||||
|> yield(name:"0")
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, load1:r._value, _time: r._time})
|
||||
|> yield(name:"0")
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#datatype,string,long,string,double,dateTime:RFC3339
|
||||
#datatype,string,long,string,dateTime:RFC3339,double
|
||||
#partition,false,false,true,false,false
|
||||
#default,0,,,,
|
||||
,result,table,_measurement,load1,time
|
||||
,,0,system,1.83,2018-05-22T19:53:26Z
|
||||
,,0,system,1.7,2018-05-22T19:53:36Z
|
||||
,,0,system,1.74,2018-05-22T19:53:46Z
|
||||
,,0,system,1.63,2018-05-22T19:53:56Z
|
||||
,,0,system,1.91,2018-05-22T19:54:06Z
|
||||
,,0,system,1.84,2018-05-22T19:54:16Z
|
||||
,result,table,_measurement,_time,load1
|
||||
,,0,system,2018-05-22T19:53:26Z,1.83
|
||||
,,0,system,2018-05-22T19:53:36Z,1.7
|
||||
,,0,system,2018-05-22T19:53:46Z,1.74
|
||||
,,0,system,2018-05-22T19:53:56Z,1.63
|
||||
,,0,system,2018-05-22T19:54:06Z,1.91
|
||||
,,0,system,2018-05-22T19:54:16Z,1.84
|
||||
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
from(db:"test")
|
||||
|> range(start:-5m)
|
||||
|> max(column: "_value")
|
||||
|> map(fn: (r) => {time:r._time, _measurement:r._measurement, max:r._value}, mergeKey:false)
|
||||
|> map(fn: (r) => {_time:r._time, _measurement:r._measurement, max:r._value}, mergeKey:false)
|
||||
|> yield(name:"0")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#datatype,string,long,string,double,dateTime:RFC3339
|
||||
#datatype,string,long,string,dateTime:RFC3339,double
|
||||
#partition,false,false,true,false,false
|
||||
#default,0,,,,
|
||||
,result,table,_measurement,max,time
|
||||
,,0,m1,43,2018-04-17T00:00:01Z
|
||||
,result,table,_measurement,_time,max
|
||||
,,0,m1,2018-04-17T00:00:01Z,43
|
||||
|
||||
|
|
|
|
@ -1,5 +1,5 @@
|
|||
from(db:"testdb")
|
||||
|> range(start: 2018-05-22T00:00:00Z)
|
||||
|> window(every:1s)
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, io_time:r._value,time: r._time})
|
||||
|> map(mergeKey:false, fn: (r) => {_measurement:r._measurement, io_time:r._value,_time: r._time})
|
||||
|> yield(name:"0")
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#datatype,string,long,string,long,dateTime:RFC3339
|
||||
#partition,false,false,true,false,false
|
||||
#default,0,,,,
|
||||
,result,table,_measurement,io_time,time
|
||||
,,0,diskio,15204688,2018-05-22T19:53:26Z
|
||||
,,0,diskio,648,2018-05-22T19:53:26Z
|
||||
,,0,diskio,15204894,2018-05-22T19:53:36Z
|
||||
,,0,diskio,648,2018-05-22T19:53:36Z
|
||||
,,0,diskio,15205102,2018-05-22T19:53:46Z
|
||||
,,0,diskio,648,2018-05-22T19:53:46Z
|
||||
,,0,diskio,15205226,2018-05-22T19:53:56Z
|
||||
,,0,diskio,648,2018-05-22T19:53:56Z
|
||||
,,0,diskio,15205499,2018-05-22T19:54:06Z
|
||||
,,0,diskio,648,2018-05-22T19:54:06Z
|
||||
,,0,diskio,15205755,2018-05-22T19:54:16Z
|
||||
,,0,diskio,648,2018-05-22T19:54:16Z
|
||||
,result,table,_measurement,_time,io_time
|
||||
,,0,diskio,2018-05-22T19:53:26Z,15204688
|
||||
,,0,diskio,2018-05-22T19:53:26Z,648
|
||||
,,0,diskio,2018-05-22T19:53:36Z,15204894
|
||||
,,0,diskio,2018-05-22T19:53:36Z,648
|
||||
,,0,diskio,2018-05-22T19:53:46Z,15205102
|
||||
,,0,diskio,2018-05-22T19:53:46Z,648
|
||||
,,0,diskio,2018-05-22T19:53:56Z,15205226
|
||||
,,0,diskio,2018-05-22T19:53:56Z,648
|
||||
,,0,diskio,2018-05-22T19:54:06Z,15205499
|
||||
,,0,diskio,2018-05-22T19:54:06Z,648
|
||||
,,0,diskio,2018-05-22T19:54:16Z,15205755
|
||||
,,0,diskio,2018-05-22T19:54:16Z,648
|
||||
|
||||
|
|
|
Loading…
Reference in New Issue