@@ -17,6 +17,9 @@ import (
17
17
"github.com/influxdata/flux/internal/function"
18
18
"github.com/influxdata/flux/memory"
19
19
"github.com/influxdata/flux/plan"
20
+ "github.com/opentracing/opentracing-go"
21
+ "github.com/opentracing/opentracing-go/ext"
22
+ "github.com/opentracing/opentracing-go/log"
20
23
)
21
24
22
25
const SqlKind = "experimental/iox.sql"
@@ -116,6 +119,10 @@ func (s *sqlSource) createSchema(schema *stdarrow.Schema) ([]flux.ColMeta, error
116
119
}
117
120
118
121
func (s * sqlSource ) run (ctx context.Context ) error {
122
+ span , ctx := opentracing .StartSpanFromContext (ctx , "sqlSouce.run" )
123
+ defer span .Finish ()
124
+ span .LogFields (log .String ("query" , s .query ))
125
+
119
126
// Note: query args are not actually supported yet, see
120
127
// https://github.com/influxdata/influxdb_iox/issues/3718
121
128
rr , err := s .client .Query (ctx , s .query , nil , s .mem )
@@ -130,14 +137,31 @@ func (s *sqlSource) run(ctx context.Context) error {
130
137
}
131
138
key := execute .NewGroupKey (nil , nil )
132
139
133
- for rr .Next () {
140
+ hasMore , err := nextRecordBatch (rr )
141
+ for hasMore && err == nil {
134
142
if err := s .produce (key , cols , rr .Record ()); err != nil {
143
+ ext .LogError (span , err )
135
144
return err
136
145
}
146
+ hasMore , err = nextRecordBatch (rr )
137
147
}
148
+ if err != nil {
149
+ ext .LogError (span , err )
150
+ return err
151
+ }
152
+
138
153
return nil
139
154
}
140
155
156
+ func nextRecordBatch (rr iox.RecordReader ) (bool , error ) {
157
+ n := rr .Next ()
158
+ if n {
159
+ return true , nil
160
+ }
161
+
162
+ return false , rr .Err ()
163
+ }
164
+
141
165
func (s * sqlSource ) produce (key flux.GroupKey , cols []flux.ColMeta , record stdarrow.Record ) error {
142
166
buffer := arrow.TableBuffer {
143
167
GroupKey : key ,
0 commit comments