gpt4 book ai didi

java - Cassandra Spark Connector JavaDemo 编译错误

转载 作者:行者123 更新时间:2023-12-01 09:10:02 27 4
gpt4 key购买 nike

我正在使用 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 进行编译。我已经修复了一些问题,但下面这个问题困扰着我: 此行出现编译错误:

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,如下所示。

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 创建了更新代码的要点

关于java - Cassandra Spark Connector JavaDemo 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40975591/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com