/** Tests for column removal. */
@Test
public void testDeleteColumn() throws Exception {
RowKeyFormat2 format = makeHashPrefixedRowKeyFormat();
// Reference layout with a single column : "family_name:column_name"
final TableLayoutDesc refDesc = TableLayoutDesc.newBuilder()
.setName("table_name")
.setKeysFormat(format)
.setVersion(TABLE_LAYOUT_VERSION)
.setLocalityGroups(Lists.newArrayList(
makeMinimalLocalityGroup()))
.build();
final KijiTableLayout refLayout = KijiTableLayout.newLayout(refDesc);
{
// Target layout deleting the column
final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
.setName("table_name")
.setKeysFormat(format)
.setVersion(TABLE_LAYOUT_VERSION)
.setLocalityGroups(Lists.newArrayList(
LocalityGroupDesc.newBuilder()
.setName("locality_group_name")
.setInMemory(false)
.setTtlSeconds(84600)
.setMaxVersions(1)
.setCompressionType(CompressionType.GZ)
.setFamilies(Lists.newArrayList(
FamilyDesc.newBuilder()
.setName("family_name")
.setColumns(Lists.newArrayList(
ColumnDesc.newBuilder()
.setName("column_name")
.setColumnSchema(CellSchema.newBuilder()
.setStorage(SchemaStorage.UID)
.setType(SchemaType.INLINE)
.setValue("\"string\"")
.build())
.setDelete(true)
.build()))
.build()))
.build()))
.build();
final KijiTableLayout layout = KijiTableLayout.createUpdatedLayout(desc, refLayout);
final KijiTableLayout.LocalityGroupLayout.FamilyLayout fLayout =
layout.getFamilyMap().get("family_name");
assertNotNull(fLayout);
assertTrue(fLayout.getColumns().isEmpty());
assertTrue(fLayout.getColumnMap().isEmpty());
}
{
// Target layout with an invalid column deletion
final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
.setName("table_name")
.setKeysFormat(format)
.setVersion(TABLE_LAYOUT_VERSION)
.setLocalityGroups(Lists.newArrayList(
LocalityGroupDesc.newBuilder()
.setName("locality_group_name")
.setInMemory(false)
.setTtlSeconds(84600)
.setMaxVersions(1)
.setCompressionType(CompressionType.GZ)
.setFamilies(Lists.newArrayList(
FamilyDesc.newBuilder()
.setName("family_name")
.build()))
.build()))
.build();
try {
KijiTableLayout.createUpdatedLayout(desc, refLayout);
Assert.fail("Layout update with missing column did not fail.");
} catch (InvalidLayoutException ile) {
// Exception is expected!
}
}
{
// Target layout with an invalid column rename
final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
.setName("table_name")
.setKeysFormat(format)
.setVersion(TABLE_LAYOUT_VERSION)
.setLocalityGroups(Lists.newArrayList(
LocalityGroupDesc.newBuilder()