将hadoop+hive与aws emr上的mongodb连接(未找到类com/mongodb/dbobject)

ldxq2e6h  于 2021-05-30  发布在  Hadoop
关注(0)|答案(1)|浏览(494)

我喜欢通过mongodb连接(而不是通过bson转储)将emr集群连接到mongodb。
为此,我在aws管理控制台上生成了集群。在引导配置中,我指向了这个放在s3上的文件:


# !/bin/sh

wget -P /home/hadoop/lib http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.13.0/mongo-java-driver-2.13.0.jar

wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-core-1.3.2.jar
wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-pig-1.3.2.jar
wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-hive-1.3.2.jar

当集群生成时,我将其放入主集群,并看到它们已成功下载。
当我在Hive壳中执行此操作时:

CREATE TABLE nicks
( 
  id STRING,
  name STRING,
  business STRING,
  alias STRING
)
STORED BY 'com.mongodb.hadoop.hive.MongoStorageHandler'
TBLPROPERTIES('mongo.uri'='mongodb://54.93.123.123:27017/foo.aliases');

ADD JAR /home/hadoop/lib/mongo-hadoop-core-1.3.2.jar;
ADD JAR /home/hadoop/lib/mongo-hadoop-hive-1.3.2.jar;
ADD JAR /home/hadoop/lib/mongo-java-driver-2.13.0.jar;

Select * from nicks;

我得到一个例外:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
    at com.mongodb.hadoop.splitter.MongoSplitterFactory.getSplitterByClass(MongoSplitterFactory.java:41)
    at com.mongodb.hadoop.splitter.MongoSplitterFactory.getSplitter(MongoSplitterFactory.java:109)
    at com.mongodb.hadoop.hive.input.HiveMongoInputFormat.getSplits(HiveMongoInputFormat.java:64)
    at com.mongodb.hadoop.hive.input.HiveMongoInputFormat.getSplits(HiveMongoInputFormat.java:44)
    at org.apache.hadoop.hive.ql.exec.FetchOperator.getRecordReader(FetchOperator.java:418)
    at org.apache.hadoop.hive.ql.exec.FetchOperator.getNextRow(FetchOperator.java:561)
    at org.apache.hadoop.hive.ql.exec.FetchOperator.pushRow(FetchOperator.java:534)
    at org.apache.hadoop.hive.ql.exec.FetchTask.fetch(FetchTask.java:137)
    at org.apache.hadoop.hive.ql.Driver.getResults(Driver.java:1519)
    at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:292)
    at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:227)
    at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:430)
    at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:803)
    at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:697)
    at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:636)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: java.lang.ClassNotFoundException: com.mongodb.DBObject
    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:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 20 more

注:
我已经(使用ssh)将所有4个lib放在正确的文件夹中
MongoHiveConnectorJAR似乎已加载,因为在此之前我遇到了另一个异常,通过执行“addjar…”修复了该异常。
我检查了mongojava驱动程序jar的内容。它似乎是有效的(我在里面找到了dbobject类)
如何修复或如何调试错误?

ibps3vxo

ibps3vxo1#

解决办法是把libs也放到 /home/hadoop/hive/lib . 使用此脚本可以:


# !/bin/sh

wget -P /home/hadoop/lib http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.13.0/mongo-java-driver-2.13.0.jar

wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-core-1.3.2.jar
wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-pig-1.3.2.jar
wget -P /home/hadoop/lib https://github.com/mongodb/mongo-hadoop/releases/download/r1.3.2/mongo-hadoop-hive-1.3.2.jar

cp /home/hadoop/lib/mongo* /home/hadoop/hive/lib

相关问题