|
5 | 5 | import java.time.LocalDate; |
6 | 6 | import java.time.LocalDateTime; |
7 | 7 |
|
| 8 | +import java.time.chrono.IsoChronology; |
8 | 9 | import java.time.temporal.ChronoUnit; |
9 | 10 |
|
10 | 11 | import org.junit.Assert; |
11 | 12 | import org.junit.ClassRule; |
12 | 13 | import org.junit.Test; |
13 | 14 |
|
14 | 15 | import tech.ydb.common.transaction.TxMode; |
| 16 | +import tech.ydb.core.Issue; |
| 17 | +import tech.ydb.core.Status; |
| 18 | +import tech.ydb.core.StatusCode; |
15 | 19 | import tech.ydb.query.tools.QueryReader; |
16 | 20 | import tech.ydb.query.tools.SessionRetryContext; |
17 | 21 | import tech.ydb.table.query.Params; |
18 | 22 | import tech.ydb.table.result.ResultSetReader; |
| 23 | +import tech.ydb.table.result.ValueReader; |
| 24 | +import tech.ydb.table.values.PrimitiveType; |
19 | 25 | import tech.ydb.table.values.PrimitiveValue; |
| 26 | +import tech.ydb.table.values.Type; |
20 | 27 | import tech.ydb.test.junit4.GrpcTransportRule; |
21 | 28 |
|
22 | 29 | /** |
@@ -68,6 +75,40 @@ public void date32datetime64timestamp64interval64() { |
68 | 75 | Assert.assertEquals(Duration.parse("-PT2S"), resultSetReader.getColumn(3).getInterval64()); |
69 | 76 | } |
70 | 77 |
|
| 78 | + @Test |
| 79 | + public void timestamp64ReadTest() { |
| 80 | + System.out.println(Instant.ofEpochSecond(-4611669897600L)); |
| 81 | + QueryReader result = CTX.supplyResult( |
| 82 | + s -> QueryReader.readFrom(s.createQuery("SELECT " |
| 83 | + + "Timestamp64('-144169-01-01T00:00:00Z') as t1," |
| 84 | + + "Timestamp64('148107-12-31T23:59:59.999999Z') as t2;", |
| 85 | + TxMode.NONE |
| 86 | + )) |
| 87 | + ).join().getValue(); |
| 88 | + |
| 89 | + Assert.assertEquals(1, result.getResultSetCount()); |
| 90 | + |
| 91 | + ResultSetReader rs = result.getResultSet(0); |
| 92 | + Assert.assertTrue(rs.next()); |
| 93 | + |
| 94 | + assertTimestamp64(rs.getColumn("t1"), false, Instant.ofEpochSecond(-4611669897600L)); |
| 95 | + assertTimestamp64(rs.getColumn("t2"), false, Instant.ofEpochSecond(4611669811199L, 999999000)); |
| 96 | + |
| 97 | + Status invalid = CTX.supplyResult( |
| 98 | + s -> s.createQuery("SELECT " |
| 99 | + + "Timestamp64('-144170-01-01T00:00:00Z') as t1," |
| 100 | + + "Timestamp64('148108-01-01T00:00:00.000000Z') as t2;", |
| 101 | + TxMode.NONE |
| 102 | + ).execute() |
| 103 | + ).join().getStatus(); |
| 104 | + |
| 105 | + Assert.assertEquals(StatusCode.GENERIC_ERROR, invalid.getCode()); |
| 106 | + Issue[] issues = invalid.getIssues(); |
| 107 | + Assert.assertEquals(2, issues.length); |
| 108 | + Assert.assertEquals("Invalid value \"-144170-01-01T00:00:00Z\" for type Timestamp64", issues[0].getMessage()); |
| 109 | + Assert.assertEquals("Invalid value \"148108-01-01T00:00:00.000000Z\" for type Timestamp64", issues[1].getMessage()); |
| 110 | + } |
| 111 | + |
71 | 112 | private void date32datetime64timestamp64interval64Assert(LocalDate date32, LocalDateTime datetime64, |
72 | 113 | Instant timestamp64, Duration interval64) { |
73 | 114 | QueryReader reader = CTX.supplyResult( |
@@ -95,4 +136,16 @@ private void date32datetime64timestamp64interval64Assert(LocalDate date32, Local |
95 | 136 | Assert.assertEquals(timestamp64, resultSetReader.getColumn(2).getTimestamp64()); |
96 | 137 | Assert.assertEquals(interval64, resultSetReader.getColumn(3).getInterval64()); |
97 | 138 | } |
| 139 | + |
| 140 | + private void assertTimestamp64(ValueReader vr, boolean optional, Instant expected) { |
| 141 | + Assert.assertNotNull(vr); |
| 142 | + if (optional) { |
| 143 | + Assert.assertSame(Type.Kind.OPTIONAL, vr.getType().getKind()); |
| 144 | + Assert.assertSame(PrimitiveType.Timestamp64, vr.getType().unwrapOptional()); |
| 145 | + } else { |
| 146 | + Assert.assertSame(PrimitiveType.Timestamp64, vr.getType()); |
| 147 | + } |
| 148 | + |
| 149 | + Assert.assertEquals(expected, vr.getTimestamp64()); |
| 150 | + } |
98 | 151 | } |
0 commit comments