Hbase Create Table With Multiple Column Families and Splits

Subsequently successful installation of HBase on top of Hadoop, we get an interactive trounce to execute various commands and perform several operations. Using these commands, we tin can perform multiple operations on data-tables that can give better data storage efficiencies and flexible interaction by the client.

We can interact with HBase in two means,

  • HBase interactive shell mode and
  • Through Coffee API

In HBase, interactive vanquish mode is used to collaborate with HBase for table operations, tabular array management, and data modeling. By using Java API model, we tin perform all type of table and data operations in HBase. We tin collaborate with HBase using this both methods.

The only difference betwixt these 2 is Java API utilize java code to connect with HBase and shell fashion use shell commands to connect with HBase.

Quick overcap of HBase before nosotros proceed-

  • HBase uses Hadoop files every bit storage organization to store the large amounts of information. Hbase consists of Master Servers and Regions Servers
  • The data that is going to shop in HBase will exist in the class of regions. Further, these regions volition be split up and stored in multiple region servers
  • This beat out commands allows the programmer to ascertain table schemas and data operations using complete beat mode interaction
  • Whichever command we apply, it's going to reflect in HBase data model
  • Nosotros employ HBase crush commands in operating organization script interpreters like Bash shell
  • Bash shell is the default control interpreters for most of Linux and Unix operating distributions
  • HBase avant-garde versions provides shell commands jruby-style object oriented references for tables
  • Table reference variables tin can be used to perform information operations in HBase shell mode

For examples,

  • In this tutorial, we accept created a table in which 'education' represents table name and corresponds to column proper name "guru99".
  • In some commands "guru99," itself represents a tabular array name.

In this tutorial- you will larn,

  • Full general commands
  • Tables Managements commands
  • Data manipulation commands
  • Cluster Replication Commands

General commands

In Hbase, general commands are categorized into following commands

  • Condition
  • Version
  • Table_help ( scan, driblet, get, put, disable, etc.)
  • Whoami

To get enter into HBase beat command, offset of all, we accept to execute the code as mentioned below

HBase Shell and General Commands

hbase Shell

Once we get to enter into HBase shell, we can execute all vanquish commands mentioned below. With the help of these commands, we can perform all blazon of tabular array operations in the HBase shell fashion.

Let usa look into all of these commands and their usage 1 by one with an example.

Condition

Syntax:status

This command will give details nearly the system status like a number of servers present in the cluster, active server count, and average load value. You lot tin can as well laissez passer whatever particular parameters depending on how detailed condition you want to know about the system. The parameters tin can be 'summary', 'elementary', or 'detailed', the default parameter provided is "summary".

Below we have shown how y'all tin can pass dissimilar parameters to the condition control.

If we find the below screen shot, we volition get a meliorate idea.

HBase Shell and General Commands

hbase(main):001:0>status hbase(primary):002:0>status 'simple' hbase(main):003:0>condition 'summary' hbase(main):004:0> status 'detailed'

When we execute this control status, information technology will requite information about number of server's present, dead servers and average load of server, hither in screenshot it shows the information like- ane alive server, 1 dead servers, and vii.0000 average load.

Version

Syntax: version

HBase Shell and General Commands

  • This command will display the currently used HBase version in command fashion
  • If you run version command, it will give output as shown to a higher place

Table aid

Syntax:table_help

HBase Shell and General Commands

This command guides

  • What and how to use tabular array-referenced commands
  • It will provide unlike HBase shell control usages and its syntaxes
  • Here in the screen shot in a higher place, its shows the syntax to "create" and "get_table" command with its usage. We tin can manipulate the table via these commands one time the table gets created in HBase.
  • Information technology volition give table manipulations commands like put, get and all other commands data.

whoami

Syntax:

Syntax: Whoami

HBase Shell and General Commands

This command "whoami" is used to return the electric current HBase user information from the HBase cluster.

It will provide information like

  • Groups present in HBase
  • The user information, for example in this example "hduser" represent the user proper noun as shown in screen shot

TTL(Time To Alive) – Aspect

In HBase, Column families can be set to fourth dimension values in seconds using TTL. HBase will automatically delete rows once the expiration fourth dimension is reached. This attribute applies to all versions of a row – fifty-fifty the current version too.

The TTL time encoded in the HBase for the row is specified in UTC. This attribute used with tabular array direction commands.

Important differences between TTL handling and Cavalcade family TTLs are beneath

  • Cell TTLs are expressed in units of milliseconds instead of seconds.
  • A cell TTLs cannot extend the effective lifetime of a cell across a Column Family level TTL setting.

Tables Managements commands

These commands will allow programmers to create tables and table schemas with rows and cavalcade families.

The following are Table Direction commands

  • Create
  • List
  • Describe
  • Disable
  • Disable_all
  • Enable
  • Enable_all
  • Drop
  • Drop_all
  • Show_filters
  • Alter
  • Alter_status

Permit us await into various command usage in HBase with an example.

Create

Syntax: create <tablename>, <columnfamilyname>

HBase Shell and General Commands

Instance:-

hbase(main):001:0> create 'didactics' ,'guru99' 0 rows(southward) in 0.312 seconds =>Hbase::Table – education

The above example explains how to create a tabular array in HBase with the specified name given according to the lexicon or specifications as per column family. In addition to this nosotros can as well pass some table-scope attributes too into information technology.

In social club to check whether the table 'education' is created or not, we have to use the "list" command equally mentioned below.

List

Syntax:listing

HBase Shell and General Commands

  • "List" command will display all the tables that are nowadays or created in HBase
  • The output showing in above screen shot is currently showing the existing tables in HBase
  • Here in this screenshot, it shows that there are total 8 tables present inside HBase
  • We can filter output values from tables past passing optional regular expression parameters

Describe

Syntax:describe <table name>

HBase Shell and General Commands

hbase(main):010:0>depict 'education'

This control describes the named table.

  • It volition give more than data about column families present in the mentioned table
  • In our example, it gives the description about table "education."
  • It will give data about table name with cavalcade families, associated filters, versions and some more than details.

disable

Syntax: disable <tablename>

HBase Shell and General Commands

hbase(main):011:0>disable 'education'
  • This command will offset disabling the named table
  • If table needs to be deleted or dropped, it has to disable first

Here, in the higher up screenshot nosotros are disabling table pedagogy

disable_all

            Syntax: disable_all<"matching regex"
  • This command will disable all the tables matching the given regex.
  • The implementation is same as delete command (Except adding regex for matching)
  • Once the tabular array gets disable the user tin can able to delete the tabular array from HBase
  • Before delete or dropping table, information technology should be disabled kickoff

Enable

Syntax: enable <tablename>

HBase Shell and General Commands

hbase(chief):012:0>enable 'education'
  • This command volition commencement enabling the named table
  • Whichever table is disabled, to retrieve back to its previous state we apply this command
  • If a table is disabled in the outset example and non deleted or dropped, and if we want to re-use the disabled table then we have to enable information technology by using this command.
  • Here in the above screenshot we are enabling the table "education."

show_filters

Syntax: show_filters

HBase Shell and General Commands

This command displays all the filters present in HBase similar ColumnPrefix Filter, TimestampsFilter, PageFilter, FamilyFilter, etc.

drop

Syntax:driblet <table proper noun>

HBase Shell and General Commands

hbase(main):017:0>drop 'didactics'

We have to discover below points for drop command

  • To delete the tabular array present in HBase, first we take to disable it
  • To drib the table present in HBase, showtime we have to disable it
  • And so either table to drop or delete showtime the table should exist disable using disable command
  • Here in above screenshot nosotros are dropping tabular array "education."
  • Before execution of this control, it is necessary that y'all disable table "education."

drop_all

Syntax: drop_all<"regex">
  • This command will drop all the tables matching the given regex
  • Tables have to disable get-go before executing this command using disable_all
  • Tables with regex matching expressions are going to drop from HBase

is_enabled

Syntax: is_enabled 'instruction'

This control will verify whether the named table is enabled or not. Usually, there is a little confusion between "enable" and "is_enabled" command action, which we clear here

  • Suppose a table is disabled, to use that table nosotros accept to enable it by using enable command
  • is_enabled command will check either the table is enabled or not

alter

Syntax: alter <tablename>, Proper noun=><cavalcade familyname>, VERSIONS=>5

This command alters the cavalcade family unit schema. To understand what exactly it does, nosotros take explained it hither with an example.

Examples:

In these examples, we are going to perform alter control operations on tables and on its columns. Nosotros will perform operations like

  • Altering unmarried, multiple column family unit names
  • Deleting column family names from tabular array
  • Several other operations using telescopic attributes with table
  1. To change or add together the 'guru99_1' column family in table 'teaching' from current value to go on a maximum of v cell VERSIONS,
  • "educational activity" is table proper noun created with column name "guru99" previously
  • Hither with the aid of an alter command nosotros are trying to change the column family schema to guru99_1 from guru99

HBase Shell and General Commands

hbase> modify 'education', Proper noun='guru99_1', VERSIONS=>5
  1. You can also operate the modify control on several column families besides. For instance, nosotros will ascertain 2 new column to our existing table "didactics".
            hbase> alter 'edu', 'guru99_1', {Name => 'guru99_2', IN_MEMORY => truthful}, {Proper noun => 'guru99_3', VERSIONS => v}

HBase Shell and General Commands

  • We can change more than i column schemas at a fourth dimension using this command
  • guru99_2 and guru99_3 as shown in in a higher place screenshot are the two new column names that we have defined for the tabular array didactics
  • We can run into the way of using this command in the previous screen shot
  1. In this stride, we will encounter how to delete column family from the table. To delete the 'f1' column family in table 'teaching'.

Utilize 1 ofthese commands below,

hbase> alter 'pedagogy', Name => 'f1', METHOD => 'delete'
hbase> alter 'education', 'delete' =>' guru99_1'          
  • In this command, we are trying to delete the column infinite proper name guru99_1 that we previously created in the first footstep

HBase Shell and General Commands

  1. As shown in the below screen shots, it shows two steps – how to change table scope attribute and how to remove the table telescopic attribute.
Syntax: alter <'tablename'>, MAX_FILESIZE=>'132545224'

HBase Shell and General Commands

Step i) You can change table-scope attributes like MAX_FILESIZE, READONLY, MEMSTORE_FLUSHSIZE, DEFERRED_LOG_FLUSH, etc. These tin be put at the end;for instance, to change the max size of a region to 128MB or any other memory value we apply this command.

Usage:

  • Nosotros can apply MAX_FILESIZE with the table as telescopic attribute equally above
  • The number represent in MAX_FILESIZE is in term of retentivity in bytes

NOTE: MAX_FILESIZE Attribute Tabular array scope will be determined by some attributes present in the HBase. MAX_FILESIZE also come up nether tabular array scope attributes.

Step 2) You lot tin can likewise remove a table-telescopic attribute using table_att_unset method. If you run into the control

alter 'didactics', METHOD => 'table_att_unset', NAME => 'MAX_FILESIZE'
  • The to a higher place screen shot shows altered tabular array proper noun with telescopic attributes
  • Method table_att_unset is used to unset attributes present in the table
  • The second instance we are unsetting attribute MAX_FILESIZE
  • After execution of the command, it will simply unset MAX_FILESIZE aspect from"pedagogy" tabular array.

alter_status

            Syntax: alter_status 'instruction'

HBase Shell and General Commands

  • Through this control, you can get the status of the alter command
  • Which indicates the number of regions of the table that take received the updated schema pass table name
  • Here in above screen shot it shows 1/one regions updated. It means that it has updated i region. Later that if it successful it will brandish annotate done.

Data manipulation commands

These commands will work on the table related to data manipulations such as putting data into a table, retrieving data from a tabular array and deleting schema, etc.

The commands come under these are

  • Count
  • Put
  • Get
  • Delete
  • Delete all
  • Truncate
  • Scan

Let expect into these commands usage with an example.

Count

Syntax: count <'tablename'>, CACHE =>1000
  • The control will call back the count of a number of rows in a table. The value returned by this one is the number of rows.
  • Current count is shown per every 1000 rows by default.
  • Count interval may be optionally specified.
  • Default cache size is x rows.
  • Count command will piece of work fast when it is configured with right Cache.

Example:

HBase Shell and General Commands

hbase> count 'guru99', CACHE=>k

This instance count fetches 1000 rows at a fourth dimension from "Guru99" tabular array.

Nosotros tin make enshroud to some lower value if the table consists of more rows.

But by default information technology will fetch one row at a time.

hbase>count 'guru99', INTERVAL => 100000 hbase> count 'guru99', INTERVAL =>10, CACHE=> 1000

If suppose if the table "Guru99" having some table reference like say g.

We tin can run the count command on table reference also like below

hbase>chiliad.count INTERVAL=>100000 hbase>one thousand.count INTERVAL=>10, Cache=>1000

Put

Syntax:  put <'tablename'>,<'rowname'>,<'columnvalue'>,<'value'>

This command is used for following things

  • Information technology volition put a prison cell 'value' at defined or specified table or row or column.
  • It will optionally coordinate time postage stamp.

Example:

  • Hither we are placing values into table "guru99" under row r1 and column c1
    hbase> put 'guru99', 'r1', 'c1', 'value', 10
  • We have placed three values, 10,xv and thirty in table "guru99" as shown in screenshot below

HBase Shell and General Commands

  • Suppose if the tabular array "Guru99" having some table reference like say yard. We can also run the control on table reference also similar

    hbase> g.put 'guru99', 'r1', 'c1', 'value', 10
  • The output volition be as shown in the above screen shot later placing values into "guru99".

To cheque whether the input value is correctly inserted into the table, we use "scan" command. In the below screen shot, we can see the values are inserted correctly

HBase Shell and General Commands

Code Snippet: For Practise

create 'guru99', {NAME=>'Edu', VERSIONS=>213423443} put 'guru99', 'r1', 'Edu:c1', 'value', 10 put 'guru99', 'r1', 'Edu:c1', 'value', 15 put 'guru99', 'r1', 'Edu:c1', 'value', 30

From the code snippet, nosotros are doing these things

  • Here we are creating a table named 'guru99' with the column name as "Edu."
  • By using "put" command, nosotros are placing values into row proper noun r1 in column "Edu" into table "guru99."

Get

Syntax: get <'tablename'>, <'rowname'>, {< Additional parameters>}

Hither <Additional Parameters> include TIMERANGE, TIMESTAMP, VERSIONS and FILTERS.

Past using this control, y'all will get a row or cell contents nowadays in the table. In addition to that you tin also add additional parameters to it like TIMESTAMP, TIMERANGE,VERSIONS, FILTERS, etc. to become a particular row or prison cell content.

HBase Shell and General Commands

Examples:-

hbase> go 'guru99', 'r1', {Cavalcade => 'c1'}

For table "guru99′ row r1 and column c1 values volition brandish using this command equally shown in the above screen shot

hbase> get 'guru99', 'r1'

For tabular array "guru99″row r1 values will be displayed using this command

hbase> get 'guru99', 'r1', {TIMERANGE => [ts1, ts2]}

For tabular array "guru99″row one values in the fourth dimension range ts1 and ts2 will be displayed using this control

hbase> go 'guru99', 'r1', {COLUMN => ['c1', 'c2', 'c3']}

For table "guru99" row r1 and column families' c1, c2, c3 values volition be displayed using this command

Delete

Syntax:delete <'tablename'>,<'row name'>,<'column name'>
  • This command will delete prison cell value at defined table of row or column.
  • Delete must and should friction match the deleted cells coordinates exactly.
  • When scanning, delete cell suppresses older versions of values.

HBase Shell and General Commands

Instance:

hbase(main):)020:0> delete 'guru99', 'r1', 'c1''.          
  • The above execution will delete row r1 from column family c1 in table "guru99."
  • Suppose if the table "guru99" having some table reference like say k.
  • We can run the control on table reference also like hbase> chiliad.delete 'guru99', 'r1', 'c1′".

deleteall

Syntax: deleteall <'tablename'>, <'rowname'>

HBase Shell and General Commands

  • This Command will delete all cells in a given row.
  • Nosotros can define optionally column names and time stamp to the syntax.

Instance:-

hbase>deleteall 'guru99', 'r1', 'c1'

This volition delete all the rows and columns present in the tabular array. Optionally nosotros tin mention cavalcade names in that.

Truncate

Syntax:  truncate <tablename>

HBase Shell and General Commands

After truncate of an hbase table, the schema will present but non the records. This command performs 3 functions; those are listed beneath

  • Disables table if it already presents
  • Drops table if it already presents
  • Recreates the mentioned table

Scan

Syntax: scan <'tablename'>, {Optional parameters}

This control scans entire tabular array and displays the tabular array contents.

  • We can laissez passer several optional specifications to this browse command to get more data about the tables present in the organisation.
  • Scanner specifications may include one or more of the following attributes.
  • These are TIMERANGE, FILTER, TIMESTAMP, LIMIT, MAXLENGTH, COLUMNS, Enshroud, STARTROW and STOPROW.
browse 'guru99'          

The output equally beneath shown in screen shot

HBase Shell and General Commands

In the above screen shot

  • It shows "guru99" tabular array with column name and values
  • It consists of iii row values r1, r2, r3 for unmarried column value c1
  • It displays the values associated with rows

Examples:-

The unlike usages of scan command

Command Usage

scan '.META.', {COLUMNS => 'info:regioninfo'}

Information technology display all the meta information data related to columns that are present in the tables in HBase

scan 'guru99', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}

Information technology display contents of tabular array guru99 with their column families c1 and c2 limiting the values to 10

scan 'guru99', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}

It display contents of guru99 with its column name c1 with the values present in between the mentioned time range attribute value

scan 'guru99', {RAW => truthful, VERSIONS =>10}

In this control RAW=> true provides advanced feature like to display all the cell values present in the tabular array guru99

Code Case:

Get-go create tabular array and place values into table

create 'guru99', {Proper name=>'due east', VERSIONS=>2147483647} put 'guru99', 'r1', 'e:c1', 'value', x put 'guru99', 'r1', 'e:c1', 'value', 12 put 'guru99', 'r1', 'e:c1', 'value', 14 delete 'guru99', 'r1', 'e:c1', 11

Input Screenshot:

HBase Shell and General Commands

If we run scan control

Query: browse 'guru99', {RAW=>true, VERSIONS=>grand}

Information technology will display output shown in below.

Output screen shot:

HBase Shell and General Commands

The output shown in in a higher place screen shot gives the following information

  • Scanning guru99 tabular array with attributes RAW=>true, VERSIONS=>chiliad
  • Displaying rows with column families and values
  • In the tertiary row, the values displayed shows deleted value present in the column
  • The output displayed past information technology is random; it cannot be same order every bit the values that we inserted in the table

Cluster Replication Commands

  • These commands piece of work on cluster set mode of HBase.
  • For calculation and removing peers to cluster and to start and stop replication these commands are used in general.
Control Functionality

add_peer

Add peers to cluster to replicate

hbase> add_peer 'iii', zk1,zk2,zk3:2182:/hbase-prod

remove_peer

Stops the defined replication stream.

Deletes all the metadata information well-nigh the peer

hbase> remove_peer '1'

start_replication

Restarts all the replication features

hbase> start_replication

stop_replication

Stops all the replication features

hbase>stop_replication

Summary

HBase beat out and general commands give consummate data about dissimilar type of data manipulation, tabular array direction, and cluster replication commands. We can perform various functions using these commands on tables present in HBase.

lindtthemply.blogspot.com

Source: https://www.guru99.com/hbase-shell-general-commands.html

0 Response to "Hbase Create Table With Multiple Column Families and Splits"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel