|
127 | 127 | import java.nio.ByteBuffer; |
128 | 128 | import java.nio.charset.StandardCharsets; |
129 | 129 | import java.nio.file.FileSystems; |
| 130 | +import java.time.Instant; |
| 131 | +import java.time.temporal.ChronoUnit; |
130 | 132 | import java.util.ArrayList; |
131 | 133 | import java.util.Collection; |
132 | 134 | import java.util.Collections; |
@@ -448,6 +450,29 @@ public class ITBigQueryTest { |
448 | 450 |
|
449 | 451 | @Rule public Timeout globalTimeout = Timeout.seconds(300); |
450 | 452 |
|
| 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 | + |
451 | 476 | @BeforeClass |
452 | 477 | public static void beforeClass() throws InterruptedException, IOException { |
453 | 478 | RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); |
|
0 commit comments