Skip to content

Commit e207a24

Browse files
committed
add tests for incorrect timestamp rounding
1 parent 2b942da commit e207a24

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/FieldValueTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public void testTimestamp() {
9595
long received = fieldValue.getTimestampValue();
9696
long expected = -19954383398377106L;
9797
assertEquals(expected, received);
98+
99+
fieldValue = FieldValue.of(FieldValue.Attribute.PRIMITIVE, "1643068465.0955739");
100+
received = fieldValue.getTimestampValue();
101+
expected = 1643068465095574L;
102+
assertEquals(expected, received);
98103
}
99104

100105
@Test

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
import java.nio.ByteBuffer;
128128
import java.nio.charset.StandardCharsets;
129129
import java.nio.file.FileSystems;
130+
import java.time.Instant;
131+
import java.time.temporal.ChronoUnit;
130132
import java.util.ArrayList;
131133
import java.util.Collection;
132134
import java.util.Collections;
@@ -448,6 +450,29 @@ public class ITBigQueryTest {
448450

449451
@Rule public Timeout globalTimeout = Timeout.seconds(300);
450452

453+
@Test
454+
public void tmpTest() throws InterruptedException {
455+
Instant instant = Instant.parse("2022-01-24T23:54:25.095574Z");
456+
System.out.println("timestamp to write : " + instant);
457+
458+
String query = "SELECT TIMESTAMP '" + instant + "'";
459+
System.out.println("query : " + query);
460+
461+
TableResult tableResult = bigquery.query(
462+
QueryJobConfiguration
463+
.newBuilder(query)
464+
.setPriority(QueryJobConfiguration.Priority.INTERACTIVE)
465+
.build()
466+
);
467+
468+
FieldValue fieldValue = tableResult.iterateAll().iterator().next().get(0);
469+
System.out.println("fieldValue : " + fieldValue);
470+
471+
long microSecondsSinceEpoch = fieldValue.getTimestampValue();
472+
Instant instantReadBack = Instant.EPOCH.plus(microSecondsSinceEpoch, ChronoUnit.MICROS);
473+
System.out.println("timestamp read back : " + instantReadBack);
474+
}
475+
451476
@BeforeClass
452477
public static void beforeClass() throws InterruptedException, IOException {
453478
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();

0 commit comments

Comments
 (0)