mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 11:13:26 +08:00
pass tsdbQuery to transformToTimeSeries and transformToTable to get
access to selected frontend timerange
This commit is contained in:
@ -56,7 +56,7 @@ func (e *MysqlQueryEndpoint) Query(ctx context.Context, dsInfo *models.DataSourc
|
|||||||
return e.sqlEngine.Query(ctx, dsInfo, tsdbQuery, e.transformToTimeSeries, e.transformToTable)
|
return e.sqlEngine.Query(ctx, dsInfo, tsdbQuery, e.transformToTimeSeries, e.transformToTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e MysqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
func (e MysqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
||||||
columnNames, err := rows.Columns()
|
columnNames, err := rows.Columns()
|
||||||
columnCount := len(columnNames)
|
columnCount := len(columnNames)
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func (e MysqlQueryEndpoint) getTypedRowData(types []*sql.ColumnType, rows *core.
|
|||||||
return values, nil
|
return values, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
func (e MysqlQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
||||||
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
||||||
seriesByQueryOrder := list.New()
|
seriesByQueryOrder := list.New()
|
||||||
columnNames, err := rows.Columns()
|
columnNames, err := rows.Columns()
|
||||||
|
@ -60,7 +60,7 @@ func (e *PostgresQueryEndpoint) Query(ctx context.Context, dsInfo *models.DataSo
|
|||||||
return e.sqlEngine.Query(ctx, dsInfo, tsdbQuery, e.transformToTimeSeries, e.transformToTable)
|
return e.sqlEngine.Query(ctx, dsInfo, tsdbQuery, e.transformToTimeSeries, e.transformToTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e PostgresQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
func (e PostgresQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
||||||
|
|
||||||
columnNames, err := rows.Columns()
|
columnNames, err := rows.Columns()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -157,7 +157,7 @@ func (e PostgresQueryEndpoint) getTypedRowData(rows *core.Rows) (tsdb.RowValues,
|
|||||||
return values, nil
|
return values, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult, tsdbQuery *tsdb.TsdbQuery) error {
|
||||||
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
||||||
seriesByQueryOrder := list.New()
|
seriesByQueryOrder := list.New()
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ type SqlEngine interface {
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
ds *models.DataSource,
|
ds *models.DataSource,
|
||||||
query *TsdbQuery,
|
query *TsdbQuery,
|
||||||
transformToTimeSeries func(query *Query, rows *core.Rows, result *QueryResult) error,
|
transformToTimeSeries func(query *Query, rows *core.Rows, result *QueryResult, tsdbQuery *TsdbQuery) error,
|
||||||
transformToTable func(query *Query, rows *core.Rows, result *QueryResult) error,
|
transformToTable func(query *Query, rows *core.Rows, result *QueryResult, tsdbQuery *TsdbQuery) error,
|
||||||
) (*Response, error)
|
) (*Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ func (e *DefaultSqlEngine) Query(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
dsInfo *models.DataSource,
|
dsInfo *models.DataSource,
|
||||||
tsdbQuery *TsdbQuery,
|
tsdbQuery *TsdbQuery,
|
||||||
transformToTimeSeries func(query *Query, rows *core.Rows, result *QueryResult) error,
|
transformToTimeSeries func(query *Query, rows *core.Rows, result *QueryResult, tsdbQuery *TsdbQuery) error,
|
||||||
transformToTable func(query *Query, rows *core.Rows, result *QueryResult) error,
|
transformToTable func(query *Query, rows *core.Rows, result *QueryResult, tsdbQuery *TsdbQuery) error,
|
||||||
) (*Response, error) {
|
) (*Response, error) {
|
||||||
result := &Response{
|
result := &Response{
|
||||||
Results: make(map[string]*QueryResult),
|
Results: make(map[string]*QueryResult),
|
||||||
@ -117,13 +117,13 @@ func (e *DefaultSqlEngine) Query(
|
|||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case "time_series":
|
case "time_series":
|
||||||
err := transformToTimeSeries(query, rows, queryResult)
|
err := transformToTimeSeries(query, rows, queryResult, tsdbQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResult.Error = err
|
queryResult.Error = err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case "table":
|
case "table":
|
||||||
err := transformToTable(query, rows, queryResult)
|
err := transformToTable(query, rows, queryResult, tsdbQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
queryResult.Error = err
|
queryResult.Error = err
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user