下面列出了怎么用org.apache.hadoop.fs.GlobPattern的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void prepare() throws IOException {
String argPattern = getArgument(1);
if (!caseSensitive) {
argPattern = StringUtils.toLowerCase(argPattern);
}
globPattern = new GlobPattern(argPattern);
}
@Override
public void prepare() throws IOException {
String argPattern = getArgument(1);
if (!caseSensitive) {
argPattern = StringUtils.toLowerCase(argPattern);
}
globPattern = new GlobPattern(argPattern);
}
public static Path getFirstMatch(FileSystem fs, Path path, String globPatternStr, boolean recursive)
throws IOException
{
RemoteIterator<LocatedFileStatus> files = fs.listFiles(path, recursive);
GlobPattern globPattern = new GlobPattern(globPatternStr);
while (files.hasNext())
{
Path aFile = files.next().getPath();
if(globPattern.matches(aFile.getName()))
return aFile;
}
return null;
}
/**
* A helper to determine if the path description of this {@link DatasetDescriptor} is a superset of paths
* accepted by the other {@link DatasetDescriptor}. If the path description of the other {@link DatasetDescriptor}
* is a glob pattern, we return false.
*
* @param otherPath a glob pattern that describes a set of paths.
* @return true if the glob pattern described by the otherPath matches the path in this {@link DatasetDescriptor}.
*/
private boolean isPathContaining(String otherPath) {
if (otherPath == null) {
return false;
}
if (DatasetDescriptorConfigKeys.DATASET_DESCRIPTOR_CONFIG_ANY.equals(this.getPath())) {
return true;
}
if (PathUtils.isGlob(new Path(otherPath))) {
return false;
}
GlobPattern globPattern = new GlobPattern(this.getPath());
return globPattern.matches(otherPath);
}
String createHiveDatasetWhitelist() {
if (new GlobPattern(this.databaseName).hasWildcard()) {
return this.databaseName + ".*";
} else {
return this.databaseName + "." + this.tableName.replace(',', '|');
}
}
/** {@inheritDoc} */
@Override
public void initialise(FindOptions options) {
String argPattern = getArguments().get(0);
if(!caseSensitive) {
argPattern = argPattern.toLowerCase();
}
globPattern = new GlobPattern(argPattern);
}
/**
* Determines based on suitability of {@code fixedPath} whether to use flat globbing logic where
* we use a single large listing during globStatus to then perform the core globbing logic
* in-memory.
*/
@VisibleForTesting
boolean couldUseFlatGlob(Path fixedPath) {
// Only works for filesystems where the base Hadoop Path scheme matches the underlying URI
// scheme for GCS.
if (!getUri().getScheme().equals(GoogleCloudStorageFileSystem.SCHEME)) {
logger.atFinest().log(
"Flat glob is on, but doesn't work for scheme '%s', using default behavior.",
getUri().getScheme());
return false;
}
// The full pattern should have a wildcard, otherwise there's no point doing the flat glob.
GlobPattern fullPattern = new GlobPattern(fixedPath.toString());
if (!fullPattern.hasWildcard()) {
logger.atFinest().log(
"Flat glob is on, but Path '%s' has no wildcard, using default behavior.", fixedPath);
return false;
}
// To use a flat glob, there must be an authority defined.
if (isNullOrEmpty(fixedPath.toUri().getAuthority())) {
logger.atFinest().log(
"Flat glob is on, but Path '%s' has a empty authority, using default behavior.",
fixedPath);
return false;
}
// And the authority must not contain a wildcard.
GlobPattern authorityPattern = new GlobPattern(fixedPath.toUri().getAuthority());
if (authorityPattern.hasWildcard()) {
logger.atFinest().log(
"Flat glob is on, but Path '%s' has a wildcard authority, using default behavior.",
fixedPath);
return false;
}
return true;
}
@Override
protected Pattern compile(String s) {
return GlobPattern.compile(s);
}
@Override
protected Pattern compile(String s) {
return GlobPattern.compile(s);
}
/**
* Compile glob pattern string
*
* @param globPattern the glob pattern
* @return the pattern object
*/
public static Pattern compile(String globPattern) {
return new GlobPattern(globPattern).compiled();
}