.setSchemaFormat(SchemaFormat.UID));
// Fetch all the layout history:
final List<KijiTableLayout> layouts =
getTableLayoutVersions(tableName, HConstants.ALL_VERSIONS);
final KijiTableLayout currentLayout = layouts.isEmpty() ? null : layouts.get(0);
final KijiTableLayout tableLayout = KijiTableLayout.createUpdatedLayout(update, currentLayout);
Preconditions.checkArgument(tableName.equals(tableLayout.getName()));
// Set of all the former layout IDs:
final Set<String> layoutIDs = Sets.newHashSet();
for (KijiTableLayout layout : layouts) {
layoutIDs.add(layout.getDesc().getLayoutId());
}
final String refLayoutIdStr = update.getReferenceLayout();
final boolean hasCurrentLayout = (null != currentLayout);
final boolean hasRefLayoutId = (null != refLayoutIdStr);
if (hasCurrentLayout && !hasRefLayoutId) {
throw new IOException(String.format(
"Layout for table '%s' does not specify reference layout ID.", tableName));
}
if (!hasCurrentLayout && hasRefLayoutId) {
throw new IOException(String.format(
"Initial layout for table '%s' must not specify reference layout ID.", tableName));
}
final String layoutId = tableLayout.getDesc().getLayoutId();
if (layoutIDs.contains(layoutId)) {
throw new InvalidLayoutException(tableLayout,
String.format("Layout ID '%s' already exists", layoutId));
}
//String metaTableName = mMetaTableName;
Preconditions.checkNotNull(mUpdateTableLayoutStatement);
// TODO: This should do a "check-and-put" to match the HBase implementation.
mAdmin.execute(
mUpdateTableLayoutStatement.bind(
tableName,
new Date(),
layoutId,
ByteBuffer.wrap(mCellEncoder.encode(tableLayout.getDesc())),
ByteBuffer.wrap(mCellEncoder.encode(update)))
);
// Flush the writer schema for the Avro table layout first so other readers can see it.
mSchemaTable.flush();