Java 映射函数从不执行

Java 映射函数从不执行,java,apache-spark,Java,Apache Spark,我编写了一个方法,该方法采用块矩阵并设置所有非0到1的值 public BlockMatrix SetNonZeroesToOnes(BlockMatrix matrix) { // initialize JavaRDD<MatrixEntry> matrixEntries = matrix.toCoordinateMatrix().entries().toJavaRDD(); // transformation matrixEntries.map(

我编写了一个方法,该方法采用块矩阵并设置所有非0到1的值

public BlockMatrix SetNonZeroesToOnes(BlockMatrix matrix)
{
    // initialize
    JavaRDD<MatrixEntry> matrixEntries = matrix.toCoordinateMatrix().entries().toJavaRDD();

    // transformation
    matrixEntries.map(t -> 
    {
        if(t.value() != 0)
        {
            return new MatrixEntry(t.i(), t.j(), 1);
        }

        return new MatrixEntry(t.i(), t.j(), 0);
    });

    // action
    List<MatrixEntry> list = matrixEntries.collect();
    for (MatrixEntry matrixEntry : list) 
    {
        System.out.println("(" + matrixEntry.i() + ", " + matrixEntry.j() + ") = " + matrixEntry.value());
    }

    // return value
    CoordinateMatrix coordMat = new CoordinateMatrix(matrixEntries.rdd(), matrix.numRows(), matrix.numCols());
    return coordMat.toBlockMatrix();
}
public BlockMatrix setnonzerostones(块矩阵)
{
//初始化
JavaRDD matrix entries=matrix.toCoordinateMatrix().entries().toJavaRDD();
//转化
matrixEntries.map(t->
{
如果(t.值()!=0)
{
返回新矩阵entry(t.i(),t.j(),1);
}
返回新矩阵entry(t.i(),t.j(),0);
});
//行动
List=matrixEntries.collect();
for(矩阵输入矩阵输入:列表)
{
System.out.println(“(“+matrixEntry.i()+”,“+matrixEntry.j()+””=“+matrixEntry.value());
}
//返回值
CoordinateMatrix coordMat=新的CoordinateMatrix(matrix Entries.rdd(),matrix.numRows(),matrix.numCols());
返回coordMat.toBlockMatrix();
}
问题是map函数从未执行过。我还没有将该方法与我的代码集成起来,但现在我只是在它上运行JUnit测试。测试设置相当简单,块矩阵是由本地spark上下文并行化的数据生成的,并提供给方法

我知道Spark固有的延迟执行,这就是我添加collect方法的原因,因为一个操作应该触发先前转换的执行。注意,它不应该出现在最终版本中,因为其他方法将对数据集执行操作

我甚至在映射部分添加了跟踪日志,但它们从未被记录,调试器不会进入其中,当然,功能也不会执行


所以,问题是,我在这里遗漏了什么?为什么这个map->collect调用与其他类似调用不同?

您忽略了matrixEntries.map(…)调用的结果,所以Spark甚至不尝试构建结果。如果不需要对原始矩阵的引用,则应编写
matrixEntries=matrixEntries.map(…)