class BigQueryConfiguration {

  public static String getTemporaryPathRoot(Configuration conf, @Nullable JobID jobId)
      throws IOException {
    // Try using the temporary gcs path.
    String pathRoot = conf.get(BigQueryConfiguration.TEMP_GCS_PATH.getKey());

    if (Strings.isNullOrEmpty(pathRoot)) {
      checkNotNull(jobId, "jobId is required if '%s' is not set", TEMP_GCS_PATH.getKey());
      logger.atInfo().log(
          "Fetching key '%s' since '%s' isn't set explicitly.",
          GCS_BUCKET.getKey(), TEMP_GCS_PATH.getKey());

      String gcsBucket = conf.get(GCS_BUCKET.getKey());
      if (Strings.isNullOrEmpty(gcsBucket)) {
        throw new IOException(
            "Must supply a value for configuration setting: " + GCS_BUCKET.getKey());
      }

      pathRoot = String.format("gs://%s/hadoop/tmp/bigquery/%s", gcsBucket, jobId);
    }

    logger.atInfo().log("Using working path: '%s'", pathRoot);
    Path workingPath = new Path(pathRoot);

    FileSystem fs = workingPath.getFileSystem(conf);
    Preconditions.checkState("gs".equals(fs.getScheme()), "Export FS must be GCS ('gs' scheme).");
    return pathRoot;
  }

}