Java - Spark SQL DataFrame map function is not working

后端 未结 6 811
说谎
说谎 2021-01-01 01:46

In Spark SQL when I tried to use map function on DataFrame then I am getting below error.

The method map(Function1, ClassTag) in the type DataFrame is not applicab

6条回答
  •  隐瞒了意图╮
    2021-01-01 02:44

    Change this to:

    Java 6 & 7

    List teenagerNames = teenagers.javaRDD().map(
        new Function() {
        public String call(Row row) {
            return "Name: " + row.getString(0);
        }
    }).collect();
    

    Java 8

    List t2 = teenagers.javaRDD().map(
        row -> "Name: " + row.getString(0)
    ).collect();
    

    Once you call javaRDD() it works just like any other RDD map function.

    This works with Spark 1.3.0 and up.

提交回复
热议问题