@@ -159,23 +159,35 @@ func (d *Datasource) RefreshDBConnection() error {
159
159
return nil
160
160
}
161
161
162
- func (d * Datasource ) ExecuteQuery (queryString string ) (* sql.Rows , error ) {
163
- rows , err := d .databricksDB .Query (queryString )
162
+ // ExecContext is a helper function to execute a query on the Databricks SQL DB without returning any rows and handling session expiration
163
+ func (d * Datasource ) ExecContext (ctx context.Context , queryString string ) error {
164
+ _ , err := d .databricksDB .ExecContext (ctx , queryString )
164
165
if err != nil {
165
166
if strings .Contains (err .Error (), "Invalid SessionHandle" ) {
166
167
err = d .RefreshDBConnection ()
167
168
if err != nil {
168
- return nil , err
169
+ return err
169
170
}
170
- rows , err = d .ExecuteQuery (queryString )
171
+ return d .ExecContext (ctx , queryString )
172
+ }
173
+ return err
174
+ }
175
+ return nil
176
+ }
177
+
178
+ // QueryContext is a helper function to query the Databricks SQL DB returning the rows and handling session expiration
179
+ func (d * Datasource ) QueryContext (ctx context.Context , queryString string ) (* sql.Rows , error ) {
180
+ rows , err := d .databricksDB .QueryContext (ctx , queryString )
181
+ if err != nil {
182
+ if strings .Contains (err .Error (), "Invalid SessionHandle" ) {
183
+ err = d .RefreshDBConnection ()
171
184
if err != nil {
172
185
return nil , err
173
186
}
174
- } else {
175
- return nil , err
187
+ return d .QueryContext (ctx , queryString )
176
188
}
189
+ return nil , err
177
190
}
178
-
179
191
return rows , nil
180
192
}
181
193
@@ -187,7 +199,7 @@ type Datasource struct {
187
199
}
188
200
189
201
func (d * Datasource ) CallResource (ctx context.Context , req * backend.CallResourceRequest , sender backend.CallResourceResponseSender ) error {
190
- return autocompletionQueries (req , sender , d )
202
+ return autocompletionQueries (ctx , req , sender , d )
191
203
}
192
204
193
205
// Dispose here tells plugin SDK that plugin wants to clean up resources when a new instance
@@ -230,7 +242,7 @@ type queryModel struct {
230
242
QuerySettings querySettings `json:"querySettings"`
231
243
}
232
244
233
- func (d * Datasource ) query (_ context.Context , pCtx backend.PluginContext , query backend.DataQuery ) backend.DataResponse {
245
+ func (d * Datasource ) query (ctx context.Context , pCtx backend.PluginContext , query backend.DataQuery ) backend.DataResponse {
234
246
response := backend.DataResponse {}
235
247
236
248
// Unmarshal the JSON into our queryModel.
@@ -260,7 +272,7 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query
260
272
if len (queries ) > 1 {
261
273
// Execute all but the last statement without returning any data
262
274
for _ , query := range queries [:len (queries )- 1 ] {
263
- _ , err := d .ExecuteQuery ( query )
275
+ err := d .ExecContext ( ctx , query )
264
276
if err != nil {
265
277
response .Error = err
266
278
log .DefaultLogger .Info ("Error" , "err" , err )
@@ -276,7 +288,7 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query
276
288
277
289
frame := data .NewFrame ("response" )
278
290
279
- rows , err := d .ExecuteQuery ( queryString )
291
+ rows , err := d .QueryContext ( ctx , queryString )
280
292
if err != nil {
281
293
response .Error = err
282
294
log .DefaultLogger .Info ("Error" , "err" , err )
@@ -332,10 +344,10 @@ func (d *Datasource) query(_ context.Context, pCtx backend.PluginContext, query
332
344
// The main use case for these health checks is the test button on the
333
345
// datasource configuration page which allows users to verify that
334
346
// a datasource is working as expected.
335
- func (d * Datasource ) CheckHealth (_ context.Context , req * backend.CheckHealthRequest ) (* backend.CheckHealthResult , error ) {
347
+ func (d * Datasource ) CheckHealth (ctx context.Context , req * backend.CheckHealthRequest ) (* backend.CheckHealthResult , error ) {
336
348
log .DefaultLogger .Info ("CheckHealth called" , "request" , req )
337
349
338
- rows , err := d .ExecuteQuery ( "SELECT 1" )
350
+ rows , err := d .QueryContext ( ctx , "SELECT 1" )
339
351
340
352
if err != nil {
341
353
return & backend.CheckHealthResult {
0 commit comments