Search in sources :

Example 81 with PathFilter

use of org.apache.hadoop.fs.PathFilter in project drill by axbaretto.

the class FileSystemUtilTest method testListFilesWithFilter.

@Test
public void testListFilesWithFilter() throws IOException {
    List<FileStatus> statuses = FileSystemUtil.listFiles(fs, new Path(base, "a"), false, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith(".txt");
        }
    });
    assertEquals("File count should match", 3, statuses.size());
    Collections.sort(statuses);
    assertEquals("File name should match", ".f.txt", statuses.get(0).getPath().getName());
    assertEquals("File name should match", "_f.txt", statuses.get(1).getPath().getName());
    assertEquals("File name should match", "f.txt", statuses.get(2).getPath().getName());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 82 with PathFilter

use of org.apache.hadoop.fs.PathFilter in project drill by axbaretto.

the class FileSystemUtilTest method testListDirectoriesEmptyResult.

@Test
public void testListDirectoriesEmptyResult() throws IOException {
    List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, false, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().startsWith("abc");
        }
    });
    assertEquals("Directory count should match", 0, statuses.size());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 83 with PathFilter

use of org.apache.hadoop.fs.PathFilter in project drill by axbaretto.

the class FileSystemUtilTest method testListDirectoriesWithFilter.

@Test
public void testListDirectoriesWithFilter() throws IOException {
    List<FileStatus> statuses = FileSystemUtil.listDirectories(fs, base, false, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith("a");
        }
    });
    assertEquals("Directory count should match", 3, statuses.size());
    Collections.sort(statuses);
    assertEquals("Directory name should match", ".a", statuses.get(0).getPath().getName());
    assertEquals("Directory name should match", "_a", statuses.get(1).getPath().getName());
    assertEquals("Directory name should match", "a", statuses.get(2).getPath().getName());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 84 with PathFilter

use of org.apache.hadoop.fs.PathFilter in project drill by axbaretto.

the class FileSystemUtilTest method testListAllWithFilter.

@Test
public void testListAllWithFilter() throws IOException {
    List<FileStatus> statuses = FileSystemUtil.listAll(fs, new Path(base, "a"), false, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith("a") || path.getName().endsWith(".txt");
        }
    });
    assertEquals("Directory and file count should match", 4, statuses.size());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Example 85 with PathFilter

use of org.apache.hadoop.fs.PathFilter in project drill by axbaretto.

the class FileSystemUtilTest method testListFilesRecursiveWithFilter.

@Test
public void testListFilesRecursiveWithFilter() throws IOException {
    List<FileStatus> statuses = FileSystemUtil.listFiles(fs, base, true, new PathFilter() {

        @Override
        public boolean accept(Path path) {
            return path.getName().endsWith("a") || path.getName().endsWith(".txt");
        }
    });
    assertEquals("File count should match", 8, statuses.size());
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Test(org.junit.Test)

Aggregations

PathFilter (org.apache.hadoop.fs.PathFilter)123 Path (org.apache.hadoop.fs.Path)114 FileStatus (org.apache.hadoop.fs.FileStatus)96 Test (org.junit.Test)47 IOException (java.io.IOException)42 FileSystem (org.apache.hadoop.fs.FileSystem)39 ArrayList (java.util.ArrayList)22 List (java.util.List)19 Configuration (org.apache.hadoop.conf.Configuration)18 Collections (java.util.Collections)11 BufferedReader (java.io.BufferedReader)9 InputStreamReader (java.io.InputStreamReader)9 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 URI (java.net.URI)8 Test (org.testng.annotations.Test)8 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)7 IGNORED (com.facebook.presto.hive.NestedDirectoryPolicy.IGNORED)6 RECURSE (com.facebook.presto.hive.NestedDirectoryPolicy.RECURSE)6