|
24 | 24 | import tech.ydb.table.transaction.TxControl; |
25 | 25 | import tech.ydb.table.values.DecimalType; |
26 | 26 | import tech.ydb.table.values.DecimalValue; |
| 27 | +import tech.ydb.table.values.ListValue; |
27 | 28 | import tech.ydb.table.values.NullType; |
28 | 29 | import tech.ydb.table.values.NullValue; |
29 | 30 | import tech.ydb.table.values.PrimitiveType; |
30 | 31 | import tech.ydb.table.values.PrimitiveValue; |
| 32 | +import tech.ydb.table.values.StructValue; |
31 | 33 | import tech.ydb.table.values.Type; |
| 34 | +import tech.ydb.table.values.Value; |
32 | 35 | import tech.ydb.test.junit4.GrpcTransportRule; |
33 | 36 |
|
34 | 37 | /** |
@@ -113,6 +116,89 @@ public void uuidReadTest() { |
113 | 116 | Assert.assertEquals(0x6e73b41c4ede4d08L, v2.getUuidHigh()); |
114 | 117 | } |
115 | 118 |
|
| 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 | + |
116 | 202 | private void assertTimestamp(ValueReader vr, boolean optional, Instant expected) { |
117 | 203 | Assert.assertNotNull(vr); |
118 | 204 | if (optional) { |
|
0 commit comments