【问题标题】:Cassandra as input to Hadoop job exceptionCassandra 作为 Hadoop 作业异常的输入
【发布时间】:2015-06-04 18:14:55
【问题描述】:

由于某种原因,我在尝试使用 Cassandra 作为 Hadoop 的输入时遇到以下异常

Exception in thread "main" java.lang.NoClassDefFoundError: com/datastax/driver/core/policies/LoadBalancingPolicy

这里是代码

public class CDriver extends Configured implements Tool{

public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException, Exception
{
    Configuration conf = new Configuration();

    ToolRunner.run(new CDriver(), args);
}

@Override
public int run(String[] args) throws Exception {

    String output = args[0];

    Configuration conf = super.getConf();

    Job job = new Job(conf);

    job.setJarByClass(CDriver.class);
    job.setJobName("Cassandra as input");

    ConfigHelper.setInputInitialAddress(conf, "127.0.0.1");
    ConfigHelper.setInputColumnFamily(conf, "basketball", "nba");
    ConfigHelper.setInputPartitioner(conf, "Murmur3Partitioner");
    CqlConfigHelper.setInputCQLPageRowSize(conf, "3");
    job.setInputFormatClass(CqlInputFormat.class);

    FileOutputFormat.setOutputPath(job, new Path(output));

    job.setMapperClass(CMapper.class);
    job.setReducerClass(CReducer.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    job.waitForCompletion(true);

    return 0;
}

}

它在下一行熄灭

CqlConfigHelper.setInputCQLPageRowSize(conf, "3");

这里是 Maven 依赖项:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.nissatech</groupId>
    <artifactId>TestingCassandra</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-core</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cassandra</groupId>
            <artifactId>cassandra-all</artifactId>
            <version>2.1.5</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.nissatech.testingcassandra.CDriver</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>
                            jar-with-dependencies
                        </descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

谁能解释一下是什么问题?我在 localhost 上运行 Cassandra。

【问题讨论】:

  • 如何向 hadoop 提交作业?
  • 我已经尝试在 NetBeans 和伪分布式模式下使用 hadoop jar TestingCassandra-1.0-SNAPSHOT-jar-with-dependencies.jar /user/pera/testingcassandra/output 和一个胖 jar。
  • 你能显示完整的 pom.xml(或关于 fat jar 的部分)吗?你确定所有的 cassandra deps 都在你的胖罐子里吗?
  • 我已添加完整的 pom.xml,感谢您的关注。

标签: hadoop cassandra


【解决方案1】:

您还需要将 Datastax Java 驱动程序作为第三方依赖项包含在您的 pom.xml 中。见https://github.com/datastax/java-driver#maven。如果您将其作为传递依赖项,请确保您使用的是正确的版本。

【讨论】:

  • 感谢您的回答。但不应该已经包括在内了吗?如果您查看 mvnrepository.com/artifact/org.apache.cassandra/cassandra-all/... 您可以看到它作为我包含的 jar 的依赖项而存在。我尝试了您的建议,结果发生的奇怪事情是-在NetBeans中我得到了一个新异常-java.lang.UnsupportedOperationException:您必须使用setInputColumnFamily()设置键空间和列族,而在伪分布式模式下运行我得到了同样的异常,即使我已经添加了依赖项和重建项目?
  • 听起来好像您的依赖项依赖于不同版本的 Datastax Cassandra 驱动程序。你检查过不同版本的驱动是否有多个传递依赖吗?
  • 好吧,我不这么认为。检查它的最佳方法是什么?我一步一步跟着这个gerrymcnicol.com/index.php/2014/01/21/… 出现了这个错误......
  • 你试过在命令行上执行mvn dependency:tree吗?如果它多次列出不同版本的驱动程序,那就是问题所在。
  • 我这样做了,但是在我将它添加到依赖项之前没有驱动程序,然后只出现一次,所以它不应该被复制。安装 Cassandra 会不会有一些问题,比如它的不同版本和库?我正在运行的 Cassandra 我从 PlanetCassandra 下载,DataStax 版本,也许我应该添加一些其他依赖项?顺便说一句,Cassandra 在终端或数据中心都可以正常工作...
猜你喜欢
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-24
  • 1970-01-01
相关资源
最近更新 更多