Skip to content

Full support for DATE, TIME, and DATETIME in BigQuery#1819

Closed
garrettjonesgoogle wants to merge 1 commit intogoogleapis:masterfrom
garrettjonesgoogle:master
Closed

Full support for DATE, TIME, and DATETIME in BigQuery#1819
garrettjonesgoogle wants to merge 1 commit intogoogleapis:masterfrom
garrettjonesgoogle:master

Conversation

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor

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

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 28, 2017
@garrettjonesgoogle
Copy link
Copy Markdown
Contributor Author

Note I have fixed the codacy errors - I'll push them with other PR updates.


/**
* 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.

This comment was marked as spam.

* 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.

This comment was marked as spam.

This comment was marked as spam.

* 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.

This comment was marked as spam.

} 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.

This comment was marked as spam.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor Author

@shinfan PTAL

@shinfan
Copy link
Copy Markdown
Contributor

shinfan commented Mar 29, 2017

LGTM

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling fee2415 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.

Copy link
Copy Markdown

@vkedia vkedia left a 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

* @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.

This comment was marked as spam.

}

/**
* @param dateTime Date plus time: (yyyy-MM-dd HH:mm:ss.SSSSSSSSS) or

This comment was marked as spam.

This comment was marked as spam.

}

/**
* Constructs a new CivilDate instance.

This comment was marked as spam.

This comment was marked as spam.

nanos = (int) TimeUnit.MILLISECONDS.toNanos(fractionalNumber);
} else if (fractional.length() == 6) {
nanos = (int) TimeUnit.MICROSECONDS.toNanos(fractionalNumber);
} else {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return time;
}

/** Formats the date and time in the format yyyy-MM-dd HH:mm:ss.SSSSSSSSS */

This comment was marked as spam.

This comment was marked as spam.

}

/** Formats the date and time in the format yyyy-MM-dd HH:mm:ss.SSSSSSSSS */
public String formatMicroCloudTime() {

This comment was marked as spam.

This comment was marked as spam.

this.nanos = nanos;
}

public static Timestamp ofTimeMicroseconds(long microseconds) {

This comment was marked as spam.

This comment was marked as spam.

*/
public static CivilDateTime parseDateTime(String dateTime) {
String splitToken = " ";
if (dateTime.contains("T")) {

This comment was marked as spam.

This comment was marked as spam.

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.

/** 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.

This comment was marked as spam.

This comment was marked as spam.

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.

This comment was marked as spam.


/**
* 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.

This comment was marked as spam.


DateTime dateTime = new DateTime();
dateTime = parseTz(dateTime, tz);
dateTime = parseDate(dateTime, Preconditions.checkNotNull(date));

This comment was marked as spam.

This comment was marked as spam.

return ofTimeSecondsAndNanos(TimeUnit.MILLISECONDS.toSeconds(dateTime.getMillis()), nanos);
}

private static DateTime parseDate(DateTime newDateTime, String dateString) {

This comment was marked as spam.

This comment was marked as spam.

* 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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor Author

All so-far-agreed-to feedback has been addressed.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 8e26935 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.

@@ -252,12 +262,28 @@ public static QueryParameterValue time(String value) {

This comment was marked as spam.

This comment was marked as spam.

*/
@SuppressWarnings("unchecked")
public long getTimestampValue() {
public Timestamp getTimestampValue() {

This comment was marked as spam.

This comment was marked as spam.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor Author

I have pushed some doc improvements, PTAL

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 3151e09 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.

@garrettjonesgoogle
Copy link
Copy Markdown
Contributor Author

@vkedia do you have any other concerns?

@vkedia
Copy link
Copy Markdown

vkedia commented Mar 31, 2017

Looks good to me.

@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 7a54804 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.

@garrettjonesgoogle garrettjonesgoogle force-pushed the master branch 2 times, most recently from b35947a to 3151e09 Compare March 31, 2017 23:34
@coveralls
Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 3151e09 on garrettjonesgoogle:master into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 80.903% when pulling 1535cc1 on garrettjonesgoogle:master into 5dae747 on GoogleCloudPlatform:master.

meltsufin pushed a commit that referenced this pull request Dec 22, 2025
This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: https://github.com/googleapis/synthtool/commit/ef9fe2ef6d92c7ff967d9d4f704035b3f5c9051d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9
chingor13 pushed a commit that referenced this pull request Jan 6, 2026
* ci: javadoc job (JDK 17) in ci.yaml (#1819)

This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: googleapis/synthtool@ef9fe2e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9

* fix javadoc

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Tomo Suzuki <suztomo@google.com>
chingor13 pushed a commit that referenced this pull request Jan 22, 2026
This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: googleapis/synthtool@ef9fe2e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
suztomo pushed a commit that referenced this pull request Mar 9, 2026
* ci: javadoc job (JDK 17) in ci.yaml (#1819)

This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: googleapis/synthtool@ef9fe2e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9

* fix errors

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* fix error

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Neenu1995 <neenushaji@google.com>
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 11, 2026
This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: https://github.com/googleapis/synthtool/commit/ef9fe2ef6d92c7ff967d9d4f704035b3f5c9051d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9
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>
suztomo pushed a commit that referenced this pull request Mar 30, 2026
* ci: javadoc job (JDK 17) in ci.yaml (#1819)

This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: googleapis/synthtool@ef9fe2e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9

* docs: fix java 17 doclint errors

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
lqiu96 pushed a commit that referenced this pull request Apr 1, 2026
* ci: javadoc job (JDK 17) in ci.yaml (#1819)

This also changes the JDK distribution from zulu to temurin
https://github.com/actions/setup-java#eclipse-temurin
Source-Link: googleapis/synthtool@ef9fe2e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:31c8276a1bfb43766597d32645721c029cb94571f1b8d996cb2c290744fe52f9

* docs: fix java 17 doclint errors

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants