Java Spark SQL RowFactory返回空行

Java Spark SQL RowFactory返回空行,java,apache-spark,apache-spark-sql,Java,Apache Spark,Apache Spark Sql,我有一个具有以下模式的数据集: {"user":"A10T7BS07XCWQ1","recommendations":[{"iID":34142,"rating":22.998692},{"iID":24963,"rating":22.678337},{"iID":47761,"rating":22.31455},{"iID":28694,"rating":21.269365},{"iID":36890,"rating":21.143366},{"iID":48522,"rating":20.6

我有一个具有以下模式的数据集:

{"user":"A10T7BS07XCWQ1","recommendations":[{"iID":34142,"rating":22.998692},{"iID":24963,"rating":22.678337},{"iID":47761,"rating":22.31455},{"iID":28694,"rating":21.269365},{"iID":36890,"rating":21.143366},{"iID":48522,"rating":20.678747},{"iID":20032,"rating":20.330639},{"iID":57315,"rating":20.099955},{"iID":18148,"rating":20.07064},{"iID":7321,"rating":19.754635}]}
我尝试通过以下方式平面映射我的数据集:

    StructType struc = new StructType();
    struc.add("user", DataTypes.StringType, false);
    struc.add("item", DataTypes.IntegerType, false);
    struc.add("relevance", DataTypes.DoubleType, false);
    ExpressionEncoder<Row> encoder = RowEncoder.apply(struc);

    Dataset<Row> recomenderResult = userRecs.flatMap((FlatMapFunction<Row, Row>) row -> {
        String user = row.getString(0);
        List<Row> recsWithIntItemID = row.getList(1);
        Integer item;
        Double relevance;
        List<Row> rows = new ArrayList<>();

        for (Row rec : recsWithIntItemID) {

            item = rec.getInt(0);
            relevance = (double) rec.getFloat(1);
            System.out.println(user + " : " + item + " : " + relevance);

            Row newRow = RowFactory.create(user, item, relevance);
            rows.add(newRow);
        }
        System.out.println("++++++++++++++++++++++++++++++++");
        return rows.iterator();
    }, encoder);

    recomenderResult.write().json("temp2");
    recomenderResult.show();
但Row实例为空,show()方法给出如下输出:

++
||
++
||
||
我不知道为什么我的结果数据集是空的。我已经在这个网站上观看了所有与我的问题相关的主题,并使用了谷歌,但我还没有找到解决我问题的方法。有人能帮我吗?

这是一个非常愚蠢的错误:(简单的回答,错误在这里:

    StructType struc = new StructType();
    struc = struc.add("user", DataTypes.StringType, false);
    struc = struc.add("item", DataTypes.IntegerType, false);
    struc = struc.add("relevance", DataTypes.DoubleType, false);
    ExpressionEncoder<Row> encoder = RowEncoder.apply(struc);
StructType struc=new StructType();
struc=struc.add(“用户”,DataTypes.StringType,false);
struc=struc.add(“项”,DataTypes.IntegerType,false);
struc=struc.add(“相关性”,DataTypes.DoubleType,false);
ExpressionEncoder编码器=RowEncoder.apply(struc);
我花了两天一夜

    StructType struc = new StructType();
    struc = struc.add("user", DataTypes.StringType, false);
    struc = struc.add("item", DataTypes.IntegerType, false);
    struc = struc.add("relevance", DataTypes.DoubleType, false);
    ExpressionEncoder<Row> encoder = RowEncoder.apply(struc);