Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gortools/src/main/scala/gorsat/Analysis/ForkWrite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.apache.commons.lang3.StringUtils
import org.gorpipe.exceptions.GorResourceException
import org.gorpipe.gor.binsearch.GorIndexType
import org.gorpipe.gor.driver.linkfile.{LinkFile, LinkFileEntryV1}
import org.gorpipe.gor.driver.meta.DataType
import org.gorpipe.gor.driver.meta.{DataType, SourceReference}
import org.gorpipe.gor.driver.providers.stream.sources.StreamSource
import org.gorpipe.gor.model.{DriverBackedFileReader, Row}
import org.gorpipe.gor.session.{GorSession, ProjectContext}
Expand Down Expand Up @@ -159,8 +159,10 @@ case class ForkWrite(forkCol: Int,
fullFileName.replace("#{fork}", forkValue).replace("""${fork}""", forkValue)
} else {
if (fullFileName.isEmpty && options.linkFile.nonEmpty) {
val linkSourceRef = new SourceReference(options.linkFile, null, projectContext.getFileReader.getCommonRoot, null, null, true);
// Infer the full file name from the link (and defautl locations)
LinkFile.inferDataFileNameFromLinkFile(projectContext.getFileReader.resolveUrl(options.linkFile).asInstanceOf[StreamSource])
LinkFile.inferDataFileNameFromLinkFile(
projectContext.getFileReader.resolveDataSource(linkSourceRef).asInstanceOf[StreamSource]);
} else {
fullFileName
}
Expand Down
18 changes: 18 additions & 0 deletions gortools/src/test/java/gorsat/UTestGorWrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ public void testWriteLinkFileWithInferFileName() throws IOException {

}

@Test
public void testWriteLinkFileWithInferFileNameForExistingLink() throws IOException {

environmentVariables.set(GorDriverConfig.GOR_DRIVER_LINK_MANAGED_DATA_FILES_URL, workDirPath.resolve("managed_data").toString());
TestUtils.runGorPipe("gorrow chr1,1,100 | write -link ltest.gor", "-gorroot", workDirPath.toString());
TestUtils.runGorPipe("gorrow chr1,1,101 | write -link ltest.gor", "-gorroot", workDirPath.toString());

var linkFile = LinkFile.load(new FileSource(workDirPath.resolve("ltest.gor.link").toString()));

Assert.assertEquals(2, linkFile.getEntriesCount());
Assert.assertTrue(linkFile.getLatestEntry().url().startsWith(workDirPath.resolve("managed_data/" + workDirPath.getFileName() + "/ltest").toString()));
Assert.assertTrue(linkFile.getLatestEntry().url().endsWith(".gor"));
Assert.assertTrue(Files.exists(Path.of(linkFile.getLatestEntry().url())));
Assert.assertEquals("#chrom\tbpStart\tbpStop\nchr1\t1\t101\n",
Files.readString(Path.of(linkFile.getLatestEntry().url())));

}

@Test
public void testTxtWriteServer() throws IOException {
Path p = Paths.get("../tests/data/nor/simple.nor");
Expand Down
Loading