Skip to content

Commit d91d52c

Browse files
committed
Added UUID sorting intergration test
1 parent 28e302c commit d91d52c

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

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

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
import tech.ydb.table.transaction.TxControl;
2525
import tech.ydb.table.values.DecimalType;
2626
import tech.ydb.table.values.DecimalValue;
27+
import tech.ydb.table.values.ListValue;
2728
import tech.ydb.table.values.NullType;
2829
import tech.ydb.table.values.NullValue;
2930
import tech.ydb.table.values.PrimitiveType;
3031
import tech.ydb.table.values.PrimitiveValue;
32+
import tech.ydb.table.values.StructValue;
3133
import tech.ydb.table.values.Type;
34+
import tech.ydb.table.values.Value;
3235
import tech.ydb.test.junit4.GrpcTransportRule;
3336

3437
/**
@@ -113,6 +116,89 @@ public void uuidReadTest() {
113116
Assert.assertEquals(0x6e73b41c4ede4d08L, v2.getUuidHigh());
114117
}
115118

119+
@Test
120+
public void uuidSortTest() {
121+
String[] sorted = new String[] {
122+
"00000000-0000-0000-0000-000000000001",
123+
"00000000-0000-0000-0000-000000000010",
124+
"00000000-0000-0000-0000-000000000100",
125+
"00000000-0000-0000-0000-000000001000",
126+
"00000000-0000-0000-0000-000000010000",
127+
"00000000-0000-0000-0000-000000100000",
128+
"00000000-0000-0000-0000-000001000000",
129+
"00000000-0000-0000-0000-000010000000",
130+
"00000000-0000-0000-0000-000100000000",
131+
"00000000-0000-0000-0000-001000000000",
132+
"00000000-0000-0000-0000-010000000000",
133+
"00000000-0000-0000-0000-100000000000",
134+
135+
"00000000-0000-0000-0001-000000000000",
136+
"00000000-0000-0000-0010-000000000000",
137+
"00000000-0000-0000-0100-000000000000",
138+
"00000000-0000-0000-1000-000000000000",
139+
140+
"00000000-0000-0100-0000-000000000000",
141+
"00000000-0000-1000-0000-000000000000",
142+
"00000000-0000-0001-0000-000000000000",
143+
"00000000-0000-0010-0000-000000000000",
144+
145+
"00000000-0100-0000-0000-000000000000",
146+
"00000000-1000-0000-0000-000000000000",
147+
"00000000-0001-0000-0000-000000000000",
148+
"00000000-0010-0000-0000-000000000000",
149+
150+
"01000000-0000-0000-0000-000000000000",
151+
"10000000-0000-0000-0000-000000000000",
152+
"00010000-0000-0000-0000-000000000000",
153+
"00100000-0000-0000-0000-000000000000",
154+
"00000100-0000-0000-0000-000000000000",
155+
"00001000-0000-0000-0000-000000000000",
156+
"00000001-0000-0000-0000-000000000000",
157+
"00000010-0000-0000-0000-000000000000",
158+
};
159+
160+
StructValue[] sv = new StructValue[sorted.length];
161+
for (int idx = 0; idx < sorted.length; idx++) {
162+
sv[idx] = StructValue.of("uuid", PrimitiveValue.newUuid(sorted[idx]));
163+
}
164+
ListValue list = ListValue.of(sv);
165+
166+
DataQueryResult result = CTX.supplyResult(s -> s.executeDataQuery(""
167+
+ "DECLARE $input AS List<Struct<uuid: UUID>>;"
168+
+ "SELECT uuid FROM AS_TABLE($input) ORDER BY uuid ASC;"
169+
+ "SELECT uuid FROM AS_TABLE($input) ORDER BY uuid DESC;",
170+
TxControl.snapshotRo(), Params.of("$input", list)
171+
)).join().getValue();
172+
173+
Assert.assertEquals(2, result.getResultSetCount());
174+
ResultSetReader rs1 = result.getResultSet(0);
175+
ResultSetReader rs2 = result.getResultSet(1);
176+
177+
Value<?> p1 = null;
178+
Value<?> p2 = null;
179+
for (int idx = 0; idx < sorted.length; idx++) {
180+
Assert.assertTrue(rs1.next());
181+
Assert.assertTrue(rs2.next());
182+
183+
Assert.assertEquals(UUID.fromString(sorted[idx]), rs1.getColumn(0).getUuid());
184+
Assert.assertEquals(UUID.fromString(sorted[sorted.length - 1 - idx]), rs2.getColumn(0).getUuid());
185+
186+
Value<?> v1 = rs1.getColumn(0).getValue();
187+
Value<?> v2 = rs2.getColumn(0).getValue();
188+
189+
if (idx != 0) {
190+
Assert.assertTrue("" + v1 + " > " + p1, v1.compareTo(p1) > 0);
191+
Assert.assertTrue("" + v2 + " < " + p2, v2.compareTo(p2) < 0);
192+
}
193+
194+
p1 = v1;
195+
p2 = v2;
196+
}
197+
198+
Assert.assertFalse(rs1.next());
199+
Assert.assertFalse(rs2.next());
200+
}
201+
116202
private void assertTimestamp(ValueReader vr, boolean optional, Instant expected) {
117203
Assert.assertNotNull(vr);
118204
if (optional) {

0 commit comments

Comments
 (0)