0

私はCassandra 2.2.8、JDK8、spark-cassandra-connector-java_2.10、spark-cassandra-connector_2.11-2.0.0-M3、cassandra-driver-core-3.1を使用しています。 .0とその後に続く Cassandra Spark Connector Example JavaDemo。このデモは、新しい2.1 Connetcor APIでコンパイルするために修正する必要があります。私はいくつかのことを修正しましたが、1つ下の、これは私に遊説されています。この行で コンパイルエラー:Cassandra Spark Connector JavaDemoコンパイルエラー

JavaPairRDD<Integer, BigDecimal> allSalesRDD = joinedRDD.flatMap(new PairFlatMapFunction<Tuple2<Integer, Tuple2<Sale, Product>>, Integer, BigDecimal>() { 
     @Override 
     public Iterable<Tuple2<Integer, BigDecimal>> call(Tuple2<Integer, Tuple2<Sale, Product>> input) throws Exception { 

エラー:

The method 
    flatMap(FlatMapFunction<Tuple2<Integer,Tuple2<SparkJavaDemo.Sale,SparkJavaDemo.Product>>,U>) in the type 
     AbstractJavaRDDLike<Tuple2<Integer,Tuple2<SparkJavaDemo.Sale,SparkJavaDemo.Product>>,JavaPairRDD<Integer,Tuple2<SparkJavaDemo. 
     Sale,SparkJavaDemo.Product>>> is not applicable for the arguments (new 
     PairFlatMapFunction<Tuple2<Integer,Tuple2<SparkJavaDemo.Sale,SparkJavaDemo.Product>>,Integer,BigDecimal>(){}) 

あなたはflatMapToPair代わりのflatMapを使用することができますおかげ

答えて

1

を以下のように。

JavaPairRDD<Integer, BigDecimal> allSalesRDD = joinedRDD.flatMapToPair(new PairFlatMapFunction<Tuple2<Integer, Tuple2<Sale, Product>>, Integer, BigDecimal>() { 
     @Override 
     public Iterator<Tuple2<Integer, BigDecimal>> call(Tuple2<Integer, Tuple2<Sale, Product>> input) throws Exception { 
      Tuple2<Sale, Product> saleWithProduct = input._2(); 
      List<Tuple2<Integer, BigDecimal>> allSales = new ArrayList<>(saleWithProduct._2().getParents().size() + 1); 
      allSales.add(new Tuple2<>(saleWithProduct._1().getProduct(), saleWithProduct._1().getPrice())); 
      for (Integer parentProduct : saleWithProduct._2().getParents()) { 
       allSales.add(new Tuple2<>(parentProduct, saleWithProduct._1().getPrice())); 
      } 
      return allSales.iterator(); 
     } 
    }); 

は私が試したhttps://gist.github.com/baghelamit/f2963d9e37acc55474559104f5f16cf1

+0

で更新されたコードのための要旨を作成しているこの**取得する別のエラーになりました**: '公共のIterator >コール(Tuple2 <整数、Tuple2 < **戻り値の型は互換性がありません** \t PairFlatMapFunction >、Integer、BigDecimal> .call(Tuple2 >) ' –

+0

コア3.1 Javaドライバを使用すると別のコンパイルエラーが発生する(2.1で問題なく動作する)実装していません \t java.lang.AutoCloseable try(セッションセッション= connector.openSession()) –

+0

JavaDemoのpom.xmlとjavaクラスを更新しました。更新されたファイルはhttps://gist.github.com/baghelamit/f2963d9e37acc55474559104f5f16cf1です。それを確認しましたか? – abaghel

関連する問題