用于单元测试目的我正在构建我自己的HBase Result对象,如下所示
val row = Bytes.toBytes( "row01" )
val cf = Bytes.toBytes( "cf" )
val cell1 = new KeyValue( row, cf, "v1".getBytes(), Bytes.toBytes( "file1" ) )
val cell2 = new KeyValue( row2, cf, "v2".getBytes(), Bytes.toBytes( "file2" ) )
val cells = List( cell1, cell2 )
val result = Result.create( cells )
现在我想将它添加到sparkContext对象,比如
val sparkContext = new org.apache.spark.SparkContext( conf )
val rdd = sparkContext.parallelize( List( result ) )
然而,一旦我尝试通过foreach访问rdd,比如
rdd.foreach{x=>x}
我得到着名的Spark任务不可序列化。
有没有人知道克拉特RDD的更好方法[结果]?
答案 0 :(得分:1)
Result
不可序列化,因此如果您需要RDD[Result]
,则必须从其他输入中生成节点本身的Result
(当然,还有collect
之类的操作在节点之间发送first
的{1}} Result
将无效。例如,
val rdd0 = sparkContext.parallelize( List( ("row", "cf") ) )
val rdd = rdd.map { case (str1, str2) =>
val row = Bytes.toBytes( str1 )
val cf = Bytes.toBytes( str2 )
val cell1 = new KeyValue( row, cf, "v1".getBytes(), Bytes.toBytes( "file1" ) )
val cell2 = new KeyValue( row2, cf, "v2".getBytes(), Bytes.toBytes( "file2" ) )
val cells = List( cell1, cell2 )
Result.create( cells )
}