Skip to content

Commit

Permalink
SNOW-1846830 allow triple slash file prefix (file:///) (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mkubik authored Feb 10, 2025
1 parent fdebcea commit 6d5d616
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ private void uploadFiles(Set<String> fileList, int parallel) throws SnowflakeSQL
threadExecutor.submit(
getUploadFileCallable(
stageInfo,
srcFile,
srcFileObj.getPath(),
fileMetadata,
(stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS)
? null
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/FileUploaderLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/** Tests for SnowflakeFileTransferAgent that require an active connection */
@Tag(TestTags.OTHERS)
Expand Down Expand Up @@ -885,4 +886,32 @@ public void testUploadWithTildeInPath() throws SQLException, IOException {
FileUtils.deleteDirectory(subDir.toFile());
}
}

@Test
public void testUploadWithTripleSlashFilePrefix(@TempDir File tempDir)
throws SQLException, IOException {
String stageName = "testStage" + SnowflakeUtil.randomAlphaNumeric(10);
try (Connection connection = getConnection();
Statement statement = connection.createStatement()) {
try {
statement.execute("CREATE OR REPLACE STAGE " + stageName);
SFSession sfSession = connection.unwrap(SnowflakeConnectionV1.class).getSfSession();

String command =
"PUT file:///" + getFullPathFileInResource(TEST_DATA_FILE) + " @" + stageName;
SnowflakeFileTransferAgent sfAgent =
new SnowflakeFileTransferAgent(command, sfSession, new SFStatement(sfSession));
assertTrue(sfAgent.execute());

String tempDirPath = tempDir.getCanonicalPath().replace("\\", "/");
String getCommand = "GET @" + stageName + " file:///" + tempDirPath;
SnowflakeFileTransferAgent sfAgent1 =
new SnowflakeFileTransferAgent(getCommand, sfSession, new SFStatement(sfSession));
assertTrue(sfAgent1.execute());
assertEquals(1, sfAgent1.statusRows.size());
} finally {
statement.execute("DROP STAGE if exists " + stageName);
}
}
}
}

0 comments on commit 6d5d616

Please sign in to comment.