2017-09-12 12 views
0

Apache Spark 2.1.0とCassandra 3.0.14を使用しています。私のコードでは、私は、Sparkとカサンドラの間の接続を作成したい:Apache SparkとCassandraのセッションを作成するときにNullpointerExceptionが発生する

  ... 
SparkSession sparkSession = SparkSession.builder() 
    .appName(appName) 
    .config("spark.cassandra.connection.host", "localhost")        
    .config("spark.cassandra.connection.port", 9042) 
    .getOrCreate(); 

CassandraConnector cassandraConnector = CassandraConnector 
    .apply(sparkSession.sparkContext().getConf()); 
Session session = cassandraConnector.openSession(); 
ResultSet rs = session.execute("select * from myDB.myTable"); 
      ... 

私は日食のすべてにローカルでコードを実行すると正常に動作しますが、私は私の地元の火花サーバー上のjarファイルを実行すると、私は

を取得
Exception in thread "main" java.lang.NullPointerException 

このエラーが

cassandraConnector.openSession(); 

これは私のpom.xmlである原因となる方法:

<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>xign_analysis</groupId> 
    <artifactId>xign_analysis_jar_archive</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <properties> 
     <maven.compiler.target>1.8</maven.compiler.target> 
     <maven.compiler.source>1.8</maven.compiler.source> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <build> 
    </build> 
    <dependencies> 
     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.10 --> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-core_2.10</artifactId> 
      <version>2.1.1</version> 
      <scope>compile</scope> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.10 --> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-sql_2.10</artifactId> 
      <version>2.1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-mllib_2.10</artifactId> 
      <version>2.1.1</version> 
      <scope>compile</scope> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/org.apache.cassandra/cassandra-all --> 
     <dependency> 
      <groupId>org.apache.cassandra</groupId> 
      <artifactId>cassandra-all</artifactId> 
      <version>3.11.0</version> 
      <exclusions> 
       <exclusion> 
        <groupId>org.slf4j</groupId> 
        <artifactId>log4j-over-slf4j</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.datastax.spark/spark-cassandra-connector_2.10 --> 
     <dependency> 
      <groupId>com.datastax.spark</groupId> 
      <artifactId>spark-cassandra-connector_2.10</artifactId> 
      <version>2.0.5</version> 
     </dependency> 

     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
     </dependency> 
    </dependencies> 
</project> 

私はMacbook with El Capitan(10.11.06)を使用しています。 My Spark Master、Spark Worker、Cassandraサーバーは正常に動作しています。私はこの問題をどのように修正するのか分かりません。

+0

Cassandraがlocalhost:9042で動作しているため、接続ができないようです。したがって、 'cassandraConnector.openSession()'メソッドは** null **を返します。 cassandraホストとポートを構成する別の方法はありますか? –

答えて

0

解決策が見つかりました。 spark/jars dirには、Guava:Java Core Libraries For Javaの古いバージョンがあります。この古いバージョン(v。14.0.1)を最新のもの(v。23.0)に置き換えれば、すべて正常に動作します。

関連する問題