Skip to content

Commit b12dd4c

Browse files
authored
Allow to modify the query FillMode (#27)
1 parent 85e19b7 commit b12dd4c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

datasource.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,17 @@ func (ds *sqldatasource) handleQuery(req backend.DataQuery) (data.Frames, error)
9292
return nil, errors.WithMessage(err, "Could not apply macros")
9393
}
9494

95+
// Apply the default FillMode, overwritting it if the query specifies it
96+
fillMode := ds.c.FillMode()
97+
if q.FillMissing != nil {
98+
fillMode = q.FillMissing
99+
}
100+
95101
// FIXES:
96102
// * Some datasources (snowflake) expire connections or have an authentication token that expires if not used in 1 or 4 hours.
97103
// Because the datasource driver does not include an option for permanent connections, we retry the connection
98104
// if the query fails. NOTE: this does not include some errors like "ErrNoRows"
99-
res, err := query(ds.db, ds.c.Converters(), ds.c.FillMode(), q)
105+
res, err := query(ds.db, ds.c.Converters(), fillMode, q)
100106
if err == nil {
101107
return res, nil
102108
}
@@ -106,7 +112,7 @@ func (ds *sqldatasource) handleQuery(req backend.DataQuery) (data.Frames, error)
106112
if err != nil {
107113
return nil, err
108114
}
109-
return query(ds.db, ds.c.Converters(), ds.c.FillMode(), q)
115+
return query(ds.db, ds.c.Converters(), fillMode, q)
110116
}
111117

112118
return nil, err

query.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Query struct {
3232
Interval time.Duration `json:"-"`
3333
TimeRange backend.TimeRange `json:"-"`
3434
MaxDataPoints int64 `json:"-"`
35+
FillMissing *data.FillMissing `json:"fillMode,omitempty"`
3536

3637
// Macros
3738
Schema string `json:"schema,omitempty"`
@@ -48,6 +49,7 @@ func (q *Query) WithSQL(query string) *Query {
4849
Interval: q.Interval,
4950
TimeRange: q.TimeRange,
5051
MaxDataPoints: q.MaxDataPoints,
52+
FillMissing: q.FillMissing,
5153
Schema: q.Schema,
5254
Table: q.Table,
5355
Column: q.Column,
@@ -70,6 +72,7 @@ func GetQuery(query backend.DataQuery) (*Query, error) {
7072
Interval: query.Interval,
7173
TimeRange: query.TimeRange,
7274
MaxDataPoints: query.MaxDataPoints,
75+
FillMissing: model.FillMissing,
7376
Schema: model.Schema,
7477
Table: model.Table,
7578
Column: model.Column,

0 commit comments

Comments
 (0)