Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.common.io.BaseEncoding;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.Instant;
Expand Down Expand Up @@ -224,7 +223,8 @@ public boolean getBooleanValue() {
@SuppressWarnings("unchecked")
public long getTimestampValue() {
if (useInt64Timestamps) {
return new BigInteger(getStringValue()).longValue();
// INT64 timestamps are signed 64-bit microseconds since epoch; parse without BigInteger.
return Long.parseLong(getStringValue());
}
// timestamps are encoded in the format 1408452095.22 where the integer part is seconds since
// epoch (e.g. 1408452095.22 == 2014-08-19 07:41:35.220 -05:00)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,8 @@ public GetQueryResultsResponse getQueryResults(
public GetQueryResultsResponse getQueryResultsSkipExceptionTranslation(
String projectId, String jobId, String location, Map<Option, ?> options) throws IOException {
validateRPC();
DataFormatOptions formatOptions = this.options.getDataFormatOptions();
TimestampFormatOptions timestampFormat = formatOptions.timestampFormatOptions();
Bigquery.Jobs.GetQueryResults queryRequest =
bigquery
.jobs()
Expand All @@ -1843,7 +1845,12 @@ public GetQueryResultsResponse getQueryResultsSkipExceptionTranslation(
Option.START_INDEX.getLong(options) != null
? BigInteger.valueOf(Option.START_INDEX.getLong(options))
: null)
.setTimeoutMs(Option.TIMEOUT.getLong(options));
.setTimeoutMs(Option.TIMEOUT.getLong(options))
.setFormatOptionsUseInt64Timestamp(formatOptions.useInt64Timestamp() ? true : null)
.setFormatOptionsTimestampOutputFormat(
timestampFormat != TimestampFormatOptions.TIMESTAMP_OUTPUT_FORMAT_UNSPECIFIED
? timestampFormat.toString()
: null);

queryRequest
.getRequestHeaders()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,9 +1713,37 @@ public void testGetQueryResultsNoTelemetry() throws Exception {
rpc.getQueryResultsSkipExceptionTranslation(PROJECT_ID, JOB_ID, LOCATION, new HashMap<>());

verifyRequest("GET", "/projects/" + PROJECT_ID + "/queries/" + JOB_ID);
assertThat(lastRequestUrl).doesNotContain("formatOptions");
verifyNoSpans();
}

@Test
public void testGetQueryResultsWithDataFormatOptions() throws Exception {
setMockResponse("{\"kind\":\"bigquery#getQueryResultsResponse\"}");

BigQueryOptions customOptions =
BigQueryOptions.newBuilder()
.setProjectId(PROJECT_ID)
.setCredentials(NoCredentials.getInstance())
.setTransportOptions(
BigQueryOptions.getDefaultHttpTransportOptions().toBuilder()
.setHttpTransportFactory(() -> mockTransport)
.build())
.setDataFormatOptions(
DataFormatOptions.newBuilder()
.useInt64Timestamp(true)
.timestampFormatOptions(TimestampFormatOptions.ISO8601_STRING)
.build())
.build();
HttpBigQueryRpc customRpc = new HttpBigQueryRpc(customOptions);

customRpc.getQueryResultsSkipExceptionTranslation(
PROJECT_ID, JOB_ID, LOCATION, new HashMap<>());

assertThat(lastRequestUrl).contains("formatOptions.useInt64Timestamp=true");
assertThat(lastRequestUrl).contains("formatOptions.timestampOutputFormat=ISO8601_STRING");
}

@Test
public void testGetQueryResultsWithRowLimitNoTelemetry() throws Exception {
setMockResponse("{\"kind\":\"bigquery#getQueryResultsResponse\"}");
Expand Down