fix(query/influxql): influxql transpiler should set the now time

The now time is stamped by the influxql transpiler and used inside of
the actual query. It will result in more accuracy if we take the
timestamp we have created and send it as part of the spec to queryd
rather than force ourselves to ensure absolute times exist everywhere.
pull/10616/head
Jonathan A. Sternberg 2018-07-25 08:34:41 -05:00
parent e92d05eef8
commit 4b7bfb21c2
16 changed files with 19 additions and 6 deletions

View File

@ -53,7 +53,7 @@ func createVarRefCursor(t *transpilerState, ref *influxql.VarRef) (cursor, error
return nil, err
}
valuer := influxql.NowValuer{Now: t.now}
valuer := influxql.NowValuer{Now: t.spec.Now}
_, tr, err := influxql.ConditionExpr(t.stmt.Condition, &valuer)
if err != nil {
return nil, err
@ -63,7 +63,7 @@ func createVarRefCursor(t *transpilerState, ref *influxql.VarRef) (cursor, error
// the end time will be set to now.
if tr.Max.IsZero() {
if window, err := t.stmt.GroupByInterval(); err == nil && window > 0 {
tr.Max = t.now
tr.Max = t.spec.Now
}
}

View File

@ -133,7 +133,7 @@ func (gr *groupInfo) createCursor(t *transpilerState) (cursor, error) {
tags map[influxql.VarRef]struct{}
cond influxql.Expr
)
valuer := influxql.NowValuer{Now: t.now}
valuer := influxql.NowValuer{Now: t.spec.Now}
if t.stmt.Condition != nil {
var err error
if cond, _, err = influxql.ConditionExpr(t.stmt.Condition, &valuer); err != nil {
@ -312,7 +312,7 @@ func (gr *groupInfo) group(t *transpilerState, in cursor) (cursor, error) {
} else if len(lit2.Args) != 0 {
return nil, errors.New("time dimension offset now() function requires no arguments")
}
now := t.now
now := t.spec.Now
windowOffset = now.Sub(now.Truncate(windowEvery))
// Use the evaluated offset to replace the argument. Ideally, we would

View File

@ -160,6 +160,7 @@ func init() {
{Parent: aggregate.ID, Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -145,6 +145,7 @@ func init() {
{Parent: aggregate.ID, Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -122,6 +122,7 @@ func init() {
{Parent: aggregate.ID, Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -147,6 +147,7 @@ func init() {
{Parent: "window1", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -148,6 +148,7 @@ func init() {
{Parent: "window1", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -219,6 +219,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -247,6 +247,7 @@ func init() {
{Parent: "join0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -240,6 +240,7 @@ func init() {
{Parent: "max0", Child: "map1"},
{Parent: "map1", Child: "yield1"},
},
Now: Now(),
},
),
)

View File

@ -119,6 +119,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -142,6 +142,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -143,6 +143,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)
@ -278,6 +279,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -119,6 +119,7 @@ func init() {
{Parent: "group0", Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
},
),
)

View File

@ -161,6 +161,7 @@ func init() {
{Parent: selector.ID, Child: "map0"},
{Parent: "map0", Child: "yield0"},
},
Now: Now(),
}
}),
)

View File

@ -56,7 +56,6 @@ type transpilerState struct {
config Config
spec *query.Spec
nextID map[string]int
now time.Time
dbrpMappingSvc platform.DBRPMappingService
}
@ -74,7 +73,7 @@ func newTranspilerState(dbrpMappingSvc platform.DBRPMappingService, config *Conf
}
// Stamp the current time using the now function from the config or the default.
state.now = state.config.NowFn()
state.spec.Now = state.config.NowFn()
return state
}