Skip to content

Commit

Permalink
add tests for incorrect timestamp rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-du committed Oct 8, 2021
1 parent 2b942da commit e207a24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public void testTimestamp() {
long received = fieldValue.getTimestampValue();
long expected = -19954383398377106L;
assertEquals(expected, received);

fieldValue = FieldValue.of(FieldValue.Attribute.PRIMITIVE, "1643068465.0955739");
received = fieldValue.getTimestampValue();
expected = 1643068465095574L;
assertEquals(expected, received);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystems;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -448,6 +450,29 @@ public class ITBigQueryTest {

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

@Test
public void tmpTest() throws InterruptedException {
Instant instant = Instant.parse("2022-01-24T23:54:25.095574Z");
System.out.println("timestamp to write : " + instant);

String query = "SELECT TIMESTAMP '" + instant + "'";
System.out.println("query : " + query);

TableResult tableResult = bigquery.query(
QueryJobConfiguration
.newBuilder(query)
.setPriority(QueryJobConfiguration.Priority.INTERACTIVE)
.build()
);

FieldValue fieldValue = tableResult.iterateAll().iterator().next().get(0);
System.out.println("fieldValue : " + fieldValue);

long microSecondsSinceEpoch = fieldValue.getTimestampValue();
Instant instantReadBack = Instant.EPOCH.plus(microSecondsSinceEpoch, ChronoUnit.MICROS);
System.out.println("timestamp read back : " + instantReadBack);
}

@BeforeClass
public static void beforeClass() throws InterruptedException, IOException {
RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create();
Expand Down

0 comments on commit e207a24

Please sign in to comment.