如何为从hive jdbc查询启动的mr作业指定其他jar?

时间:2014-03-12 15:23:09

标签: java hadoop jdbc hive avro

我试图通过使用avro存储格式的jdbc查询hive表,但我在查询产生的mr作业中遇到了一个类找不到错误。奇怪的是我可以从hive shell运行查询而不会发生异常。

我可以运行不会产生地图缩减作业(select * from table limit 10)的查询,并且它可以正常工作。

2014-03-12 10:23:34,040 WARN [main] org.apache.hadoop.mapred.YarnChild: Exception running child : java.io.IOException: java.lang.reflect.InvocationTargetException
    at org.apache.hadoop.hive.io.HiveIOExceptionHandlerChain.handleRecordReaderCreationException(HiveIOExceptionHandlerChain.java:97)
    at org.apache.hadoop.hive.io.HiveIOExceptionHandlerUtil.handleRecordReaderCreationException(HiveIOExceptionHandlerUtil.java:57)
    at org.apache.hadoop.hive.shims.HadoopShimsSecure$CombineFileRecordReader.initNextRecordReader(HadoopShimsSecure.java:344)
    at org.apache.hadoop.hive.shims.HadoopShimsSecure$CombineFileRecordReader.<init>(HadoopShimsSecure.java:291)
    at org.apache.hadoop.hive.shims.HadoopShimsSecure$CombineFileInputFormatShim.getRecordReader(HadoopShimsSecure.java:405)
    at org.apache.hadoop.hive.ql.io.CombineHiveInputFormat.getRecordReader(CombineHiveInputFormat.java:560)
    at org.apache.hadoop.mapred.MapTask$TrackedRecordReader.<init>(MapTask.java:168)
    at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:409)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:342)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:165)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:160)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.hadoop.hive.shims.HadoopShimsSecure$CombineFileRecordReader.initNextRecordReader(HadoopShimsSecure.java:330)
    ... 11 more
Caused by: java.lang.NoClassDefFoundError: org/apache/avro/mapred/FsInput
    at org.apache.hadoop.hive.ql.io.avro.AvroGenericRecordReader.<init>(AvroGenericRecordReader.java:82)
    at org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat.getRecordReader(AvroContainerInputFormat.java:51)
    at org.apache.hadoop.hive.ql.io.CombineHiveRecordReader.<init>(CombineHiveRecordReader.java:65)
    ... 16 more
Caused by: java.lang.ClassNotFoundException: org.apache.avro.mapred.FsInput
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more

2 个答案:

答案 0 :(得分:1)

可能是hive.aux.jars.path包含用户定义函数和serdes 实现的插件jar的位置。 CLI可以从JDBC hiverserver / hiverservre2中获取另一个配置值。尝试在两个环境中运行set hive.aux.jars.path;并比较结果。例如。 here Denny将所有avro JAR添加到hive-site.xml中的hive.aux.jars.path。

答案 1 :(得分:0)

解决方案是为每个创建的新连接执行以下sql stmt。

add jar /hive-ext/avro-mapred-1.7.5-cdh5.0.0-beta-2-hadoop2.jar ;

路径/hive-ext对于配置单元服务器是本地的,即在运行配置单元服务器的同一台机器上

请务必更改您的语句以匹配avro-mapred jar文件的名称