Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Apache Spark函数2,声明不正确_Java_Apache Spark_Map Function - Fatal编程技术网

Java Apache Spark函数2,声明不正确

Java Apache Spark函数2,声明不正确,java,apache-spark,map-function,Java,Apache Spark,Map Function,(这是基于尝试将整数RDD映射到TholdDropResult RDD,但我们需要初始化单个SparkDoDrop来生成所有(10^8)TholdDropResults,因此使用了Java中唯一的mapPartition风格,它将提供我们需要的函数类型methinks。) 问题:我使用org.apache.spark.api.java.function.Function2时出错 我不知道如何将“布尔值”转换为新函数2 当我尝试此代码时,向右滚动以查看似乎给我带来麻烦的newfunction2声明

(这是基于尝试将整数RDD映射到TholdDropResult RDD,但我们需要初始化单个SparkDoDrop来生成所有(10^8)TholdDropResults,因此使用了Java中唯一的mapPartition风格,它将提供我们需要的函数类型methinks。)

问题:我使用
org.apache.spark.api.java.function.Function2时出错

我不知道如何将“布尔值”转换为
新函数2

当我尝试此代码时,向右滚动以查看似乎给我带来麻烦的
newfunction2
声明(从应答中添加了生成器样式的格式):

当我尝试将布尔arg放入其中时,如下所示:
newfunction2()
我收到一个错误:

error: wrong number of type arguments; required 3
            JavaRDD<TholdDropResult> dropResultsN = dataSetN.mapPartitionsWithIndex(new Function2<Integer, Iterator<Integer>, Iterator<TholdDropResult>, Boolean>(){

您需要在
布尔值之前使用附加的
关闭
函数2

JavaRDD<TholdDropResult> dropResultsN =
   dataSetN.mapPartitionsWithIndex(new Function2<Integer, 
                                                 Iterator<Integer>,
                                                 Iterator<TholdDropResult>>, Boolean>

函数2
接受一个
整数和一个
迭代器
,并返回一个
迭代器
。预期的
布尔值
函数2

中未定义的参数。这是可行的,不确定原因,但分离出函数2起了作用(当然我还没有编译和运行:)

Function2 makeLIThenDropResults=newfunction2(){
@凌驾
公共迭代器调用(Integer partitionID、迭代器integerIterator)引发异常{
SparkDoDrop standin=makeNewSparkDoDrop();
standin.initializeLI();
List rddToReturn=new ArrayList();
while(integerIterator.hasNext()){
添加(standin.call(integerIterator.next());
}
返回rddToReturn.iterator();
}
};
//现在做N的子集的RDD
//为并行化设置大小为N的伪数组以导致dropResultsN
JavaRDD dropResultsN=dataSetN.mapPartitionsWithIndex(makeLIThenDropResults,true);

(帽子提示)

我将选择+1并接受,部分原因是为了提醒我应该使用更好的格式。同时,这并没有解决它。当我使用
dataSetN.mapPartitionsWithIndex(新函数2,布尔值>(){
I将使用foreachPartition()时,我得到了意外的标记、@Override上的错误以及更多错误但是我需要这个来返回TholdDropResult的RDD,我不相信foreachPartition允许除VoidFunction之外的任何函数。HMMMI得到了它,请看我的答案,感谢你为我指明了正确的方向,也从这个答案中得到了帮助,FWIW这种方法的全部原因是因为行
standin.initializeLI();
创建一个相当大的对象,我们不想序列化,我们希望Spark在执行器上创建这个对象。
error: wrong number of type arguments; required 3
            JavaRDD<TholdDropResult> dropResultsN = dataSetN.mapPartitionsWithIndex(new Function2<Integer, Iterator<Integer>, Iterator<TholdDropResult>, Boolean>(){
error: unexpected type
            JavaRDD<TholdDropResult> dropResultsN = dataSetN.mapPartitionsWithIndex(new Function2<Integer, Iterator<Integer>, Iterator<TholdDropResult>, boolean>(){
                                                                                                                                                         ^
  required: reference
  found:    boolean

error: wrong number of type arguments; required 3
            JavaRDD<TholdDropResult> dropResultsN = dataSetN.mapPartitionsWithIndex(new Function2<Integer, Iterator<Integer>, Iterator<TholdDropResult>, boolean>(){
JavaRDD<TholdDropResult> dropResultsN =
   dataSetN.mapPartitionsWithIndex(new Function2<Integer, 
                                                 Iterator<Integer>,
                                                 Iterator<TholdDropResult>>, Boolean>
<R> JavaRDD<R> mapPartitionsWithIndex(Function2<java.lang.Integer,
                                                java.util.Iterator<T>,
                                                java.util.Iterator<R>> f,
                                                boolean preservesPartitioning)
        Function2 makeLIThenDropResults = new Function2<Integer,
                                                        Iterator<Integer>,
                                                        Iterator<TholdDropResult>>() {
            @Override
            public Iterator<TholdDropResult> call(Integer partitionID, Iterator<Integer> integerIterator) throws Exception {
                SparkDoDrop standin = makeNewSparkDoDrop();

                standin.initializeLI();
                List<TholdDropResult> rddToReturn = new ArrayList<>();
                while (integerIterator.hasNext()){
                    rddToReturn.add(standin.call(integerIterator.next()));
                }
                return rddToReturn.iterator();
            }
        };

        // now make the RDD of subset of N
        // setup bogus arrays of size N for parallelize to lead to dropResultsN
        JavaRDD<TholdDropResult> dropResultsN = dataSetN.mapPartitionsWithIndex(makeLIThenDropResults, true);