This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb-extras.git


The following commit(s) were added to refs/heads/master by this push:
     new b4953d1  Fixed the issue where the Grafana plugin does not display 
data when there is no time value (#13)
b4953d1 is described below

commit b4953d1c6b54110d26f3c4c6acca04d046265c5e
Author: CloudWise-Lukemiao <[email protected]>
AuthorDate: Mon Aug 5 11:34:44 2024 +0800

    Fixed the issue where the Grafana plugin does not display data when there 
is no time value (#13)
    
    Co-authored-by: luke.miao <[email protected]>
---
 connectors/grafana-plugin/pkg/plugin/plugin.go | 36 ++++++++++++++------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/connectors/grafana-plugin/pkg/plugin/plugin.go 
b/connectors/grafana-plugin/pkg/plugin/plugin.go
index 5f3b374..49f4a25 100644
--- a/connectors/grafana-plugin/pkg/plugin/plugin.go
+++ b/connectors/grafana-plugin/pkg/plugin/plugin.go
@@ -292,24 +292,26 @@ func (d *IoTDBDataSource) query(cxt context.Context, pCtx 
backend.PluginContext,
        // create data frame response.
        frame := data.NewFrame("response")
        for i := 0; i < len(queryDataResp.Expressions); i++ {
-               if queryDataResp.Timestamps == nil || 
len(queryDataResp.Timestamps) == 0 {
-                       times := make([]time.Time, 1)
-                       tmp := make([]float64, 1)
-                       frame.Fields = append(frame.Fields,
-                               data.NewField("time", nil, times),
-                               data.NewField(queryDataResp.Expressions[i], 
nil, tmp),
-                       )
-                       continue
-               }
-               times := make([]time.Time, len(queryDataResp.Timestamps))
-               for c := 0; c < len(queryDataResp.Timestamps); c++ {
-                       times[c] = time.Unix(0, 
queryDataResp.Timestamps[c]*1000000)
+               if queryDataResp.Timestamps != nil && 
len(queryDataResp.Timestamps) > 0 {
+                       times := make([]time.Time, 
len(queryDataResp.Timestamps))
+                       for c := 0; c < len(queryDataResp.Timestamps); c++ {
+                               times[c] = time.Unix(0, 
queryDataResp.Timestamps[c]*1000000)
+                       }
+                       if queryDataResp.Values != nil && 
len(queryDataResp.Values) > 0 {
+                               values := recoverType(queryDataResp.Values[i])
+                               frame.Fields = append(frame.Fields,
+                                       data.NewField("time", nil, times),
+                                       
data.NewField(queryDataResp.Expressions[i], nil, values),
+                               )
+                       }
+               } else {
+                       if queryDataResp.Values != nil && 
len(queryDataResp.Values) > 0 {
+                               values := recoverType(queryDataResp.Values[i])
+                               frame.Fields = append(frame.Fields,
+                                       
data.NewField(queryDataResp.Expressions[i], nil, values),
+                               )
+                       }
                }
-               values := recoverType(queryDataResp.Values[i])
-               frame.Fields = append(frame.Fields,
-                       data.NewField("time", nil, times),
-                       data.NewField(queryDataResp.Expressions[i], nil, 
values),
-               )
        }
 
        response.Frames = append(response.Frames, frame)

Reply via email to