Sie sind auf Seite 1von 3

#Check HBase on portal:

http://localhost:60010

# Login to HBase Shell


hbase shell

# Show version of Hbase

version

#Lists all the tables in HBase.


list

# Create table in HBase


create 'Student', {NAME => 'CF1'}
create 'Student1', {NAME => 'CF1'}, {NAME => 'CF2'}, {NAME => 'CF3'}

create 'Student2', {NAME => 'CF1', VERSIONS => 5}

create 'Student3', 'CF1', 'CF2', 'CF3'

# describe
describe 'Student'

# disable
disable 'Student'

# is_disabled
is_disabled 'Student'

# disable_all
disable_all 'S.*'

# enable
enable 'Student'

# is_enabled
is_enabled 'Student'

# enable_all
enable_all 'S.*'

#Alter table
alter 'Student', NAME => 'CF1', VERSIONS => 5
alter 'Student1', 'delete' => 'CF3'

#exists
exists 'Student'
#drop
disable 'Student'
drop 'Student'

#drop_all
disable_all 'S.*'
drop_all 's.*'

# Insert rows into table in HBase


put 'Student', '1', 'CF1:StName', 'John'
put 'Student', '1', 'CF1:StYear', '2001'
put 'Student', '1', 'CF1:StScore', '95'
put 'Student', '1', 'CF1:StRegion', 'East'

# Show table content in HBase


scan 'Student'

# Show table content in HBase


scan 'Student', {COLUMNS => ['CF1:StName', 'CF1:StRegion']}

scan 'Student', {COLUMNS => ['CF1:StName', 'CF1:StRegion']}, {VERSIONS => 2}

# Show table content with versions


put 'Student', '1', 'CF1:StScore', '95'
scan 'Student', {VERSIONS => 2}

# Reading table data by Row_Key


get 'Student', '1'

# Auto delete data after TTL (Time to Live), Block Size, Compression
create 'Student1', {NAME => 'CF1', TTL => '18000', BLOCKSIZE => '65536',COMPRESSION
=> 'SNAPPY'}

# Truncate table
truncate 'Student'
- Disabling table...
- Dropping table...
- Creating table...

# Count number of rows

count 'Student'

# HBase integrartion with Hive


Drop table Stemp;
Drop table StudentHive;

# HBase Commands through Shell Script


#!/bin/sh
echo "create " | hbase shell
echo "drop_all .* " | hbase shell

# In hive
CREATE EXTERNAL TABLE StudentHive (StID String, StName String, StYear int, StScore
int, StRegion String) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ('hbase.columns.mapping' =
':key,CF1:StName,CF1:StYear,CF1:StScore,CF1:StRegion') TBLPROPERTIES
('hbase.table.name' = 'StudentHBase');

CREATE TABLE Stemp (StID String, StName String, StYear int, StScore int, StRegion
String) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
Load Data Local inpath '/home/training/Desktop/Student' into table Stemp;

ADD JAR /home/training/hive/lib/hive-hbase-handler-0.10.0.jar;


ADD JAR /home/training/hive/lib/zookeeper-3.4.3.jar;
ADD JAR /home/training/hive/lib/hbase-0.92.0.jar;
ADD JAR /home/training/hive/lib/guava-r09.jar;

insert into table StudentHive select StID,StName,StYear,StScore,StRegion from


Stemp;

Java Statements:
----------------
admin.enableTable("Student");
admin.disableTable("Student");
admin.addColumn("Student", columnDescriptor);
boolean bool = admin.tableExists("emp");
admin.deleteTable("emp12");
admin.shutdown();

# HBase integration with PIG


raw = LOAD filepath/filename USING
org.apache.pig.backend.hadoop.hbase.HBaseStorage(family:col01', -loadKey true
-limit 5') AS (first_name:chararray);

# Bulkload
hadoop jar $HBASE_HOME/hbase-0.94.10.jar importtsv
-Dimporttsv.columns=HBASE_ROW_KEY,CF1:StName,CF1:StYear,CF1:StScore,CF1:StRegion '-
Dimporttsv.separator=,' 'Student' '/Student'

# Namespace Related Commands


namespace_create <namespace>, {
hbase.rsgroup.name=>'<group_name>',
hbase.namespace.quota.maxtables=>'<count>',
hbase.namespace.quota.maxregions=>'<count>'}
namespace_alter <namespace>, {
hbase.namespace.quota.maxtables=>'<count>',
hbase.namespace.quota.maxregions=>'<count>'}
namespace_drop <name>
namespace_list
namespace_get <namespace>
grant <user/group> <privilege> @<namespace>
revoke <user/group> @<namespace>

Das könnte Ihnen auch gefallen