|
1 | 1 | package tech.ydb.table.integration; |
2 | 2 |
|
| 3 | +import java.time.Instant; |
3 | 4 | import java.util.UUID; |
4 | 5 |
|
5 | 6 | import org.junit.Assert; |
@@ -101,4 +102,41 @@ public void uuidReadTest() { |
101 | 102 | Assert.assertEquals(0x9cfbb7462d9e498bL, v2.getUuidLow()); |
102 | 103 | Assert.assertEquals(0x6e73b41c4ede4d08L, v2.getUuidHigh()); |
103 | 104 | } |
| 105 | + |
| 106 | + private void assertTimestamp(ValueReader vr, boolean optional, Instant expected) { |
| 107 | + Assert.assertNotNull(vr); |
| 108 | + if (optional) { |
| 109 | + Assert.assertSame(Type.Kind.OPTIONAL, vr.getType().getKind()); |
| 110 | + Assert.assertSame(PrimitiveType.Timestamp, vr.getType().unwrapOptional()); |
| 111 | + } else { |
| 112 | + Assert.assertSame(PrimitiveType.Timestamp, vr.getType()); |
| 113 | + } |
| 114 | + |
| 115 | + Assert.assertEquals(expected, vr.getTimestamp()); |
| 116 | + } |
| 117 | + |
| 118 | + @Test |
| 119 | + public void timestampReadTest() { |
| 120 | + DataQueryResult result = CTX.supplyResult( |
| 121 | + s -> s.executeDataQuery("SELECT " |
| 122 | + + "DateTime::MakeTimestamp(DateTime::FromMilliseconds(0ul)) as t1," |
| 123 | + + "DateTime::MakeTimestamp(DateTime::FromMicroseconds(1000ul)) as t2," |
| 124 | + + "DateTime::MakeTimestamp(DateTime::FromMicroseconds(4291747199999999ul)) as t3," |
| 125 | + + "Timestamp('1970-01-01T00:00:00.000000Z') as t4," |
| 126 | + + "Timestamp('2105-12-31T23:59:59.999999Z') as t5;", |
| 127 | + TxControl.serializableRw() |
| 128 | + ) |
| 129 | + ).join().getValue(); |
| 130 | + |
| 131 | + Assert.assertEquals(1, result.getResultSetCount()); |
| 132 | + |
| 133 | + ResultSetReader rs = result.getResultSet(0); |
| 134 | + Assert.assertTrue(rs.next()); |
| 135 | + |
| 136 | + assertTimestamp(rs.getColumn("t1"), true, Instant.EPOCH); |
| 137 | + assertTimestamp(rs.getColumn("t2"), true, Instant.EPOCH.plusMillis(1)); |
| 138 | + assertTimestamp(rs.getColumn("t3"), true, Instant.parse("2105-12-31T23:59:59.999999Z")); |
| 139 | + assertTimestamp(rs.getColumn("t4"), false, Instant.ofEpochSecond(0, 0)); |
| 140 | + assertTimestamp(rs.getColumn("t5"), false, Instant.ofEpochSecond(4291747199l, 999999000l)); |
| 141 | + } |
104 | 142 | } |
0 commit comments