HBase在createTable的时候遇到如下问题:
代码
public class HBaseClient {
public static void main(String[] args) throws Exception {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
String tableName = "test-hbase";
String columName = "info";
Admin admin = connection.getAdmin();
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
HColumnDescriptor columnDescriptor = new HColumnDescriptor(columName);
admin.addColumn(TableName.valueOf(tableName), columnDescriptor);
admin.createTable(tableDescriptor);
admin.close();
connection.close();
}
}
解决方案:
public class HBaseClient {
public static void main(String[] args) throws Exception {
Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
String tableName = "test-hbase";
String columName = "info";
Admin admin = connection.getAdmin();
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
HColumnDescriptor columnDescriptor = new HColumnDescriptor(columName);
tableDescriptor.addFamily(columnDescriptor);
admin.createTable(tableDescriptor);
admin.close();
connection.close();
}
}
Exception in thread "main" org.apache.hadoop.hbase.InvalidFamilyOperationException: org.apache.hadoop.hbase.InvalidFamilyOperationException: Column family 'info' in table 'test-hbase' already exists so cannot be added
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:106)
at org.apache.hadoop