describe
此命令返回表的描述.其语法如下:
hbase> describe 'table name'
以下是 \\ temp 表中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⇒ 'personaldata', 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 ⇒ 'professionaldata', DATA_BLOCK_ENCODING ⇒ 'NONE', BLOOMFILTER ⇒ 'ROW', REPLICATION_SCOPE ⇒ '0',VERSIONS ⇒ '1', COMPRESSION ⇒ 'NONE', MIN_VERSIONS ⇒ '0', TTL ⇒'FOREVER', KEEP_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
Alter是用于更改现有表的命令.使用此命令,可以更改列族的最大单元数,设置和删除表范围运算符,以及从表中删除列族.
更改最大单元数列族
下面给出了更改列族最大单元数的语法.
hbase> alter 't1', NAME ⇒ 'f1', VERSIONS ⇒ 5
在以下示例中,最大单元格数设置为5.
hbase(main):003:0> alter 'emp', NAME ⇒ 'personal data', VERSIONS ⇒ 5Updating 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)
在下面的示例中,我们将 \\ temp 表设为只读.
hbase(main):006:0> alter 'emp', READONLYUpdating 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+CELLrow1 column = personal:city, timestamp = 1418193767, value = hyderabadrow1 column = personal:name, timestamp = 1418193806767, value = rajurow1 column = professional:designation, timestamp = 1418193767, value = managerrow1 column = professional:salary, timestamp = 1418193806767, value = 500001 row(s) in 0.0160 seconds
现在让我们删除名为 professional的列族使用alter命令.
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 + CELLrow1 column = personal:city, timestamp = 14181936767, value = hyderabadrow1 column = personal:name, timestamp = 1418193806767, value = raju1 row(s) in 0.0830 seconds
使用Java API添加列族
您可以添加列族使用 HBAseAdmin 类的方法 addColumn()的表格.按照下面给出的步骤将列族添加到表中.
步骤1
实例化 HBaseAdmin 类.
//实例化配置对象配置conf = HBaseConfiguration.create(); //实例化HBaseAdmin类 HBaseAdmin admin = new HBaseAdmin(conf);
第2步
addColumn()方法需要表名和对象 HColumnDescriptor 类.因此,实例化 HColumnDescriptor 类. HColumnDescriptor 的构造函数又需要添加列族名称.这里我们将一个名为"contactDetails"的列族添加到现有的"employee"表中.
//实例化columnDescriptor对象 HColumnDescriptor columnDescriptor = new HColumnDescriptor("contactDetails");
步骤3
使用 addColumn 方法添加列族.将表名和 HColumnDescriptor 类对象作为参数传递给此方法.
// Adding column familyadmin.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的族
您可以使用 HBAseAdmin 类的方法 deleteColumn()从表中删除列族.按照下面给出的步骤将列族添加到表中.
Step1
实例化 HBaseAdmin 类.
// Instantiating configuration objectConfiguration conf = HBaseConfiguration.create();// Instantiating HBaseAdmin classHBaseAdmin admin = new HBaseAdmin(conf);
Step2
使用 deleteColumn()方法添加列族.将表名和列系列名称作为参数传递给此方法.
// Deleting column familyadmin.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