创建hbase表,hive创建hbase扩展表,hive查询hbase表中的数据

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

hbase(main):001:0> 
hbase(main):002:0* CREATE 'comeon','babe' -- 创建表,列簇
0 ROW(s) IN 1.7750 seconds

=> Hbase::TABLE - comeon
hbase(main):003:0> LIST  -- 查看hbase所有表
TABLE                                                                                                                                                                                                 
comeon                                                                                                                                                                                                
1 ROW(s) IN 0.0180 seconds

=> ["comeon"]
hbase(main):004:0> put 'comeon','10000','babe:name','comeon'  -- 插入第一条数据,rowkey 为 10000
0 ROW(s) IN 0.0970 seconds

hbase(main):005:0> put 'comeon','10000','babe:age','30'   -- 插入第二条数据,rowkey 为 10000
0 ROW(s) IN 0.0150 seconds

hbase(main):006:0> put 'comeon','10000','babe:sex','male'   -- 插入第三条数据,rowkey 为 10000
0 ROW(s) IN 0.0140 seconds

-- 查看comeon表,rowkey为10000上的数据
hbase(main):010:0> get 'comeon','10000'
COLUMN                                             CELL                                                                                                                                               
 babe:age                                          TIMESTAMP=1597390271701, VALUE=30                                                                                                                  
 babe:NAME                                         TIMESTAMP=1597390222610, VALUE=comeon                                                                                                              
 babe:sex                                          TIMESTAMP=1597390296989, VALUE=male                                                                                                                
1 ROW(s) IN 0.0150 seconds

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

hbase(main):012:0* scan 'comeon'
ROW                                                COLUMN+CELL                                                                                                                                        
 10000                                             column=babe:age, timestamp=1597390271701, value=30                                                                                                 
 10000                                             column=babe:name, timestamp=1597390222610, value=comeon                                                                                            
 10000                                             column=babe:sex, timestamp=1597390296989, value=male                                                                                               
 10000000                                          column=babe:hobby, timestamp=1597393230640, value=                                                                                                 
 10000000                                          column=babe:mountain, timestamp=1597393266316, value=\xE5\x96\x9C\xE9\xA9\xAC\xE6\x8B\x89\xE9\x9B\x85                                              
2 row(s) in 0.0200 seconds

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

-- 创建扩展表
CREATE EXTERNAL TABLE IF NOT EXISTS comeon(
         Rowkey  STRING,
         AGE  STRING, 
         NAME  STRING,
         SEX  STRING
  )
 STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
 WITH SERDEPROPERTIES('hbase.columns.mapping' = ':key,babe:age,babe:name,babe:sex')
 TBLPROPERTIES('hbase.table.name' = 'comeon');
OK
TIME taken: 0.456 seconds
-- 成功创建扩展表

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

hive> SHOW DATABASES;
OK
-- 默认DB
DEFAULT
TIME taken: 0.033 seconds, Fetched: 1 ROW(s)
hive> USE DEFAULT;
OK
TIME taken: 0.023 seconds
hive> SHOW TABLES;
OK
-- 显示扩展表
comeon
TIME taken: 0.048 seconds, Fetched: 1 ROW(s)
hive> 
-- 查询表数据
hive> SELECT * FROM comeon;
OK
10000   30      comeon  male
TIME taken: 1.578 seconds, Fetched: 1 ROW(s)
hive> 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

 

 

你可能感兴趣的:(大数据,数据库)