Example usage for org.apache.hadoop.fs GlobPattern hasWildcard

List of usage examples for org.apache.hadoop.fs GlobPattern hasWildcard

Introduction

In this page you can find the example usage for org.apache.hadoop.fs GlobPattern hasWildcard.

Prototype

boolean hasWildcard

To view the source code for org.apache.hadoop.fs GlobPattern hasWildcard.

Click Source Link

Usage

From source file:com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystemBase.java

License:Open Source License

/**
 * Determines based on config settings and 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.//  w w  w. ja  v  a 2  s . co m
 */
@VisibleForTesting
boolean shouldUseFlatGlob(Path fixedPath) {
    // Config setting overrides all else.
    if (!enableFlatGlob) {
        return false;
    }

    // Only works for filesystems where the base Hadoop Path scheme matches the underlying URI
    // scheme for GCS.
    if (!getUri().getScheme().equals(GoogleCloudStorageFileSystem.SCHEME)) {
        LOG.debug("Flat glob is on, but doesn't work for scheme '{}'; usig 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()) {
        LOG.debug("Flat glob is on, but Path '{}' has no wildcard; using default behavior.", fixedPath);
        return false;
    }

    // To use a flat glob, there must be an authority defined.
    if (Strings.isNullOrEmpty(fixedPath.toUri().getAuthority())) {
        LOG.info("Flat glob is on, but Path '{}' 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()) {
        LOG.info("Flat glob is on, but Path '{}' has a wildcard authority, using default behavior.", fixedPath);
        return false;
    }

    return true;
}