|
20 | 20 |
|
21 | 21 | import java.nio.ByteBuffer; |
22 | 22 | import java.util.HashMap; |
| 23 | +import java.util.List; |
23 | 24 | import java.util.Map; |
24 | 25 | import java.util.function.Supplier; |
25 | 26 |
|
|
40 | 41 | import org.apache.cassandra.db.lifecycle.LifecycleTransaction; |
41 | 42 | import org.apache.cassandra.db.marshal.ByteType; |
42 | 43 | import org.apache.cassandra.db.marshal.BytesType; |
| 44 | +import org.apache.cassandra.db.marshal.Int32Type; |
43 | 45 | import org.apache.cassandra.db.marshal.UTF8Type; |
| 46 | +import org.apache.cassandra.db.marshal.UserType; |
44 | 47 | import org.apache.cassandra.exceptions.ConfigurationException; |
45 | 48 | import org.apache.cassandra.io.sstable.Component; |
46 | 49 | import org.apache.cassandra.io.sstable.Descriptor; |
|
51 | 54 | import static org.apache.cassandra.Util.throwAssert; |
52 | 55 | import static org.apache.cassandra.cql3.CQLTester.assertRows; |
53 | 56 | import static org.apache.cassandra.cql3.CQLTester.row; |
| 57 | +import static org.apache.cassandra.cql3.FieldIdentifier.forUnquoted; |
54 | 58 | import static org.apache.cassandra.db.ColumnFamilyStore.FlushReason.UNIT_TESTS; |
| 59 | +import static org.apache.cassandra.utils.ByteBufferUtil.bytes; |
55 | 60 | import static org.junit.Assert.assertEquals; |
56 | 61 | import static org.junit.Assert.assertFalse; |
57 | 62 | import static org.junit.Assert.assertNotNull; |
@@ -617,6 +622,32 @@ public void testEvolveSystemKeyspaceChanged() |
617 | 622 | assertEquals(keyspace1, diff.altered.get(0).after); |
618 | 623 | } |
619 | 624 |
|
| 625 | + @Test |
| 626 | + public void testInheritTypesFromPreviousKeyspace() |
| 627 | + { |
| 628 | + // given |
| 629 | + TableMetadata table0 = addTestTable("ks2", "t", ""); |
| 630 | + UserType udt = new UserType("ks2", |
| 631 | + bytes("PreviousType"), |
| 632 | + List.of(forUnquoted("a"), forUnquoted("b")), |
| 633 | + List.of(Int32Type.instance, Int32Type.instance), |
| 634 | + true); |
| 635 | + KeyspaceMetadata previousKeyspace = KeyspaceMetadata.create("ks2", KeyspaceParams.simple(1), Tables.of(table0), Views.none(), Types.of(udt), UserFunctions.none()); |
| 636 | + KeyspaceMetadata currentKeyspace = KeyspaceMetadata.create("ks2", KeyspaceParams.simple(1), Tables.of(table0)); |
| 637 | + |
| 638 | + // when |
| 639 | + SchemaTransformation transformation = SchemaTransformations.updateSystemKeyspace(currentKeyspace, 1); |
| 640 | + Keyspaces after = transformation.apply(Keyspaces.of(previousKeyspace)); |
| 641 | + |
| 642 | + // then |
| 643 | + KeyspaceMetadata keyspaceAfterTransformation = after.getNullable("ks2"); |
| 644 | + assertNotNull(keyspaceAfterTransformation); |
| 645 | + assertEquals(currentKeyspace.types.stream().count() + 1, keyspaceAfterTransformation.types.stream().count()); |
| 646 | + UserType inheritedUdt = keyspaceAfterTransformation.types.getNullable(udt.name); |
| 647 | + assertNotNull(inheritedUdt); |
| 648 | + assertEquals(udt, inheritedUdt); |
| 649 | + } |
| 650 | + |
620 | 651 | private TableMetadata addTestTable(String ks, String cf, String comment) |
621 | 652 | { |
622 | 653 | return |
|
0 commit comments