All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.hadoop.io.bigquery.BigQueryFileFormat Maven / Gradle / Ivy

package com.google.cloud.hadoop.io.bigquery;

import com.google.common.base.Joiner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.classification.InterfaceStability;

/** An enum to describe file formats supported by the BigQuery api. */
@InterfaceStability.Unstable
public enum BigQueryFileFormat {

  /** Comma separated value exports */
  CSV(".csv", "CSV"),

  /** Newline delimited JSON */
  NEWLINE_DELIMITED_JSON(".json", "NEWLINE_DELIMITED_JSON"),

  /** Avro container files */
  AVRO(".avro", "AVRO");

  /** Map used for simple deserialization of strings into BigQueryFileFormats. */
  private static final Map NAMES_MAP =
      new HashMap();

  /** A formatted string of the accepted file formats. */
  private static final String ACCEPTED_FORMATS;

  static {
    List formats = new ArrayList();
    for (BigQueryFileFormat format : BigQueryFileFormat.values()) {
      NAMES_MAP.put(format.name(), format);
      formats.add(format.name());
    }

    ACCEPTED_FORMATS = Joiner.on(',').join(formats);
  }

  private final String extension;
  private final String formatIdentifier;

  private BigQueryFileFormat(String extension, String formatIdentifier) {
    this.extension = extension;
    this.formatIdentifier = formatIdentifier;
  }

  /** Get the default extension to denote the file format. */
  public String getExtension() {
    return extension;
  }

  /** Get the identifier to specify in API requests. */
  public String getFormatIdentifier() {
    return formatIdentifier;
  }

  /**
   * Deserializes the name of a BigQueryFileFormat. If there is no matching BigQueryFileFormat for
   * the given name, an IllegalArugmentException is thrown.
   *
   * @param name the name of the BigQueryFileFormat as returned from {@link
   *     BigQueryFileFormat#name()}.
   * @return the associated BigQueryFileFormat.
   */
  public static BigQueryFileFormat fromName(String name) {
    BigQueryFileFormat entry = NAMES_MAP.get(name);
    if (entry == null) {
      throw new IllegalArgumentException(
          "Unable to find BigQueryFileFormat for '"
              + name
              + "'. Accepted formats are: [ "
              + ACCEPTED_FORMATS
              + " ]");
    }
    return entry;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy