Skip to content

Commit 6d5d616

Browse files
SNOW-1846830 allow triple slash file prefix (file:///) (#2033)
1 parent fdebcea commit 6d5d616

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/main/java/net/snowflake/client/jdbc/SnowflakeFileTransferAgent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ private void uploadFiles(Set<String> fileList, int parallel) throws SnowflakeSQL
18811881
threadExecutor.submit(
18821882
getUploadFileCallable(
18831883
stageInfo,
1884-
srcFile,
1884+
srcFileObj.getPath(),
18851885
fileMetadata,
18861886
(stageInfo.getStageType() == StageInfo.StageType.LOCAL_FS)
18871887
? null

src/test/java/net/snowflake/client/jdbc/FileUploaderLatestIT.java

+29
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.commons.io.FileUtils;
5050
import org.junit.jupiter.api.Tag;
5151
import org.junit.jupiter.api.Test;
52+
import org.junit.jupiter.api.io.TempDir;
5253

5354
/** Tests for SnowflakeFileTransferAgent that require an active connection */
5455
@Tag(TestTags.OTHERS)
@@ -885,4 +886,32 @@ public void testUploadWithTildeInPath() throws SQLException, IOException {
885886
FileUtils.deleteDirectory(subDir.toFile());
886887
}
887888
}
889+
890+
@Test
891+
public void testUploadWithTripleSlashFilePrefix(@TempDir File tempDir)
892+
throws SQLException, IOException {
893+
String stageName = "testStage" + SnowflakeUtil.randomAlphaNumeric(10);
894+
try (Connection connection = getConnection();
895+
Statement statement = connection.createStatement()) {
896+
try {
897+
statement.execute("CREATE OR REPLACE STAGE " + stageName);
898+
SFSession sfSession = connection.unwrap(SnowflakeConnectionV1.class).getSfSession();
899+
900+
String command =
901+
"PUT file:///" + getFullPathFileInResource(TEST_DATA_FILE) + " @" + stageName;
902+
SnowflakeFileTransferAgent sfAgent =
903+
new SnowflakeFileTransferAgent(command, sfSession, new SFStatement(sfSession));
904+
assertTrue(sfAgent.execute());
905+
906+
String tempDirPath = tempDir.getCanonicalPath().replace("\\", "/");
907+
String getCommand = "GET @" + stageName + " file:///" + tempDirPath;
908+
SnowflakeFileTransferAgent sfAgent1 =
909+
new SnowflakeFileTransferAgent(getCommand, sfSession, new SFStatement(sfSession));
910+
assertTrue(sfAgent1.execute());
911+
assertEquals(1, sfAgent1.statusRows.size());
912+
} finally {
913+
statement.execute("DROP STAGE if exists " + stageName);
914+
}
915+
}
916+
}
888917
}

0 commit comments

Comments
 (0)