Search in sources :

Example 1 with LOCAL_FILE_FILESYSTEM_ERROR

use of com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_FILESYSTEM_ERROR in project presto by prestodb.

the class DataLocation method files.

public List<File> files() {
    checkState(location.exists(), "location %s doesn't exist", location);
    if (!pattern.isPresent()) {
        return ImmutableList.of(location);
    }
    checkState(location.isDirectory(), "location %s is not a directory", location);
    try (DirectoryStream<Path> paths = newDirectoryStream(location.toPath(), pattern.get())) {
        ImmutableList.Builder<File> builder = ImmutableList.builder();
        for (Path path : paths) {
            builder.add(path.toFile());
        }
        List<File> files = builder.build();
        if (files.isEmpty()) {
            throw new PrestoException(LOCAL_FILE_NO_FILES, "No matching files found in directory: " + location);
        }
        return files.stream().sorted((o1, o2) -> Long.compare(o2.lastModified(), o1.lastModified())).collect(Collectors.toList());
    } catch (IOException e) {
        throw new PrestoException(LOCAL_FILE_FILESYSTEM_ERROR, "Error listing files in directory: " + location, e);
    }
}
Also used : Path(java.nio.file.Path) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) IOException(java.io.IOException) PrestoException(com.facebook.presto.spi.PrestoException) Collectors(java.util.stream.Collectors) File(java.io.File) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DirectoryStream(java.nio.file.DirectoryStream) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) Optional(java.util.Optional) Files.newDirectoryStream(java.nio.file.Files.newDirectoryStream) Path(java.nio.file.Path) LOCAL_FILE_NO_FILES(com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_NO_FILES) LOCAL_FILE_FILESYSTEM_ERROR(com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_FILESYSTEM_ERROR) ImmutableList(com.google.common.collect.ImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) File(java.io.File)

Aggregations

LOCAL_FILE_FILESYSTEM_ERROR (com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_FILESYSTEM_ERROR)1 LOCAL_FILE_NO_FILES (com.facebook.presto.localfile.LocalFileErrorCode.LOCAL_FILE_NO_FILES)1 PrestoException (com.facebook.presto.spi.PrestoException)1 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 IOException (java.io.IOException)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files.newDirectoryStream (java.nio.file.Files.newDirectoryStream)1 Path (java.nio.file.Path)1 List (java.util.List)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1