如何使用指向hbase表的复杂数据类型创建外部配置单元表?

时间:2016-07-26 21:24:19

标签: hadoop hive hbase hadoop2

我有一个带有列族(名称,联系人)和列,名称(字符串),年龄(字符串),workStreet(字符串),workCity(字符串),workState(字符串)的hbase表。

我想创建一个外部配置单元表,该表指向此hbase表,其中包含以下列 Name(String),Age(String),Address(Struct)。

CREATE EXTERNAL TABLE hiveTable(id INT,name STRING, age STRING, 
address STRUCT<Street:STRING,City:STRING,State:STRING>) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" ="Name:name,Name:age,Contact:workStreet, Contact:workCity, Contact:workState") 
TBLPROPERTIES("hbase.table.name" = "hbaseTable");

遇到以下错误,

Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. 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 5 elements (counting the key if implicit))

1 个答案:

答案 0 :(得分:0)

我尝试使用Map而不是Struct。以下是查询

CREATE EXTERNAL TABLE hiveTable(id INT,name STRING,age STRING,
                           address MAP<String,String>) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ("hbase.columns.mapping" = "Name:name,Name:,Contact:") 
TBLPROPERTIES("hbase.table.name" = "hbaseTable");