kiji.createTable(desc);
final KijiTable table = kiji.openTable("dev");
try {
final EntityId eid = table.getEntityId("row");
final KijiTableWriter writer = table.getWriterFactory().openTableWriter();
try {
// Register writer schema TestRecord1, compatible with reader TestRecord2:
final GenericData.Record record1 = new GenericData.Record(INT_RECORD1);
record1.put("integer", 314);
writer.put(eid, "info", "user_id", record1);
// Register writer schema TestRecord2, is exactly reader TestRecord2:
final GenericData.Record record2 = new GenericData.Record(INT_TEXT_RECORD1);
record2.put("integer", 314);
record2.put("text", "text");
writer.put(eid, "info", "user_id", record2);
// Register writer schema TestRecord3, compatible with reader TestRecord2:
final GenericData.Record record3 = new GenericData.Record(INT_ANOTHER_TEXT_RECORD1);
record3.put("integer", 314);
record3.put("another_text", "text");
writer.put(eid, "info", "user_id", record3);
// Any primitive type is incompatible with reader schema TestRecord1:
try {
writer.put(eid, "info", "user_id", "1");
Assert.fail("Registering writer schema 'string' should fail.");
} catch (InvalidLayoutSchemaException ilse) {
LOG.info("Expected error: {}", ilse.toString());
Assert.assertTrue(
ilse.getMessage(),
ilse.getMessage().contains("In column: 'info:user_id'"));
Assert.assertTrue(
ilse.getMessage(),
ilse.getMessage().contains("is incompatible with writer schema"));
}
} finally {
writer.close();
}
} finally {
table.release();
}