@@ -45,32 +45,34 @@ func (d Direction) String() string {
4545
4646// Create a new result page iterator.
4747func NewResultPageIterator (
48+ ctx context.Context ,
4849 delimiter Delimiter ,
4950 maxPageSize int64 ,
5051 opHandle * cli_service.TOperationHandle ,
5152 closedOnServer bool ,
5253 client cli_service.TCLIService ,
53- connectionId string ,
54- correlationId string ,
5554 logger * dbsqllog.DBSQLLogger ,
5655) ResultPageIterator {
5756
5857 // delimiter and hasMoreRows are used to set up the point in the paginated
5958 // result set that this iterator starts from.
6059 return & resultPageIterator {
60+ ctx : ctx ,
6161 Delimiter : delimiter ,
6262 isFinished : closedOnServer ,
6363 maxPageSize : maxPageSize ,
6464 opHandle : opHandle ,
6565 closedOnServer : closedOnServer ,
6666 client : client ,
67- connectionId : connectionId ,
68- correlationId : correlationId ,
67+ connectionId : driverctx . ConnIdFromContext ( ctx ) ,
68+ correlationId : driverctx . CorrelationIdFromContext ( ctx ) ,
6969 logger : logger ,
7070 }
7171}
7272
7373type resultPageIterator struct {
74+ ctx context.Context
75+
7476 // Gives the parameters of the current result page
7577 Delimiter
7678
@@ -167,15 +169,14 @@ func (rpf *resultPageIterator) getNextPage() (*cli_service.TFetchResultsResp, er
167169 nextPageStartRow := rpf .Start () + rpf .Count ()
168170
169171 rpf .logger .Debug ().Msgf ("databricks: fetching result page for row %d" , nextPageStartRow )
170- ctx := driverctx .NewContextWithCorrelationId (driverctx .NewContextWithConnId (context .Background (), rpf .connectionId ), rpf .correlationId )
171172
172173 // Keep fetching in the appropriate direction until we have the expected page.
173174 var fetchResult * cli_service.TFetchResultsResp
174175 var b bool
175176 for b = rpf .Contains (nextPageStartRow ); ! b ; b = rpf .Contains (nextPageStartRow ) {
176177
177178 direction := rpf .Direction (nextPageStartRow )
178- err := rpf .checkDirectionValid (ctx , direction )
179+ err := rpf .checkDirectionValid (direction )
179180 if err != nil {
180181 return nil , err
181182 }
@@ -190,10 +191,10 @@ func (rpf *resultPageIterator) getNextPage() (*cli_service.TFetchResultsResp, er
190191 IncludeResultSetMetadata : & includeResultSetMetadata ,
191192 }
192193
193- fetchResult , err = rpf .client .FetchResults (ctx , & req )
194+ fetchResult , err = rpf .client .FetchResults (rpf . ctx , & req )
194195 if err != nil {
195196 rpf .logger .Err (err ).Msg ("databricks: Rows instance failed to retrieve results" )
196- return nil , dbsqlerrint .NewRequestError (ctx , errRowsResultFetchFailed , err )
197+ return nil , dbsqlerrint .NewRequestError (rpf . ctx , errRowsResultFetchFailed , err )
197198 }
198199
199200 rpf .Delimiter = NewDelimiter (fetchResult .Results .StartRowOffset , CountRows (fetchResult .Results ))
@@ -218,7 +219,7 @@ func (rpf *resultPageIterator) Close() (err error) {
218219 OperationHandle : rpf .opHandle ,
219220 }
220221
221- _ , err = rpf .client .CloseOperation (context . Background () , & req )
222+ _ , err = rpf .client .CloseOperation (rpf . ctx , & req )
222223 return err
223224 }
224225 }
@@ -283,11 +284,11 @@ func CountRows(rowSet *cli_service.TRowSet) int64 {
283284}
284285
285286// Check if trying to fetch in the specified direction creates an error condition.
286- func (rpf * resultPageIterator ) checkDirectionValid (ctx context. Context , direction Direction ) error {
287+ func (rpf * resultPageIterator ) checkDirectionValid (direction Direction ) error {
287288 if direction == DirBack {
288289 // can't fetch rows previous to the start
289290 if rpf .Start () == 0 {
290- return dbsqlerrint .NewDriverError (ctx , ErrRowsFetchPriorToStart , nil )
291+ return dbsqlerrint .NewDriverError (rpf . ctx , ErrRowsFetchPriorToStart , nil )
291292 }
292293 } else if direction == DirForward {
293294 // can't fetch past the end of the query results
@@ -296,7 +297,7 @@ func (rpf *resultPageIterator) checkDirectionValid(ctx context.Context, directio
296297 }
297298 } else {
298299 rpf .logger .Error ().Msgf (errRowsUnandledFetchDirection (direction .String ()))
299- return dbsqlerrint .NewDriverError (ctx , errRowsUnandledFetchDirection (direction .String ()), nil )
300+ return dbsqlerrint .NewDriverError (rpf . ctx , errRowsUnandledFetchDirection (direction .String ()), nil )
300301 }
301302 return nil
302303}
0 commit comments