Skip to content

Commit

Permalink
Refactor to use try-with-resources for SnowflakeOutputConnection in C…
Browse files Browse the repository at this point in the history
…opyTask

- Updated the `call` method in `CopyTask` to use try-with-resources for managing `SnowflakeOutputConnection`.
- Ensured proper resource management and automatic closure of the connection.
- Improved code readability and reliability by eliminating the need for explicit connection close in the finally block.
  • Loading branch information
kentoyoshida committed Jul 8, 2024
1 parent accebc8 commit c91f7d7
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ public Void call() throws SQLException, InterruptedException, ExecutionException
try {
uploadFuture.get();

SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true);
try {
try (SnowflakeOutputConnection con = (SnowflakeOutputConnection) connector.connect(true)) {
logger.info("Running COPY from file {}", snowflakeStageFileName);

long startTime = System.currentTimeMillis();
Expand All @@ -446,9 +445,6 @@ public Void call() throws SQLException, InterruptedException, ExecutionException
logger.info(
String.format(
"Loaded file %s (%.2f seconds for COPY)", snowflakeStageFileName, seconds));

} finally {
con.close();
}
} finally {
if (deleteStageFile) {
Expand Down

0 comments on commit c91f7d7

Please sign in to comment.