Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presto: Pass custom configuration object when using FileSystemUtils #43

Merged
merged 1 commit into from
Apr 14, 2020
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 @@ -53,7 +53,9 @@ public String copyToLocalFile(String remoteFilename) {
Path remotePath = new Path(remoteFilename);
Path localPath = new Path(Paths.get(getAndCreateLocalDir(), new File(remoteFilename).getName()).toString());
FileSystem fs = remotePath.getFileSystem(conf);
String resolvedRemoteFilename = FileSystemUtils.resolveLatest(remoteFilename);
// It is important to pass the custom configuration object to FileSystemUtils since we load some extra
// properties from etc/**.xml in getConfiguration() for Presto
String resolvedRemoteFilename = FileSystemUtils.resolveLatest(remoteFilename, conf);
Path resolvedRemotePath = new Path(resolvedRemoteFilename);
fs.copyToLocalFile(resolvedRemotePath, localPath);
return localPath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobConf;

/**
* This Utils class handles multiple utilities methods related with Hadoop FileSystem.
*
*/
public class FileSystemUtils {
public static final String MAPREDUCE_FRAMEWORK_NAME = "mapreduce.framework.name";
public static final String MAPRED_JOB_TRACKER = "mapred.job.tracker";
public static final String LOCAL = "local";

private FileSystemUtils() {
// Empty on purpose
Expand All @@ -35,12 +31,18 @@ private FileSystemUtils() {
* @return the Path's FileSystem if we are not in local mode, local FileSystem if we are.
*/
public static FileSystem getFileSystem(String filePath) {
return getFileSystem(filePath, new Configuration());
}

/**
* Same as {@link #getFileSystem(String)} but allows passing a {@link Configuration} used to resolve the path
*/
public static FileSystem getFileSystem(String filePath, Configuration conf) {
FileSystem fs;
JobConf conf = new JobConf();
try {
fs = new Path(filePath).getFileSystem(conf);
} catch (IOException e) {
throw new RuntimeException("Failed to load the HDFS file system.", e);
throw new RuntimeException("Failed to load the file system for path: " + filePath, e);
}

return fs;
Expand Down Expand Up @@ -76,11 +78,18 @@ public static FileSystem getLocalFileSystem() {
* @throws IOException when the filesystem could not resolve the path
*/
public static String resolveLatest(String path) throws IOException {
return resolveLatest(path, new Configuration());
}

/**
* Same as {@link #resolveLatest(String)} but allows passing a {@link Configuration} used to resolve the path
*/
public static String resolveLatest(String path, Configuration conf) throws IOException {
if (!StringUtils.isBlank(path)) {
path = path.trim();
String[] split = path.split("#LATEST");
String retval = split[0];
FileSystem fs = getFileSystem(path);
FileSystem fs = getFileSystem(path, conf);
for (int i = 1; i < split.length; ++i) {
retval = resolveLatestHelper(retval, fs, true) + split[i];
}
Expand Down