使用transform将JavaPairRDD连接到JavaPairDStream时出现不兼容的类型错误

时间:2016-03-02 15:12:48

标签: java apache-spark spark-streaming

我正在尝试使用转换将JavaPairRDD加入JavaPairDStream中的RDD,但是我收到以下错误:

incompatible types: no instance(s) of type variable(s) W exist so that org.apache.spark.api.java.JavaPairRDD<java.lang.String,scala.Tuple2<LogType,W>> conforms to org.apache.spark.api.java.JavaRDD<U>

这是我的代码:

// Load full table from C*
JavaPairRDD<String,CassTableType> table = javaFunctions(
  jssc
).cassandraTable(
  "mykeyspace", "mytable", mapRowTo(CassTableType.class)
).keyBy(
  t -> t.getLogId()
);

// Process stream
JavaPairDStream<String,LogType> logs = flumeStream.flatMapToPair(
  flumeEvent -> { 
    List<Tuple2<String, LogType>> events = new LinkedList<>();
    LogType log = LogType.parse(flumeEvent);
    events.add(new Tuple2<String, LogType>(log.getLogID(), log));
    return events;
  }
);

// Join RDD's in logs DStream to table
JavaPairDStream<String, Tuple2<LogType, CassTableType>> 
  joinedRDD = logs.transform(
    rdd -> rdd.join(table))
);

根据我正在转变的JavaRDD<U>,这是否意味着rdd是JavaPairRDD<String,LogType>而不是JavaPairDStream<String,LogType>?我如何实现这种加入?

1 个答案:

答案 0 :(得分:0)

使用transformToPair代替转换解决了它。