系统环境:
Hbase:0.90.3
hive:0.7.0
hive 0.7.0自带的lib下包含文件“hbase-0.89.0-SNAPSHOT.jar”,我的hbase版本是0.90.3,首先拷贝hbase-0.90.3.jar到hive/lib下,然后删除“hbase-0.89.0-SNAPSHOT.jar”。
创建hive表、hbase表:
- CREATE TABLE hbase_table_1(key int, value string)
- STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
- TBLPROPERTIES (" hbase.table.name " = "xyz");
其中属性hbase.table.name值"xyz"为hbase的表名,属性hbase.columns.mapping,"cf1:val"为列族名称。
在hive 客户端执行上面语句后,会在hive中生成表"hbase_table_1",在hbase中生成表"xyz"
导入测试数据:
- hive> CREATE TABLE pokes (foo INT, bar STRING);
- hive> LOAD DATA LOCAL INPATH './examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
- hive> INSERT OVERWRITE TABLE hbase_table_1 SELECT * FROM pokes;
- hive> select * from hbase_table_1;
troubleshooting:
- FAILED: Error in metadata: MetaException(message:org.apache.hadoop.hbase.MasterNotRunningException: CNC-JN-R-541:60000
- at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:394)
- at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:83)
- at org.apache.hadoop.hive.hbase.HBaseStorageHandler.getHBaseAdmin(HBaseStorageHandler.java:74)
- at org.apache.hadoop.hive.hbase.HBaseStorageHandler.preCreateTable(HBaseStorageHandler.java:158)
- at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.createTable(HiveMetaStoreClient.java:344)
- at org.apache.hadoop.hive.ql.metadata.Hive.createTable(Hive.java:470)
- at org.apache.hadoop.hive.ql.exec.DDLTask.createTable(DDLTask.java:3146)
- at org.apache.hadoop.hive.ql.exec.DDLTask.execute(DDLTask.java:213)
- at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:130)
- at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:57)
- at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:1063)
- at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:900)
- at org.apache.hadoop.hive.ql.Driver.run(Driver.java:748)
- at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:164)
- at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:241)
- at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:456)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- at java.lang.reflect.Method.invoke(Method.java:597)
- at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
- )
出现这个错误的原因是我引入的hbase包和hive自带的hive包冲突,删除hive/lib下的 hbase-0.89.0-SNAPSHOT.jar, OK了。
当使用hive相关管理已经存在的hbase 多列table时,出现上面错误,而且列族“department ”的确存在,最终发现原因是:在hive中使用CREATE EXTERNAL TABLE 创建表的时候,"hbase.columns.mapping"的值中不能包含空格