繁体   English   中英

映射数据集行得到“此表达式的目标类型必须是功能接口”

[英]Mapping Dataset row getting “The target type of this expression must be a functional interface”

尝试映射到数据集行但有很多问题,我在地图上遇到了eclipse错误“此表达式的目标类型必须是功能接口” map(r -> new MapFunction<r, List<Tuple3<Long, Integer, Double>>>() 。代码如下:

Dataset<Object> df1 = session.read().parquet(tableName).as(Encoders.bean(Object.class));

        JavaRDD<List<Tuple3<Long, Integer, Double>>> tempData = df1.map(r -> new MapFunction<r, List<Tuple3<Long, Integer, Double>>>(){


            // to get each sample individually
            List<Tuple2<String, Integer>> samples = zipWithIndex((r.getString(9).trim().split(",")));

            // Gets the unique identifier for that pos.
            Long snp = r.getString(1);

            // Calculates the distance for this pos for each sample.
            // i.e. 0|0 => 0, 0|1 => 1, 1|0 => 1, 1|1 => 2
            return samples.stream().map(t -> {
                String alleles = t._1();
                Integer patient = t._2();

                List<String> values = Arrays.asList(alleles.split("\\|"));

                Double firstAllele = Double.parseDouble(values.get(0));
                Double secondAllele = Double.parseDouble(values.get(1));

                // Returns the initial SNP id, patient id and the distance in form of Tuple.
                return new Tuple3<>(snp, patient, firstAllele + secondAllele);
            }).collect(Collectors.toList());
        });

任何帮助,将不胜感激。

由于缺乏清晰性,我只是提出我的未完成的建议。

假设您是在指org.apache.spark.api.java.function.MapFunction

我看到了一系列问题,

  1. MapFunction<r ..>行中的r作为通用类型使用

  2. 匿名函数的定义不正确,请使用lambda表达式说,

```

JavaRDD<List<Tuple3<Long, Integer, Double>>> tempData = df1.map(r -> () {
// your definition
}

```

或者,将代码移至类的方法中

JavaRDD<List<Tuple3<Long, Integer, Double>>> tempData = df1.map(r -> new MapFunction<theRespectiveType, List<Tuple3<Long, Integer, Double>>>(){
public List<Tuple3<Long, Integer, Double>> call(theRespectiveType variable)
{
// your implementation here
});

```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM