Skip to content

Commit 01b7d80

Browse files
Add nil handling for isStagingOperation to handle older DBR versions
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent c4d5d18 commit 01b7d80

File tree

2 files changed

+97
-3
lines changed

2 files changed

+97
-3
lines changed

connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ func (c *conn) execStagingOperation(
571571
var err error
572572

573573
var isStagingOperation bool
574-
if exStmtResp.DirectResults != nil && exStmtResp.DirectResults.ResultSetMetadata != nil && exStmtResp.DirectResults.ResultSetMetadata.IsStagingOperation != nil {
575-
isStagingOperation = *exStmtResp.DirectResults.ResultSetMetadata.IsStagingOperation
574+
if exStmtResp.DirectResults != nil && exStmtResp.DirectResults.ResultSetMetadata != nil {
575+
isStagingOperation = exStmtResp.DirectResults.ResultSetMetadata.IsStagingOperation != nil && *exStmtResp.DirectResults.ResultSetMetadata.IsStagingOperation
576576
} else {
577577
req := cli_service.TGetResultSetMetadataReq{
578578
OperationHandle: exStmtResp.OperationHandle,
@@ -581,7 +581,7 @@ func (c *conn) execStagingOperation(
581581
if err != nil {
582582
return dbsqlerrint.NewDriverError(ctx, "error performing staging operation", err)
583583
}
584-
isStagingOperation = *resp.IsStagingOperation
584+
isStagingOperation = resp.IsStagingOperation != nil && *resp.IsStagingOperation
585585
}
586586

587587
if !isStagingOperation {

connection_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,100 @@ func TestConn_PrepareContext(t *testing.T) {
16771677
})
16781678
}
16791679

1680+
func TestConn_execStagingOperation(t *testing.T) {
1681+
t.Run("handles nil IsStagingOperation from DirectResults", func(t *testing.T) {
1682+
testClient := &client.TestClient{}
1683+
testConn := &conn{
1684+
session: getTestSession(),
1685+
client: testClient,
1686+
cfg: config.WithDefaults(),
1687+
}
1688+
1689+
// Create response with nil IsStagingOperation in DirectResults
1690+
exStmtResp := &cli_service.TExecuteStatementResp{
1691+
Status: &cli_service.TStatus{
1692+
StatusCode: cli_service.TStatusCode_SUCCESS_STATUS,
1693+
},
1694+
OperationHandle: &cli_service.TOperationHandle{
1695+
OperationId: &cli_service.THandleIdentifier{
1696+
GUID: []byte{1, 2, 3, 4, 2, 23, 4, 2, 3, 1, 2, 3, 4, 223, 34, 54},
1697+
Secret: []byte("b"),
1698+
},
1699+
},
1700+
DirectResults: &cli_service.TSparkDirectResults{
1701+
ResultSetMetadata: &cli_service.TGetResultSetMetadataResp{
1702+
Status: &cli_service.TStatus{
1703+
StatusCode: cli_service.TStatusCode_SUCCESS_STATUS,
1704+
},
1705+
// IsStagingOperation is nil
1706+
},
1707+
},
1708+
}
1709+
1710+
// Mock GetResultSetMetadata to return false for IsStagingOperation
1711+
var getResultSetMetadataCount int
1712+
getResultSetMetadata := func(ctx context.Context, req *cli_service.TGetResultSetMetadataReq) (_r *cli_service.TGetResultSetMetadataResp, _err error) {
1713+
getResultSetMetadataCount++
1714+
var falseVal = false
1715+
return &cli_service.TGetResultSetMetadataResp{
1716+
Status: &cli_service.TStatus{
1717+
StatusCode: cli_service.TStatusCode_SUCCESS_STATUS,
1718+
},
1719+
IsStagingOperation: &falseVal,
1720+
}, nil
1721+
}
1722+
testClient.FnGetResultSetMetadata = getResultSetMetadata
1723+
1724+
ctx := context.Background()
1725+
err := testConn.execStagingOperation(exStmtResp, ctx)
1726+
1727+
assert.Nil(t, err)
1728+
assert.Equal(t, 0, getResultSetMetadataCount) // should not be called since DirectResults.ResultSetMetadata exists
1729+
})
1730+
1731+
t.Run("handles nil IsStagingOperation from GetResultSetMetadata", func(t *testing.T) {
1732+
testClient := &client.TestClient{}
1733+
testConn := &conn{
1734+
session: getTestSession(),
1735+
client: testClient,
1736+
cfg: config.WithDefaults(),
1737+
}
1738+
1739+
// Create response with nil DirectResults.ResultSetMetadata
1740+
exStmtResp := &cli_service.TExecuteStatementResp{
1741+
Status: &cli_service.TStatus{
1742+
StatusCode: cli_service.TStatusCode_SUCCESS_STATUS,
1743+
},
1744+
OperationHandle: &cli_service.TOperationHandle{
1745+
OperationId: &cli_service.THandleIdentifier{
1746+
GUID: []byte{1, 2, 3, 4, 2, 23, 4, 2, 3, 1, 2, 3, 4, 223, 34, 54},
1747+
Secret: []byte("b"),
1748+
},
1749+
},
1750+
// DirectResults.ResultSetMetadata is nil
1751+
}
1752+
1753+
// Mock GetResultSetMetadata to return nil for IsStagingOperation
1754+
var getResultSetMetadataCount int
1755+
getResultSetMetadata := func(ctx context.Context, req *cli_service.TGetResultSetMetadataReq) (_r *cli_service.TGetResultSetMetadataResp, _err error) {
1756+
getResultSetMetadataCount++
1757+
return &cli_service.TGetResultSetMetadataResp{
1758+
Status: &cli_service.TStatus{
1759+
StatusCode: cli_service.TStatusCode_SUCCESS_STATUS,
1760+
},
1761+
// IsStagingOperation is nil
1762+
}, nil
1763+
}
1764+
testClient.FnGetResultSetMetadata = getResultSetMetadata
1765+
1766+
ctx := context.Background()
1767+
err := testConn.execStagingOperation(exStmtResp, ctx)
1768+
1769+
assert.Nil(t, err)
1770+
assert.Equal(t, 1, getResultSetMetadataCount) // should be called since DirectResults.ResultSetMetadata is nil
1771+
})
1772+
}
1773+
16801774
func getTestSession() *cli_service.TOpenSessionResp {
16811775
return &cli_service.TOpenSessionResp{SessionHandle: &cli_service.TSessionHandle{
16821776
SessionId: &cli_service.THandleIdentifier{

0 commit comments

Comments
 (0)