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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -456,7 +457,7 @@ private int doBucketize(TableLock bucketizeLock, BucketPackLevel packLevel, int
private void doBucketizeForBucketDir(DictionaryTable tempTable, String bucketDir, Map<String, List<T>> newBucketsMap, int maxBucketCount) throws IOException {
Map<String, List<T>> newBucketsMapForBucketDir =
newBucketsMap.keySet().stream()
.filter(p -> PathUtils.getParent(p).equals(PathUtils.stripTrailingSlash(bucketDir)))
.filter(p -> PathUtils.pathEquals(PathUtils.getParent(p), bucketDir))
.collect(Collectors.toMap(Function.identity(), newBucketsMap::get));

// Create the bucket files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public void testBucketFolders() throws Exception {
buckets = table.filter().get().stream().map(l -> l.getBucket()).distinct().collect(Collectors.toList());
List<String> bucketFolders = buckets.stream().map(l -> PathUtils.getParent(l)).distinct().collect(Collectors.toList());
Assert.assertEquals("Incorrect number of bucket folders", 1, bucketFolders.size());
Assert.assertEquals("Incorrect bucket folder(s)", buc.pickBucketDir(), bucketFolders.get(0));
Assert.assertEquals("Incorrect bucket folder(s)", Path.of(buc.pickBucketDir()), Path.of(bucketFolders.get(0)));
for (String bucket : buckets) {
Assert.assertTrue("Bucket does not exists", Files.exists(Path.of(PathUtils.resolve(table.getRootPath(), bucket))));
}
Expand Down Expand Up @@ -839,7 +839,9 @@ private void testBucketDirsHelper(BucketManager buc, GorDictionaryTable table, L
buckets = table.filter().get().stream().map(l -> l.getBucket()).distinct().collect(Collectors.toList());
List<String> createdBucketFolders = buckets.stream().map(p -> PathUtils.getParent(p)).distinct().collect(Collectors.toList());
Assert.assertEquals("Incorrect number of bucket folders", bucketDirs.size(), createdBucketFolders.size());
Assert.assertEquals("Incorrect bucket folder(s)", new TreeSet(bucketDirs), new TreeSet(createdBucketFolders));
Assert.assertEquals("Incorrect bucket folder(s)",
new TreeSet(bucketDirs.stream().map(s -> Path.of(s)).toList()),
new TreeSet(createdBucketFolders.stream().map(s -> Path.of(s)).toList()));
for (String bucket : buckets) {
Assert.assertTrue(String.format("Bucket %s does not exists", PathUtils.resolve(table.getRootPath(), bucket)),
Files.exists(Path.of(PathUtils.resolve(table.getRootPath(), bucket))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public PRIORITY getPriority() {
@Override
public boolean match(String file) {
// TODO: Until we get better matching strategy we must exclude mem here.
// TODO: Should check if file (as commented out), but a lot code seems to pass various
// non file elements so simply match everything (like the former impl).
// We should be the last matcher anyway.
return !DataUtil.isMem(file); //&& (file.startsWith("file:") || !file.contains(":"));
return !DataUtil.isMem(file) && (file.startsWith("file:") || !file.contains(":/"));
}
}
12 changes: 11 additions & 1 deletion model/src/main/java/org/gorpipe/gor/table/util/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static URI toRealPath(URI uri) {
public static String getParent(String path) {
String p = stripTrailingSlash(path);
var idx = p.lastIndexOf("/");
return idx >= 0 ? p.substring(0,idx) : "";
return idx >= 0 ? p.substring(0,idx+1) : "";
}

public static String getFileName(String path) {
Expand Down Expand Up @@ -343,4 +343,14 @@ public static Path getTempFilePath(Path filePath) {
return tempFileName;
}

public static boolean pathEquals(String path1, String path2) {
if (path1 == null && path2 == null) {
return true;
}
if (path1 == null || path2 == null) {
return false;
}
return Path.of(path1).normalize().equals(Path.of(path2).normalize());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package org.gorpipe.gor.driver;

import gorsat.TestUtils;
import org.gorpipe.exceptions.GorResourceException;
import org.gorpipe.gor.driver.meta.DataType;
import org.gorpipe.gor.driver.meta.SourceReference;
import org.gorpipe.gor.driver.providers.stream.sources.file.FileSource;
import org.gorpipe.gor.model.GenomicIterator;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -64,4 +66,35 @@ public void noGuice() throws IOException {
Assert.assertNotNull(iterator);
}

@Test
public void testResolveDataSourceFile() throws IOException {
String fileName = "testfile.gor";
DataSource source = gorDriver.resolveDataSource(new SourceReference(fileName));
Assert.assertTrue(source instanceof FileSource);
Assert.assertEquals(fileName, source.getName());
}

@Test
public void testResolveDataSourceFileSchema() throws IOException {
String fileName = "testfile.gor";
DataSource source = gorDriver.resolveDataSource(new SourceReference("file://" + fileName));
Assert.assertTrue(source instanceof FileSource);
Assert.assertEquals(fileName, source.getName());
}

@Test
public void testResolveDataSourceS3Schema() throws IOException {
String fileName = "s3://testfile.gor";
DataSource source = gorDriver.resolveDataSource(new SourceReference(fileName));
Assert.assertEquals(fileName, source.getName());
}

@Test
public void testResolveDataSourceUnknownSchema() throws IOException {
String fileName = "bla://testfile" + DataType.GOR.suffix;
Assert.assertThrows(GorResourceException.class, () -> {
gorDriver.resolveDataSource(new SourceReference(fileName));
});
}

}
Loading