-
Notifications
You must be signed in to change notification settings - Fork 0
DDL
Zhamri Che Ani edited this page Nov 7, 2023
·
4 revisions
create - Creates a table.
list - Lists all the tables in HBase.
disable - Disables a table.
is_disabled - Verifies whether a table is disabled.
enable - Enables a table.
is_enabled - Verifies whether a table is enabled.
describe - Provides the description of a table.
alter - Alters a table.
exists - Verifies whether a table exists.
drop - Drops a table from HBase.
drop_all - Drops the tables matching the ‘regex’ given in the command.
Java Admin API - Prior to all the above commands, Java provides an Admin API to achieve DDL functionalities through programming. Under org.apache.hadoop.hbase.client package, HBaseAdmin and HTableDescriptor are the two important classes in this package that provide DDL functionalities.
hbase> list
hbase> disable 'Car'
hbase> enable 'Car'
hbase> is_disabled 'Car'
hbase> is_enabled 'Car'
hbase> exists 'Car'
//You can't drop a table that is enabled, you typically need to disable it first:
hbase> disable 'Car'
hbase> drop 'Car'
// drop_all 'regex'
hbase> drop_all 'Test.*'
// create 'table_name', 'column_family'
// create 'table_name', 'column_family1', 'column_family2', ...
// create 'table_name', {NAME => 'column_family', VERSIONS => 5, COMPRESSION => 'GZ', ...}
create 'Car', 'details', 'info'
create 'Car', {NAME => 'details', VERSIONS => 3}, {NAME => 'info'}
To display the schema
// describe 'table_name'
hbase> describe 'Car'
To add a new column family:
// alter 'table_name', NAME => 'new_column_family'
alter 'Car', NAME => 'zhamri'
To delete a column family:
// alter 'table_name', 'delete' => 'column_family_to_delete'
alter 'Car', 'delete' => 'zhamri'
To rename the column_family
// Step 1: Add the new column family 'zhamri'
disable 'Car'
alter 'Car', NAME => 'zhamri'
enable 'Car'
// Step 2: You would use a custom script to copy data from 'details' to 'zhamri'. This step requires a custom script.
// Step 3: Delete the old column family 'details'
disable 'Car'
alter 'Car', 'delete' => 'details'
enable 'Car'