@@ -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