|
6 | 6 | import com.databricks.jdbc.client.IDatabricksUCVolumeClient; |
7 | 7 | import com.databricks.jdbc.commons.LogLevel; |
8 | 8 | import com.databricks.jdbc.commons.util.LoggingUtil; |
9 | | -import com.databricks.jdbc.core.DatabricksStatement; |
| 9 | +import com.databricks.jdbc.core.IDatabricksResultSet; |
| 10 | +import com.databricks.jdbc.core.IDatabricksStatement; |
10 | 11 | import java.io.InputStream; |
11 | 12 | import java.sql.*; |
12 | 13 | import java.util.ArrayList; |
@@ -41,6 +42,12 @@ private String createGetObjectQuery( |
41 | 42 | "GET '/Volumes/%s/%s/%s/%s' TO '%s'", catalog, schema, volume, objectPath, localPath); |
42 | 43 | } |
43 | 44 |
|
| 45 | + private String createGetObjectQueryForInputStream( |
| 46 | + String catalog, String schema, String volume, String objectPath) { |
| 47 | + return String.format( |
| 48 | + "GET '/Volumes/%s/%s/%s/%s' TO '__input_stream__'", catalog, schema, volume, objectPath); |
| 49 | + } |
| 50 | + |
44 | 51 | private String createPutObjectQuery( |
45 | 52 | String catalog, |
46 | 53 | String schema, |
@@ -293,6 +300,36 @@ public boolean getObject( |
293 | 300 | return volumeOperationStatus; |
294 | 301 | } |
295 | 302 |
|
| 303 | + @Override |
| 304 | + public InputStream getObject(String catalog, String schema, String volume, String objectPath) |
| 305 | + throws SQLException { |
| 306 | + |
| 307 | + LoggingUtil.log( |
| 308 | + LogLevel.DEBUG, |
| 309 | + String.format( |
| 310 | + "Entering getObject method with parameters: catalog={%s}, schema={%s}, volume={%s}, objectPath={%s}", |
| 311 | + catalog, schema, volume, objectPath)); |
| 312 | + |
| 313 | + String getObjectQuery = createGetObjectQueryForInputStream(catalog, schema, volume, objectPath); |
| 314 | + |
| 315 | + Statement statement = connection.createStatement(); |
| 316 | + IDatabricksStatement databricksStatement = (IDatabricksStatement) statement; |
| 317 | + databricksStatement.allowInputStreamForVolumeOperation(true); |
| 318 | + |
| 319 | + ResultSet resultSet = statement.executeQuery(getObjectQuery); |
| 320 | + LoggingUtil.log(LogLevel.INFO, "GET query executed successfully"); |
| 321 | + |
| 322 | + try { |
| 323 | + if (resultSet.next()) { |
| 324 | + return ((IDatabricksResultSet) resultSet).getVolumeOperationInputStream(); |
| 325 | + } |
| 326 | + return null; |
| 327 | + } catch (SQLException e) { |
| 328 | + LoggingUtil.log(LogLevel.ERROR, "GET query execution failed " + e); |
| 329 | + throw e; |
| 330 | + } |
| 331 | + } |
| 332 | + |
296 | 333 | public boolean putObject( |
297 | 334 | String catalog, |
298 | 335 | String schema, |
@@ -353,11 +390,11 @@ public boolean putObject( |
353 | 390 | boolean volumeOperationStatus = false; |
354 | 391 |
|
355 | 392 | try (Statement statement = connection.createStatement()) { |
356 | | - DatabricksStatement databricksStatement = (DatabricksStatement) statement; |
| 393 | + IDatabricksStatement databricksStatement = (IDatabricksStatement) statement; |
357 | 394 | databricksStatement.allowInputStreamForVolumeOperation(true); |
358 | 395 | databricksStatement.setInputStreamForUCVolume(inputStream); |
359 | 396 |
|
360 | | - ResultSet resultSet = databricksStatement.executeQuery(putObjectQueryForInputStream); |
| 397 | + ResultSet resultSet = statement.executeQuery(putObjectQueryForInputStream); |
361 | 398 | LoggingUtil.log(LogLevel.INFO, "PUT query executed successfully"); |
362 | 399 |
|
363 | 400 | if (resultSet.next()) { |
|
0 commit comments