Skip to content

Commit c5a757c

Browse files
authored
[PECOBLR-860] Bugfix : volume operation (#984)
## Description - The bug - Current JDBC Repo has a bug, in which volume operations are not executed. - Step to reproduce : use a script to generate a large csv file (say 1.5GB), execute the PUT query - you won't be able to see the file uploaded. - The customer would have to iterate through the resultSet for the volume operation to be completed. This is the workaround customers can use as of today : ``` ResultSet rs = con.createStatement() .executeQuery( "PUT 'test_csv_files/large_file.csv' INTO '/Volumes/testingcatalog/default/testvol/mytestfolder/test1'"); while(rs.next()){ //Nothing } ``` - This PR fixes the above issue without the need of any hacky fix. ## Testing - Tested locally ## Additional Notes to the Reviewer - This needs to be added to the JDK8 branch as well, will raise a PR for the same
1 parent f28c9a6 commit c5a757c

3 files changed

Lines changed: 94 additions & 160 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
### Fixed
1919
- Integrated Azure U2M flow into driver for improved stability.
2020
- Fixed `ResultSet.getString` for Boolean columns in Metadata result set.
21+
- Fixed volume operations not completing unless the ResultSet is fully iterated.
2122
---
2223
*Note: When making changes, please add your change under the appropriate section with a brief description.*

src/main/java/com/databricks/jdbc/api/impl/volume/VolumeOperationResult.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public VolumeOperationResult(
4747
long totalColumns,
4848
IDatabricksSession session,
4949
IExecutionResult resultHandler,
50-
IDatabricksStatementInternal statement) {
50+
IDatabricksStatementInternal statement)
51+
throws DatabricksSQLException {
5152
this.rowCount = totalRows;
5253
this.columnCount = totalColumns;
5354
this.session = session;
@@ -57,6 +58,7 @@ public VolumeOperationResult(
5758
DatabricksHttpClientFactory.getInstance()
5859
.getClient(session.getConnectionContext(), HttpClientType.VOLUME);
5960
this.currentRowIndex = -1;
61+
completeVolumeOperation();
6062
}
6163

6264
@VisibleForTesting
@@ -65,14 +67,16 @@ public VolumeOperationResult(
6567
IDatabricksSession session,
6668
IExecutionResult resultHandler,
6769
IDatabricksHttpClient httpClient,
68-
IDatabricksStatementInternal statement) {
70+
IDatabricksStatementInternal statement)
71+
throws DatabricksSQLException {
6972
this.rowCount = manifest.getTotalRowCount();
7073
this.columnCount = manifest.getSchema().getColumnCount();
7174
this.session = session;
7275
this.resultHandler = resultHandler;
7376
this.statement = statement;
7477
this.httpClient = httpClient;
7578
this.currentRowIndex = -1;
79+
completeVolumeOperation();
7680
}
7781

7882
private void initHandler(IExecutionResult resultHandler) throws DatabricksSQLException {
@@ -181,7 +185,12 @@ public Object getObject(int columnIndex) throws DatabricksSQLException {
181185
if (columnIndex == 0) {
182186
return volumeOperationProcessor.getStatus().name();
183187
}
184-
String errorMessage = (currentRowIndex < 0) ? "Invalid row access" : "Invalid column access";
188+
String userMessage = (currentRowIndex < 0) ? "Invalid row access" : "Invalid column access";
189+
String errorMessage =
190+
String.format(
191+
"%s, Row: %s, Column: %s, statementID %s",
192+
userMessage, currentRowIndex, columnIndex, statement.getStatementId());
193+
LOGGER.error(errorMessage);
185194
throw new DatabricksVolumeOperationException(
186195
errorMessage, DatabricksDriverErrorCode.VOLUME_OPERATION_INVALID_STATE);
187196
}
@@ -193,16 +202,21 @@ public long getCurrentRow() {
193202

194203
@Override
195204
public boolean next() throws DatabricksSQLException {
196-
if (hasNext()) {
205+
if (currentRowIndex == -1) {
206+
currentRowIndex++;
207+
return true;
208+
} else {
209+
return false;
210+
}
211+
}
212+
213+
private void completeVolumeOperation() throws DatabricksSQLException {
214+
while (resultHandler.hasNext()) {
197215
validateMetadata();
198216
resultHandler.next();
199217
initHandler(resultHandler);
200218
volumeOperationProcessor.process();
201219
ensureSuccessVolumeProcessorStatus();
202-
currentRowIndex++;
203-
return true;
204-
} else {
205-
return false;
206220
}
207221
}
208222

@@ -217,7 +231,7 @@ public InputStreamEntity getVolumeOperationInputStream() {
217231

218232
@Override
219233
public boolean hasNext() {
220-
return resultHandler.hasNext();
234+
return currentRowIndex == -1;
221235
}
222236

223237
@Override

0 commit comments

Comments
 (0)