public final class FileUtils extends Object
Modifier and Type | Field and Description |
---|---|
static org.apache.hadoop.fs.PathFilter |
HIDDEN_FILES_PATH_FILTER |
static org.apache.hadoop.fs.PathFilter |
STAGING_DIR_PATH_FILTER |
Modifier and Type | Method and Description |
---|---|
static void |
checkDeletePermission(org.apache.hadoop.fs.Path path,
org.apache.hadoop.conf.Configuration conf,
String user)
Checks if delete can be performed on given path by given user.
|
static void |
checkFileAccessWithImpersonation(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.FileStatus stat,
org.apache.hadoop.fs.permission.FsAction action,
String user)
Perform a check to determine if the user is able to access the file passed in.
|
static boolean |
copy(org.apache.hadoop.fs.FileSystem srcFS,
org.apache.hadoop.fs.Path src,
org.apache.hadoop.fs.FileSystem dstFS,
org.apache.hadoop.fs.Path dst,
boolean deleteSource,
boolean overwrite,
HiveConf conf)
Copies files between filesystems.
|
static boolean |
equalsFileSystem(org.apache.hadoop.fs.FileSystem fs1,
org.apache.hadoop.fs.FileSystem fs2) |
static String |
escapePathName(String path) |
static String |
escapePathName(String path,
String defaultPath)
Escapes a path name.
|
static org.apache.hadoop.fs.FileStatus |
getFileStatusOrNull(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Attempts to get file status.
|
static org.apache.hadoop.fs.FileStatus |
getPathOrParentThatExists(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Find the parent of path that exists, if path does not exist
|
static boolean |
isActionPermittedForFileHierarchy(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.FileStatus fileStatus,
String userName,
org.apache.hadoop.fs.permission.FsAction action)
Check if user userName has permissions to perform the given FsAction action
on all files under the file whose FileStatus fileStatus is provided
|
static boolean |
isLocalFile(HiveConf conf,
String fileName)
A best effort attempt to determine if if the file is a local file
|
static boolean |
isLocalFile(HiveConf conf,
URI fileUri)
A best effort attempt to determine if if the file is a local file
|
static boolean |
isOwnerOfFileHierarchy(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.FileStatus fileStatus,
String userName) |
static boolean |
isSubDir(org.apache.hadoop.fs.Path p1,
org.apache.hadoop.fs.Path p2,
org.apache.hadoop.fs.FileSystem fs)
Check if first path is a subdirectory of second path.
|
static void |
listStatusRecursively(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.FileStatus fileStatus,
List<org.apache.hadoop.fs.FileStatus> results)
Recursively lists status for all files starting from a particular directory (or individual file
as base case).
|
static String |
makeDefaultListBucketingDirName(List<String> skewedCols,
String name)
default directory will have the same depth as number of skewed columns
this will make future operation easy like DML merge, concatenate merge
|
static String |
makeListBucketingDirName(List<String> lbCols,
List<String> vals)
Makes a valid list bucketing directory name.
|
static String |
makePartName(List<String> partCols,
List<String> vals) |
static String |
makePartName(List<String> partCols,
List<String> vals,
String defaultStr)
Makes a valid partition name.
|
static org.apache.hadoop.fs.Path |
makeQualified(org.apache.hadoop.fs.Path path,
org.apache.hadoop.conf.Configuration conf)
Variant of Path.makeQualified that qualifies the input path against the default file system
indicated by the configuration
This does not require a FileSystem handle in most cases - only requires the Filesystem URI.
|
static boolean |
mkdir(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path f,
boolean inheritPerms,
org.apache.hadoop.conf.Configuration conf)
Creates the directory and all necessary parent directories.
|
static boolean |
moveToTrash(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path f,
org.apache.hadoop.conf.Configuration conf)
Move a particular file or directory to the trash.
|
static boolean |
renameWithPerms(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path sourcePath,
org.apache.hadoop.fs.Path destPath,
boolean inheritPerms,
org.apache.hadoop.conf.Configuration conf) |
static boolean |
trashFilesUnderDir(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path f,
org.apache.hadoop.conf.Configuration conf)
Deletes all files under a directory, sending them to the trash.
|
static String |
unescapePathName(String path) |
public static final org.apache.hadoop.fs.PathFilter HIDDEN_FILES_PATH_FILTER
public static final org.apache.hadoop.fs.PathFilter STAGING_DIR_PATH_FILTER
public static org.apache.hadoop.fs.Path makeQualified(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf) throws IOException
path
- path to be fully qualifiedconf
- Configuration fileIOException
public static String makePartName(List<String> partCols, List<String> vals, String defaultStr)
partCols
- The partition keys' namesvals
- The partition valuesdefaultStr
- The default name given to a partition value if the respective value is empty or null.public static String makeDefaultListBucketingDirName(List<String> skewedCols, String name)
skewedCols
- name
- public static String makeListBucketingDirName(List<String> lbCols, List<String> vals)
lbCols
- The skewed keys' namesvals
- The skewed valuespublic static String escapePathName(String path, String defaultPath)
path
- The path to escape.defaultPath
- The default name for the path, if the given path is empty or null.public static void listStatusRecursively(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.FileStatus fileStatus, List<org.apache.hadoop.fs.FileStatus> results) throws IOException
fs
- file systemfileStatus
- starting point in file systemresults
- receives enumeration of all files foundIOException
public static org.apache.hadoop.fs.FileStatus getPathOrParentThatExists(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs
- file systempath
- IOException
public static void checkFileAccessWithImpersonation(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.FileStatus stat, org.apache.hadoop.fs.permission.FsAction action, String user) throws IOException, AccessControlException, InterruptedException, Exception
fs
- FileSystem of the path to checkstat
- FileStatus representing the fileaction
- FsAction that will be checkeduser
- User name of the user that will be checked for access. If the user name
is null or the same as the current user, no user impersonation will be done
and the check will be done as the current user. Otherwise the file access
check will be performed within a doAs() block to use the access privileges
of this user. In this case the user must be configured to impersonate other
users, otherwise this check will fail with error.IOException
AccessControlException
InterruptedException
Exception
public static boolean isActionPermittedForFileHierarchy(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.FileStatus fileStatus, String userName, org.apache.hadoop.fs.permission.FsAction action) throws Exception
fs
- fileStatus
- userName
- action
- IOException
Exception
public static boolean isLocalFile(HiveConf conf, String fileName)
conf
- fileName
- public static boolean isLocalFile(HiveConf conf, URI fileUri)
conf
- fileUri
- public static boolean isOwnerOfFileHierarchy(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.FileStatus fileStatus, String userName) throws IOException
IOException
public static boolean mkdir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path f, boolean inheritPerms, org.apache.hadoop.conf.Configuration conf) throws IOException
fs
- FileSystem to usef
- path to create.inheritPerms
- whether directory inherits the permission of the last-existing parent pathconf
- Hive configurationIOException
- exception in creating the directorypublic static boolean copy(org.apache.hadoop.fs.FileSystem srcFS, org.apache.hadoop.fs.Path src, org.apache.hadoop.fs.FileSystem dstFS, org.apache.hadoop.fs.Path dst, boolean deleteSource, boolean overwrite, HiveConf conf) throws IOException
IOException
public static boolean trashFilesUnderDir(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path f, org.apache.hadoop.conf.Configuration conf) throws FileNotFoundException, IOException
fs
- FileSystem to usef
- path of directoryconf
- hive configurationFileNotFoundException
IOException
public static boolean moveToTrash(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path f, org.apache.hadoop.conf.Configuration conf) throws IOException
fs
- FileSystem to usef
- path of file or directory to move to trash.conf
- IOException
public static boolean isSubDir(org.apache.hadoop.fs.Path p1, org.apache.hadoop.fs.Path p2, org.apache.hadoop.fs.FileSystem fs)
p1
- first pathp2
- second pathfs
- FileSystem, both paths must belong to the same filesystempublic static boolean renameWithPerms(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path sourcePath, org.apache.hadoop.fs.Path destPath, boolean inheritPerms, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
public static boolean equalsFileSystem(org.apache.hadoop.fs.FileSystem fs1, org.apache.hadoop.fs.FileSystem fs2)
fs1
- fs2
- public static void checkDeletePermission(org.apache.hadoop.fs.Path path, org.apache.hadoop.conf.Configuration conf, String user) throws AccessControlException, InterruptedException, Exception
path
- conf
- user
- AccessControlException
InterruptedException
Exception
public static org.apache.hadoop.fs.FileStatus getFileStatusOrNull(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs
- file system to checkpath
- file system path to checkIOException
- if there is an I/O errorCopyright © 2017 The Apache Software Foundation. All rights reserved.