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
Jonathan A. Sternberg 2018-07-02 12:12:56 -05:00
parent f42fc81c71
commit bcd0545728
14 changed files with 61 additions and 57 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 #datatype string long string long dateTime:RFC3339
2 #partition false false false false false
3 #default 0
4 result table _measurement io_time _time time io_time
5 0 diskio 15204688 2018-05-22T19:53:26Z 2018-05-22T19:53:26Z 15204688
6 0 diskio 15204894 2018-05-22T19:53:36Z 2018-05-22T19:53:36Z 15204894
7 0 diskio 15205102 2018-05-22T19:53:46Z 2018-05-22T19:53:46Z 15205102
8 0 diskio 15205226 2018-05-22T19:53:56Z 2018-05-22T19:53:56Z 15205226
9 0 diskio 15205499 2018-05-22T19:54:06Z 2018-05-22T19:54:06Z 15205499
10 0 diskio 15205755 2018-05-22T19:54:16Z 2018-05-22T19:54:16Z 15205755
11 0 diskio 648 2018-05-22T19:53:26Z 2018-05-22T19:53:26Z 648
12 0 diskio 648 2018-05-22T19:53:36Z 2018-05-22T19:53:36Z 648
13 0 diskio 648 2018-05-22T19:53:46Z 2018-05-22T19:53:46Z 648
14 0 diskio 648 2018-05-22T19:53:56Z 2018-05-22T19:53:56Z 648
15 0 diskio 648 2018-05-22T19:54:06Z 2018-05-22T19:54:06Z 648
16 0 diskio 648 2018-05-22T19:54:16Z 2018-05-22T19:54:16Z 648
17

View File

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

View File

@ -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 #datatype string long string dateTime:RFC3339 double
2 #partition false false true false false
3 #default 0
4 result table _measurement time _time used_percent
5 0 swap 2018-05-22T19:53:26Z 82.9833984375
6 0 swap 2018-05-22T19:53:36Z 82.598876953125
7 0 swap 2018-05-22T19:53:46Z 82.598876953125

View File

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

View File

@ -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 #datatype string long string dateTime:RFC3339 double
2 #partition false false true false false
3 #default 0
4 result table _measurement time _time load1
5 0 system 2018-05-22T19:53:26Z 1.83
6 0 system 2018-05-22T19:53:36Z 1.7
7 0 system 2018-05-22T19:53:46Z 1.74
8 0 system 2018-05-22T19:53:56Z 1.63
9 0 system 2018-05-22T19:54:06Z 1.91
10 0 system 2018-05-22T19:54:16Z 1.84
11

View File

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

View File

@ -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 #datatype string long string dateTime:RFC3339 double
2 #partition false false true false false
3 #default 0
4 result table _measurement time _time max
5 0 m1 2018-04-17T00:00:01Z 43
6

View File

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

View File

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

1 #datatype string long string long dateTime:RFC3339
2 #partition false false true false false
3 #default 0
4 result table _measurement io_time _time time io_time
5 0 diskio 15204688 2018-05-22T19:53:26Z 2018-05-22T19:53:26Z 15204688
6 0 diskio 648 2018-05-22T19:53:26Z 2018-05-22T19:53:26Z 648
7 0 diskio 15204894 2018-05-22T19:53:36Z 2018-05-22T19:53:36Z 15204894
8 0 diskio 648 2018-05-22T19:53:36Z 2018-05-22T19:53:36Z 648
9 0 diskio 15205102 2018-05-22T19:53:46Z 2018-05-22T19:53:46Z 15205102
10 0 diskio 648 2018-05-22T19:53:46Z 2018-05-22T19:53:46Z 648
11 0 diskio 15205226 2018-05-22T19:53:56Z 2018-05-22T19:53:56Z 15205226
12 0 diskio 648 2018-05-22T19:53:56Z 2018-05-22T19:53:56Z 648
13 0 diskio 15205499 2018-05-22T19:54:06Z 2018-05-22T19:54:06Z 15205499
14 0 diskio 648 2018-05-22T19:54:06Z 2018-05-22T19:54:06Z 648
15 0 diskio 15205755 2018-05-22T19:54:16Z 2018-05-22T19:54:16Z 15205755
16 0 diskio 648 2018-05-22T19:54:16Z 2018-05-22T19:54:16Z 648
17