Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type HTable(config,tablename) is deprecated. What use instead?

What can I use instead of HTable(config,tablename)?

This method is deprecated. In every example I could find they use this or another Constuctor, which is also deprecated.

like image 703
dino Avatar asked Oct 25 '15 16:10

dino


2 Answers

Constructing HTable objects manually has been deprecated. Please use Connection to instantiate a Table instead.

From a Connection, Table implementations are retrieved with Connection.getTable(TableName)

Example:

Connection connection = ConnectionFactory.createConnection(config);

Table table = connection.getTable(TableName.valueOf("table1"));

try 
{
   // Use the table as needed, for a single operation and a single thread
} 
finally
{
   table.close();
   connection.close();
}
like image 63
Vinkal Avatar answered Nov 11 '22 02:11

Vinkal


Connection.getTable(TableName) is used only for retrieving Table.

If you need to create a table instead, use TableDescriptorBuilder and Admin.createTable(TableDescriptor).

For instance:

val tableDescriptor: TableDescriptor = TableDescriptorBuilder
                          .newBuilder(TableName.valueOf("mytable"))
                          .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder("myId".getBytes).build())
                          .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder("data".getBytes).build())
                          .build()

admin.createTable(tableDescriptor)
like image 2
Johnny Willer Avatar answered Nov 11 '22 02:11

Johnny Willer