描述
该命令返回表的描述。其语法如下:
hbase> describe 'table name'
以下给出 emp 表上describe命令的输出。
hbase(main):006:0> describe 'emp'
DESCRIPTION
ENABLED
'emp', {NAME ⇒ 'READONLY', DATA_BLOCK_ENCODING ⇒ 'NONE', BLOOMFILTER
⇒ 'ROW', REPLICATION_SCOPE ⇒ '0', COMPRESSION ⇒ 'NONE', VERSIONS ⇒
'1', TTL true
⇒ 'FOREVER', MIN_VERSIONS ⇒ '0', KEEP_DELETED_CELLS ⇒ 'false',
BLOCKSIZE ⇒ '65536', IN_MEMORY ⇒ 'false', BLOCKCACHE ⇒ 'true'}, {NAME
⇒ 'personal
data', DATA_BLOCK_ENCODING ⇒ 'NONE', BLOOMFILTER ⇒ 'ROW',
REPLICATION_SCOPE ⇒ '0', VERSIONS ⇒ '5', COMPRESSION ⇒ 'NONE',
MIN_VERSIONS ⇒ '0', TTL
⇒ 'FOREVER', KEEP_DELETED_CELLS ⇒ 'false', BLOCKSIZE ⇒ '65536',
IN_MEMORY ⇒ 'false', BLOCKCACHE ⇒ 'true'}, {NAME ⇒ 'professional
data', DATA_BLO
CK_ENCODING ⇒ 'NONE', BLOOMFILTER ⇒ 'ROW', REPLICATION_SCOPE ⇒ '0',
VERSIONS ⇒ '1', COMPRESSION ⇒ 'NONE', MIN_VERSIONS ⇒ '0', TTL ⇒
'FOREVER', K
EEP_DELETED_CELLS ⇒ 'false', BLOCKSIZE ⇒ '65536', IN_MEMORY ⇒
'false', BLOCKCACHE ⇒ 'true'}, {NAME ⇒ 'table_att_unset',
DATA_BLOCK_ENCODING ⇒ 'NO
NE', BLOOMFILTER ⇒ 'ROW', REPLICATION_SCOPE ⇒ '0', COMPRESSION ⇒
'NONE', VERSIONS ⇒ '1', TTL ⇒ 'FOREVER', MIN_VERSIONS ⇒ '0',
KEEP_DELETED_CELLS
⇒ 'false', BLOCKSIZE ⇒ '6
改变
Alter是用于对现有表进行更改的命令。使用此命令,可以更改列族的最大单元格数,设置和删除表范围操作符,并从表中删除列族。
更改列系列的最大单元数
下面给出了更改列族最大单元数的语法。
hbase> alter 't1', NAME ⇒ 'f1', VERSIONS ⇒ 5
在以下示例中,单元格的最大数量设置为5。
hbase(main):003:0> alter 'emp', NAME ⇒ 'personal data', VERSIONS ⇒ 5
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.3050 seconds
表范围操作符
使用alter,您可以设置和删除表格作用域运算符,例如MAX_FILESIZE,READONLY,MEMSTORE_FLUSHSIZE,DEFERRED_LOG_FLUSH等。
设置为只读
下面给出的是使表只读的语法。
hbase>alter 't1', READONLY(option)
在下面的例子中,我们只使 emp 表成为只读。
hbase(main):006:0> alter 'emp', READONLY
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.2140 seconds
删除表范围操作符
我们也可以删除表范围操作符。下面给出的是从emp表中删除'MAX_FILESIZE'的语法。
hbase> alter 't1', METHOD ⇒ 'table_att_unset', NAME ⇒ 'MAX_FILESIZE'
删除一个列族
使用alter,你也可以删除一个列族。下面给出的是使用alter删除列族的语法。
hbase> alter ‘ table name ’, ‘delete’ ⇒ ‘ column family ’
下面给出的是从'emp'表中删除一个列族的例子。
假设HBase中有一个名为employee的表。它包含以下数据:
hbase(main):006:0> scan 'employee'
ROW COLUMN+CELL
row1 column = personal:city, timestamp = 1418193767, value = hyderabad
row1 column = personal:name, timestamp = 1418193806767, value = raju
row1 column = professional:designation, timestamp = 1418193767, value = manager
row1 column = professional:salary, timestamp = 1418193806767, value = 50000
1 row(s) in 0.0160 seconds
现在让我们使用alter命令删除名为 professional 的列族。
hbase(main):007:0> alter 'employee','delete'⇒'professional'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.2380 seconds
现在在更改后验证表格中的数据。因为我们已经删除了它,所以观察列专家'专业'不再。
hbase(main):003:0> scan 'employee'
ROW COLUMN + CELL
row1 column = personal:city, timestamp = 14181936767, value = hyderabad
row1 column = personal:name, timestamp = 1418193806767, value = raju
1 row(s) in 0.0830 seconds
使用Java API添加列族
您可以使用该方法的列族添加到表 addColumn() 的 HBAseAdmin 类。按照下面给出的步骤将一个列族添加到表中。
步骤1
实例化 HBaseAdmin 类。
// Instantiating configuration object
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
第2步
所述 addColumn() 方法需要一个表名和的目的 HColumnDescriptor 类。因此实例化
HColumnDescriptor 类。 HColumnDescriptor
的构造函数反过来需要添加一个列名。在这里我们添加一个名为“contactDetails”的列族到现有的“员工”表中。
// Instantiating columnDescriptor object
HColumnDescriptor columnDescriptor = new
HColumnDescriptor("contactDetails");
第3步
使用 addColumn 方法添加列族。将表名和 HColumnDescriptor 类对象作为参数传递给此方法。
// Adding column family
admin.addColumn("employee", new HColumnDescriptor("columnDescriptor"));
下面给出了将列族添加到现有表的完整程序。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class AddColoumn{
public static void main(String args[]) throws MasterNotRunningException, IOException{
// Instantiating configuration class.
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class.
HBaseAdmin admin = new HBaseAdmin(conf);
// Instantiating columnDescriptor class
HColumnDescriptor columnDescriptor = new HColumnDescriptor("contactDetails");
// Adding column family
admin.addColumn("employee", columnDescriptor);
System.out.println("coloumn added");
}
}
编译并执行上述程序,如下所示。
$javac AddColumn.java
$java AddColumn
仅当您将类路径设置为“ .bashrc ”时 ,上述编译才有效。如果你还没有,请按照以下步骤编译你的.java文件。
//if "/home/home/hadoop/hbase " is your Hbase home folder then.
$javac -cp /home/hadoop/hbase/lib/*: Demo.java
如果一切顺利,它将产生以下输出:
column added
使用Java API删除列族
您可以使用该方法从表中删除列族 deleteColumn() 的 HBAseAdmin 类。按照下面给出的步骤将一个列族添加到表中。
步骤1
实例化 HBaseAdmin 类。
// Instantiating configuration object
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
第2步
使用 deleteColumn() 方法添加列族。将表名和列名称作为参数传递给此方法。
// Deleting column family
admin.deleteColumn("employee", "contactDetails");
下面给出了从现有表中删除列族的完整程序。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class DeleteColoumn{
public static void main(String args[]) throws MasterNotRunningException, IOException{
// Instantiating configuration class.
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class.
HBaseAdmin admin = new HBaseAdmin(conf);
// Deleting a column family
admin.deleteColumn("employee","contactDetails");
System.out.println("coloumn deleted");
}
}
编译并执行上述程序,如下所示。
$javac DeleteColumn.java
$java DeleteColumn
以下应该是输出:
column deleted