GeezerVison is showing github.com (truncated) — Full support for DATE, TIME, and DATETIME in BigQuery by garrettjonesgoogle · Pull Request #1819 · googleapis/google-cloud-java
Conversation
Also:
- Using Timestamp instead of Long for timestamp values.
- Renaming Date to CivilDate, naming new types in an analogous way, CivilTime and CivilDateTime
Fixes #1792
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Note I have fixed the codacy errors - I'll push them with other PR updates.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
/**
|
|
|
* Creates a {@code QueryParameterValue} object with a type of DATETIME.
|
|
|
* Must be in the format "yyyy-MM-dd HH:mm:ss.SSSSSS", e.g. ""2014-08-19 12:41:35.220000".
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
* and Spanner DATE
|
|
|
* (https://cloud.google.com/spanner/docs/data-types#date-type).
|
|
|
*
|
|
|
* The DATE type represents a logical calendar date, independent of time zone. A DATE value
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
* Represents a time without timezone, e.g. 07:41:35.220000.
|
|
|
*
|
|
|
* CivilTime holds values for BigQuery TIME
|
|
|
* (https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#time-type).0
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
} else if (value instanceof String) {
|
|
|
// verify that the String is in the right format
|
|
|
timestampFormatter.parseMillis((String) value);
|
|
|
Timestamp.parseCloudTimestamp((String) value);
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Changes Unknown when pulling fee2415 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still looking at Timestamp.java
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
* @param date civil date
|
|
|
*/
|
|
|
public static CivilDateTime ofDate(CivilDate date) {
|
|
|
return ofDateAndTime(date, CivilTime.ofHoursMinutesSecondsNanos(0, 0, 0, 0));
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param dateTime Date plus time: (yyyy-MM-dd HH:mm:ss.SSSSSSSSS) or
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Constructs a new CivilDate instance.
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
nanos = (int) TimeUnit.MILLISECONDS.toNanos(fractionalNumber);
|
|
|
} else if (fractional.length() == 6) {
|
|
|
nanos = (int) TimeUnit.MICROSECONDS.toNanos(fractionalNumber);
|
|
|
} else {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
return time;
|
|
|
}
|
|
|
|
|
|
/** Formats the date and time in the format yyyy-MM-dd HH:mm:ss.SSSSSSSSS */
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
}
|
|
|
|
|
|
/** Formats the date and time in the format yyyy-MM-dd HH:mm:ss.SSSSSSSSS */
|
|
|
public String formatMicroCloudTime() {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
this.nanos = nanos;
|
|
|
}
|
|
|
|
|
|
public static Timestamp ofTimeMicroseconds(long microseconds) {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
*/
|
|
|
public static CivilDateTime parseDateTime(String dateTime) {
|
|
|
String splitToken = " ";
|
|
|
if (dateTime.contains("T")) {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Represents a date and time with no timezone, e.g. e.g. 2017-03-17 07:41:35.220000.
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
/** Regexp to split timestamps into date-hour-minute-second and fractional second components. */
|
|
|
private static final Pattern FORMAT_REGEXP = Pattern.compile("([^\\.]*)(\\.\\d{0,9})?Z");
|
|
|
private static final Pattern FORMAT_REGEXP = Pattern.compile("([^.]*)(\\.\\d{0,9})?Z");
|
|
|
private static final String DATE_GROUP = "(\\d{4}-\\d{1,2}-\\d{1,2})";
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
private static final String DATE_GROUP = "(\\d{4}-\\d{1,2}-\\d{1,2})";
|
|
|
private static final String TIME_GROUP = "(\\d{1,2}:\\d{1,2}:\\d{1,2})";
|
|
|
private static final String FRACT_GROUP = "\\.(\\d{1,9})";
|
|
|
private static final String TZ_GROUP = "([\\-+]\\d{1,2}(?::\\d{1,2})?)";
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
/**
|
|
|
* Creates a Timestamp instance from the given string. String is in the format
|
|
|
* yyyy-MM-dd HH:mm:ss.SSSSSSZZ. If no timezone is given, UTC is assumed.
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
DateTime dateTime = new DateTime();
|
|
|
dateTime = parseTz(dateTime, tz);
|
|
|
dateTime = parseDate(dateTime, Preconditions.checkNotNull(date));
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
return ofTimeSecondsAndNanos(TimeUnit.MILLISECONDS.toSeconds(dateTime.getMillis()), nanos);
|
|
|
}
|
|
|
|
|
|
private static DateTime parseDate(DateTime newDateTime, String dateString) {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
* Creates a Timestamp instance from the given string. String is in the format
|
|
|
* yyyy-MM-dd HH:mm:ss.SSSSSSZZ. If no timezone is given, UTC is assumed.
|
|
|
*/
|
|
|
public static Timestamp parseCloudTimestamp(String timestamp) {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
All so-far-agreed-to feedback has been addressed.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Changes Unknown when pulling 8e26935 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
@@ -252,12 +262,28 @@ public static QueryParameterValue time(String value) { |
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public long getTimestampValue() {
|
|
|
public Timestamp getTimestampValue() {
|
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I have pushed some doc improvements, PTAL
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Changes Unknown when pulling 3151e09 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@vkedia do you have any other concerns?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Changes Unknown when pulling 7a54804 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Changes Unknown when pulling 3151e09 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Coverage increased (+0.01%) to 80.903% when pulling 1535cc1 on garrettjonesgoogle:master into 5dae747 on GoogleCloudPlatform:master.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
suztomo
pushed a commit
to suztomo/google-cloud-java
that referenced
this pull request
Mar 11, 2026
suztomo
pushed a commit
to suztomo/google-cloud-java
that referenced
this pull request
Mar 23, 2026
suztomo
pushed a commit
to suztomo/google-cloud-java
that referenced
this pull request
Mar 23, 2026
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
|