table.addFamily(new HColumnDescriptor("schema"));
table.addFamily(new HColumnDescriptor(Constants.SYS_COL_FAMILY));
hbaseAdmin.createTable(table);
}
} catch (IOException e) {
throw new DatasetIOException("Cannot open schema table", e);
}
Schema schema = getEmbeddedSchema(descriptor);
String entitySchemaString = schema.toString(true);
AvroEntitySchema entitySchema = new AvroEntitySchema(
schema, entitySchemaString, descriptor.getColumnMapping());
String tableName = getTableName(name);
String entityName = getEntityName(name);
schemaManager.refreshManagedSchemaCache(tableName, entityName);
schemaManager.createSchema(tableName, entityName, entitySchemaString,
"org.kitesdk.data.hbase.avro.AvroKeyEntitySchemaParser",
"org.kitesdk.data.hbase.avro.AvroKeySerDe",
"org.kitesdk.data.hbase.avro.AvroEntitySerDe");
try {
if (!hbaseAdmin.tableExists(tableName)) {
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(columnFamily(Constants.SYS_COL_FAMILY, descriptor));
desc.addFamily(columnFamily(Constants.OBSERVABLE_COL_FAMILY, descriptor));
for (String columnFamily : entitySchema.getColumnMappingDescriptor()
.getRequiredColumnFamilies()) {
desc.addFamily(columnFamily(columnFamily, descriptor));
}
hbaseAdmin.createTable(desc);
} else {
Set<String> familiesToAdd = entitySchema.getColumnMappingDescriptor()
.getRequiredColumnFamilies();
familiesToAdd.add(new String(Constants.SYS_COL_FAMILY));
familiesToAdd.add(new String(Constants.OBSERVABLE_COL_FAMILY));
HTableDescriptor desc = hbaseAdmin.getTableDescriptor(tableName
.getBytes());
for (HColumnDescriptor columnDesc : desc.getColumnFamilies()) {
String familyName = columnDesc.getNameAsString();
if (familiesToAdd.contains(familyName)) {
familiesToAdd.remove(familyName);
}
}
if (familiesToAdd.size() > 0) {
hbaseAdmin.disableTable(tableName);
try {
for (String family : familiesToAdd) {
hbaseAdmin.addColumn(tableName, columnFamily(family, descriptor));
}
} finally {
hbaseAdmin.enableTable(tableName);
}
}
}
} catch (IOException e) {
throw new DatasetIOException("Cannot prepare table: " + name, e);
}
return getDatasetDescriptor(schema, descriptor.getLocation());
}