Class BigqueryUtils


  • public class BigqueryUtils
    extends java.lang.Object
    Utilities related to Bigquery.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.joda.time.format.DateTimeFormatter BIGQUERY_TIMESTAMP_FORMAT
      A DateTimeFormatter that defines how to print DateTimes in a string format that BigQuery can interpret and how to parse the string formats that BigQuery emits into DateTimes.
    • Constructor Summary

      Constructors 
      Constructor Description
      BigqueryUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.joda.time.DateTime fromBigqueryTimestampString​(java.lang.String timestampString)
      Returns the DateTime for a given human-readable string-formatted BigQuery timestamp.
      static java.lang.String toBigqueryTimestamp​(long timestamp, java.util.concurrent.TimeUnit unit)
      Converts a time (in TimeUnits since the epoch) into a numeric string that BigQuery understands as a timestamp: the decimal number of seconds since the epoch, precise up to microseconds.
      static java.lang.String toBigqueryTimestamp​(org.joda.time.DateTime dateTime)
      Converts a DateTime into a numeric string that BigQuery understands as a timestamp: the decimal number of seconds since the epoch, precise up to microseconds.
      static java.lang.String toBigqueryTimestampString​(org.joda.time.DateTime dateTime)
      Returns the human-readable string version of the given DateTime, suitable for conversion within BigQuery from a string literal into a BigQuery timestamp type.
      static java.lang.String toJobReferenceString​(com.google.api.services.bigquery.model.JobReference jobRef)
      Returns the canonical string format for a JobReference object (the project ID and then job ID, delimited by a single colon) since JobReference.toString() is not customized to return it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BIGQUERY_TIMESTAMP_FORMAT

        public static final org.joda.time.format.DateTimeFormatter BIGQUERY_TIMESTAMP_FORMAT
        A DateTimeFormatter that defines how to print DateTimes in a string format that BigQuery can interpret and how to parse the string formats that BigQuery emits into DateTimes.

        The general format definition is "YYYY-MM-DD HH:MM:SS.SSS[ ZZ]", where the fractional seconds portion can have 0-6 decimal places (although we restrict it to 0-3 here since Joda DateTime only supports up to millisecond precision) and the zone if not specified defaults to UTC.

        Although we expect a zone specification of "UTC" when parsing, we don't emit it when printing because in some cases BigQuery does not allow any time zone specification (instead it assumes UTC for whatever input you provide) for input timestamp strings (see b/16380363).

        See Also:
        BigQuery Data Types - TIMESTAMP
    • Constructor Detail

      • BigqueryUtils

        public BigqueryUtils()
    • Method Detail

      • toBigqueryTimestampString

        public static java.lang.String toBigqueryTimestampString​(org.joda.time.DateTime dateTime)
        Returns the human-readable string version of the given DateTime, suitable for conversion within BigQuery from a string literal into a BigQuery timestamp type.
      • fromBigqueryTimestampString

        public static org.joda.time.DateTime fromBigqueryTimestampString​(java.lang.String timestampString)
        Returns the DateTime for a given human-readable string-formatted BigQuery timestamp.
      • toBigqueryTimestamp

        public static java.lang.String toBigqueryTimestamp​(long timestamp,
                                                           java.util.concurrent.TimeUnit unit)
        Converts a time (in TimeUnits since the epoch) into a numeric string that BigQuery understands as a timestamp: the decimal number of seconds since the epoch, precise up to microseconds.
        See Also:
        Data Types
      • toBigqueryTimestamp

        public static java.lang.String toBigqueryTimestamp​(org.joda.time.DateTime dateTime)
        Converts a DateTime into a numeric string that BigQuery understands as a timestamp: the decimal number of seconds since the epoch, precise up to microseconds.

        Note that since DateTime only stores milliseconds, the last 3 digits will be zero.

        See Also:
        Data Types
      • toJobReferenceString

        public static java.lang.String toJobReferenceString​(com.google.api.services.bigquery.model.JobReference jobRef)
        Returns the canonical string format for a JobReference object (the project ID and then job ID, delimited by a single colon) since JobReference.toString() is not customized to return it.