|
27 | 27 | import com.apple.foundationdb.record.TestRecords3Proto; |
28 | 28 | import com.apple.foundationdb.record.TestRecords4Proto; |
29 | 29 | import com.apple.foundationdb.record.TestRecords4WrapperProto; |
| 30 | +import com.apple.foundationdb.record.TestRecordsUuidProto; |
| 31 | +import com.apple.foundationdb.record.TupleFieldsProto; |
30 | 32 | import com.apple.foundationdb.record.query.plan.cascades.typing.Type; |
31 | 33 | import com.apple.foundationdb.record.query.plan.cascades.typing.TypeRepository; |
32 | 34 | import com.apple.foundationdb.record.query.plan.cascades.values.LiteralValue; |
@@ -306,4 +308,28 @@ void testAnyRecordSerialization() { |
306 | 308 | Type.AnyRecord r1 = new Type.AnyRecord(false); |
307 | 309 | Assertions.assertEquals(r1, Type.AnyRecord.fromProto(serializationContext, r1.toProto(serializationContext))); |
308 | 310 | } |
| 311 | + |
| 312 | + @Test |
| 313 | + void testUUIDInterpretedAsRecordType() { |
| 314 | + final TestRecordsUuidProto.UuidRecord uuidRecord = TestRecordsUuidProto.UuidRecord.newBuilder() |
| 315 | + .setName("testUuidRecord") |
| 316 | + .setPkey(TupleFieldsProto.UUID.newBuilder() |
| 317 | + .setMostSignificantBits(1) |
| 318 | + .setLeastSignificantBits(2)) |
| 319 | + .build(); |
| 320 | + final Type.Record recordType = Type.Record.fromDescriptor(uuidRecord.getDescriptorForType()); |
| 321 | + final Map<String, Type.Record.Field> fieldsMaps = recordType.getFieldNameFieldMap(); |
| 322 | + checkIsUuidRecordType(fieldsMaps, "pkey"); |
| 323 | + checkIsUuidRecordType(fieldsMaps, "secondary"); |
| 324 | + checkIsUuidRecordType(fieldsMaps, "unique"); |
| 325 | + } |
| 326 | + |
| 327 | + private static void checkIsUuidRecordType(@Nonnull Map<String, Type.Record.Field> fieldsMap, @Nonnull String fieldName) { |
| 328 | + Assertions.assertTrue(fieldsMap.containsKey(fieldName)); |
| 329 | + Assertions.assertInstanceOf(Type.Record.class, fieldsMap.get(fieldName).getFieldType()); |
| 330 | + final Type.Record uuidRecord = (Type.Record) fieldsMap.get(fieldName).getFieldType(); |
| 331 | + Assertions.assertEquals(2, uuidRecord.getFields().size()); |
| 332 | + Assertions.assertEquals(Type.TypeCode.LONG, uuidRecord.getFields().get(0).getFieldType().getTypeCode()); |
| 333 | + Assertions.assertEquals(Type.TypeCode.LONG, uuidRecord.getFields().get(1).getFieldType().getTypeCode()); |
| 334 | + } |
309 | 335 | } |
0 commit comments