Skip to content

Commit fb0e622

Browse files
addressed feedback
Signed-off-by: Raymond Cypher <[email protected]>
1 parent 00bd733 commit fb0e622

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

connection.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
102102
// we have an operation id so update the logger
103103
log = logger.WithContext(c.id, driverctx.CorrelationIdFromContext(ctx), client.SprintGuid(exStmtResp.OperationHandle.OperationId.GUID))
104104

105-
// since we have an operation handle we can close the operation
106-
if opStatusResp == nil || opStatusResp.GetOperationState() != cli_service.TOperationState_CLOSED_STATE {
105+
// since we have an operation handle we can close the operation if necessary
106+
alreadyClosed := exStmtResp.DirectResults != nil && exStmtResp.DirectResults.CloseOperation != nil
107+
if !alreadyClosed && (opStatusResp == nil || opStatusResp.GetOperationState() != cli_service.TOperationState_CLOSED_STATE) {
107108
_, err1 := c.client.CloseOperation(ctx, &cli_service.TCloseOperationReq{
108109
OperationHandle: exStmtResp.OperationHandle,
109110
})
110111
if err1 != nil {
111-
log.Err(err1).Msg("failed to close operation after executing statement")
112+
log.Err(err1).Msg("databricks: failed to close operation after executing statement")
112113
}
113114
}
114115
}

connection_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ func TestConn_executeStatement(t *testing.T) {
167167
assert.Equal(t, 1, executeStatementCount)
168168
assert.Equal(t, opTest.closeOperationCount, closeOperationCount)
169169
}
170+
171+
// if the execute statement response contains direct results with a non-nil CloseOperation member
172+
// we shouldn't call close
173+
closeOperationCount = 0
174+
executeStatementCount = 0
175+
executeStatementResp.DirectResults.CloseOperation = &cli_service.TCloseOperationResp{}
176+
finished := cli_service.TOperationState_FINISHED_STATE
177+
executeStatementResp.DirectResults.OperationStatus.OperationState = &finished
178+
_, err := testConn.ExecContext(context.Background(), "select 1", []driver.NamedValue{})
179+
assert.NoError(t, err)
180+
assert.Equal(t, 1, executeStatementCount)
181+
assert.Equal(t, 0, closeOperationCount)
170182
})
171183

172184
}

0 commit comments

Comments
 (0)