我创建了一个HBase表,如下所示:
创建'nancy','cf'
并在Hive中创建了一个表格,如下所示:
创建外部表nancy(id int,name string)
存储'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES(“hbase.columns.mapping”=“:key,cf:name”)
TBLPROPERTIES( “hbase.table.name”= “南西”);
我是映射它吗? “hbase.columns.mapping”中的Key表示什么?
任何人都可以解释这种映射吗?
答案 0 :(得分:4)
您是否遇到任何特定问题?查询对我来说没问题。
键表示您使用此字段作为表键。请记住,配置单元表中的每个字段都可以映射到以下其中一个:
回复您的意见:
hive> CREATE EXTERNAL TABLE hbase_table_2(key int, name string)
> STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
> WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:name")
> TBLPROPERTIES("hbase.table.name" = "nancy");
OK
Time taken: 5.106 seconds
hive> select * from hbase_table_2;
OK
Time taken: 0.077 seconds
hive> INSERT OVERWRITE TABLE hbase_table_2 SELECT * FROM demo WHERE id=1;
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_201308011237_0003, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201308011237_0003
Kill Command = /Users/miqbal1/hadoop-eco/hadoop-1.1.2/libexec/../bin/hadoop job -kill job_201308011237_0003
Hadoop job information for Stage-0: number of mappers: 1; number of reducers: 0
2013-08-01 16:29:21,832 Stage-0 map = 0%, reduce = 0%
2013-08-01 16:29:23,843 Stage-0 map = 100%, reduce = 0%
2013-08-01 16:29:24,849 Stage-0 map = 100%, reduce = 100%
Ended Job = job_201308011237_0003
1 Rows loaded to hbase_table_2
MapReduce Jobs Launched:
Job 0: Map: 1 HDFS Read: 256 HDFS Write: 0 SUCCESS
Total MapReduce CPU Time Spent: 0 msec
OK
Time taken: 8.392 seconds
hive>
这是我的HBase表:
hbase(main):017:0> scan 'nancy'
ROW COLUMN+CELL
1 column=cf:name, timestamp=1375354762803, value=tariq
1 row(s) in 0.0300 seconds
答案 1 :(得分:1)
问题在于映射":key, cf:name"
的列中的空白字符。 Hive会查找名为“cf”的列系列,而不是“cf”。 Sİnce在Tariq的回复中没有空格(":key,cf:name"
),它运作正常。
答案 2 :(得分:0)
你有两个选择,用hbase表映射hive表:
创建一个hive和hbase都可以管理的表(例如删除)
CREATE TABLE hbase_table_1(key int, name string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:name")
TBLPROPERTIES(“hbase.table.name”=“nancy”);
创建一个由hbase管理的外部表
CREATE EXTERNAL TABLE hbase_table_2(key int, name string) STORED BY
'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:name")
TBLPROPERTIES("hbase.table.name" = "nancy");
在这两种方式中你都可以使用hive sql:
insert into hbase_table_1 select 1, "name1" ;
insert into hbase_table_2 select 2, "name2" ;
HBase的(主):011:0>扫描'南希'
ROW COLUMN + CELL
1列= cf:name, timestamp = 1491979916489,value = name1
2列= cf:名称, timestamp = 1491979928355,value = name2
2行(0.3250秒)