Skip to content
Merged
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 @@ -151,6 +151,18 @@ public void testInt64Timestamp() {
assertEquals(expected, received);
}

@Test
public void testLosslessMaxTimestamp() {
// Test the lossless behavior (useInt64Timestamps = true)
// The backend returns a 64-bit integer string for microseconds when this option is enabled
String losslessTimestampString = "253402300799999999";
FieldValue losslessValue =
FieldValue.of(FieldValue.Attribute.PRIMITIVE, losslessTimestampString, true);

// Exactly matches the microsecond equivalent of 9999-12-31 23:59:59.999999
assertEquals(253402300799999999L, losslessValue.getTimestampValue());
}

@Test
public void testEquals() {
FieldValue booleanValue = FieldValue.of(FieldValue.Attribute.PRIMITIVE, "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,56 @@ static GoogleCredentials loadCredentials(String credentialFile) {
}
}

@Test
void testLosslessMaxTimestampIntegration() throws InterruptedException {
Comment thread
jinseopkim0 marked this conversation as resolved.
String query = "SELECT TIMESTAMP '9999-12-31 23:59:59.999999 UTC' as max_ts";
QueryJobConfiguration config = QueryJobConfiguration.newBuilder(query).build();

// 1. Test lossless 64-bit integer parsing (useInt64Timestamps = true)
DataFormatOptions losslessOptions =
DataFormatOptions.newBuilder().useInt64Timestamp(true).build();
Comment thread
lqiu96 marked this conversation as resolved.
BigQuery losslessBigQuery =
bigquery.getOptions().toBuilder()
.setDataFormatOptions(losslessOptions)
.build()
.getService();

TableResult losslessResult = losslessBigQuery.query(config);
assertEquals(1L, losslessResult.getTotalRows());
for (FieldValueList row : losslessResult.iterateAll()) {
long exactMicros = row.get("max_ts").getTimestampValue();
assertEquals(253402300799999999L, exactMicros);
}

// 2. Test lossy FLOAT64 rounding behavior (useInt64Timestamps = false)
DataFormatOptions floatOptions =
DataFormatOptions.newBuilder().useInt64Timestamp(false).build();
BigQuery floatBigQuery =
bigquery.getOptions().toBuilder().setDataFormatOptions(floatOptions).build().getService();

TableResult floatResult = floatBigQuery.query(config);
assertEquals(1L, floatResult.getTotalRows());
for (FieldValueList row : floatResult.iterateAll()) {
long roundedMicros = row.get("max_ts").getTimestampValue();
assertEquals(253402300800000000L, roundedMicros);
}

// 3. Test ISO8601 timestamp formatting
DataFormatOptions isoOptions =
DataFormatOptions.newBuilder()
.timestampFormatOptions(DataFormatOptions.TimestampFormatOptions.ISO8601_STRING)
.build();
BigQuery isoBigQuery =
bigquery.getOptions().toBuilder().setDataFormatOptions(isoOptions).build().getService();

TableResult isoResult = isoBigQuery.query(config);
assertEquals(1L, isoResult.getTotalRows());
for (FieldValueList row : isoResult.iterateAll()) {
String isoValue = row.get("max_ts").getStringValue();
assertEquals("9999-12-31T23:59:59.999999Z", isoValue);
}
}

@Test
void testListDatasets() {
Page<Dataset> datasets = bigquery.listDatasets("bigquery-public-data");
Expand Down
Loading