How to Create a Column family in a Selected Cluste

2019-08-27 05:16发布

问题:

In cassandra hector API allow to create table on a selected cluster as follows. I want to do the same thing using HBase, can someone please help me out?

This is how it can done using Cassandra :

public void createColumnFamily(Cluster cluster, String tableName,
                                   String columnFamilyName,
                                   StreamDefinition streamDefinition) {
    }

回答1:

There is no such concept of cluster namespace in HBase. You can simple create a table in HBase using methods of HBaseAdmin class.

HBaseConfiguration conf = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);// maps to keyspace name of cassandra.
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(columnFamilyName);// maps to column family name of cassandra.
tableDescriptor.addFamily(hColumnDescriptor);

admin.createTable(hTableDescriptor);