首页 > 代码库 > 创建Hive/hbase相关联的表异常
创建Hive/hbase相关联的表异常
hive> CREATE TABLE hperson(id string, name string,email string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":id,cf1:name,cf2:email") TBLPROPERTIES ("hbase.table.name" = "hbperson");、
FAILED: Error in metadata: java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.SerDeException org.apache.hadoop.hive.hbase.HBaseSerDe: columns has 3 elements while hbase.columns.mapping has 4 elements (counting the key if implicit))
在创建hive/hbase相关联的表时,hbase表结构默认会有一个字段key,如果没有一个显示的字段‘key‘那么在创建表的进修,会自己创建,这样hive对应的表就会出现问题,所以在hive对应的表里一定要加上key这个字段,为了避免这个问题,在hbase表结构里可以显示的添加‘key‘字段,这样不容易出问题。
正确的格式如下:
CREATE TABLE hperson1(key string,id string, name string,email string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ("hbase.columns.mapping" = "cf0:id,cf1:name,cf2:email") TBLPROPERTIES ("hbase.table.name" = "hbperson1");
或者:
CREATE TABLE hperson1(key string,id string, name string,email string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf0:id,cf1:name,cf2:email") TBLPROPERTIES ("hbase.table.name" = "hbperson1");