public static FileSelection create( final DrillFileSystem fs, final String parent, final String path) throws IOException { Stopwatch timer = Stopwatch.createStarted(); final Path combined = new Path(parent, removeLeadingSlash(path)); final FileStatus[] statuses = fs.globStatus(combined); if (statuses == null) { return null; } final FileSelection fileSel = create(Lists.newArrayList(statuses), null, combined.toUri().toString()); logger.debug("FileSelection.create() took {} ms ", timer.elapsed(TimeUnit.MILLISECONDS)); return fileSel; }
public List<FileStatus> getStatuses(final DrillFileSystem fs) throws IOException { Stopwatch timer = Stopwatch.createStarted(); if (statuses == null) { final List<FileStatus> newStatuses = Lists.newArrayList(); for (final String pathStr : files) { newStatuses.add(fs.getFileStatus(new Path(pathStr))); } statuses = newStatuses; } logger.debug( "FileSelection.getStatuses() took {} ms, numFiles: {}", timer.elapsed(TimeUnit.MILLISECONDS), statuses == null ? 0 : statuses.size()); return statuses; }
public FileSelection minusDirectories(DrillFileSystem fs) throws IOException { if (isExpanded()) { return this; } Stopwatch timer = Stopwatch.createStarted(); final List<FileStatus> statuses = getStatuses(fs); final int total = statuses.size(); final Path[] paths = new Path[total]; for (int i = 0; i < total; i++) { paths[i] = statuses.get(i).getPath(); } final List<FileStatus> allStats = fs.list(true, paths); final List<FileStatus> nonDirectories = Lists.newArrayList( Iterables.filter( allStats, new Predicate<FileStatus>() { @Override public boolean apply(@Nullable FileStatus status) { return !status.isDirectory(); } })); final FileSelection fileSel = create(nonDirectories, null, selectionRoot); logger.debug( "FileSelection.minusDirectories() took {} ms, numFiles: {}", timer.elapsed(TimeUnit.MILLISECONDS), total); // fileSel will be null if we query an empty folder if (fileSel != null) { fileSel.setExpanded(); } return fileSel; }