Skip to content

Commit c50dde5

Browse files
committed
Added tests for Timestamp
1 parent 7087c18 commit c50dde5

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

table/src/test/java/tech/ydb/table/integration/ValuesReadTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.table.integration;
22

3+
import java.time.Instant;
34
import java.util.UUID;
45

56
import org.junit.Assert;
@@ -101,4 +102,41 @@ public void uuidReadTest() {
101102
Assert.assertEquals(0x9cfbb7462d9e498bL, v2.getUuidLow());
102103
Assert.assertEquals(0x6e73b41c4ede4d08L, v2.getUuidHigh());
103104
}
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+
}
104142
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package tech.ydb.table.types;
2+
3+
import java.time.Instant;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
import tech.ydb.proto.ValueProtos.Value;
9+
import tech.ydb.table.values.PrimitiveValue;
10+
11+
/**
12+
*
13+
* @author Aleksandr Gorshenin
14+
*/
15+
public class PrimitiveTypeTest {
16+
17+
@Test
18+
public void timestampTest() {
19+
PrimitiveValue min = PrimitiveValue.newTimestamp(Instant.EPOCH);
20+
Value minValue = min.toPb();
21+
22+
Assert.assertEquals(0, minValue.getUint32Value());
23+
Assert.assertEquals(0, minValue.getUint64Value());
24+
Assert.assertEquals(0, minValue.getInt32Value());
25+
Assert.assertEquals(0, minValue.getInt64Value());
26+
Assert.assertEquals(0, minValue.getLow128());
27+
Assert.assertEquals(0, minValue.getHigh128());
28+
29+
PrimitiveValue max = PrimitiveValue.newTimestamp(Instant.parse("2105-12-31T23:59:59.999999Z"));
30+
Value maxValue = max.toPb();
31+
32+
Assert.assertEquals(0, maxValue.getUint32Value());
33+
Assert.assertEquals(4291747199999999l, maxValue.getUint64Value());
34+
Assert.assertEquals(0, maxValue.getInt32Value());
35+
Assert.assertEquals(0, maxValue.getInt64Value());
36+
Assert.assertEquals(0, maxValue.getLow128());
37+
Assert.assertEquals(0, maxValue.getHigh128());
38+
}
39+
}

0 commit comments

Comments
 (0)