为什么我在rdd中的println打印元素字符串? [英] Why does my println in rdd prints the string of elements?

查看:87
本文介绍了为什么我在rdd中的println打印元素字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试打印RDD的内容时,它打印的内容如下所示,该如何打印内容?谢谢!

When I try to print the contents of my RDD, it prints something like displayed below, how can I print the content? Thanks!

scala> lines
res15: org.apache.spark.rdd.RDD[Array[String]] = MapPartitionsRDD[3] at filter at <console>:23



scala> lines.take(5).foreach(println)

[Ljava.lang.String;@6d3db5d1
[Ljava.lang.String;@6e6be45e
[Ljava.lang.String;@6d5e0ff4
[Ljava.lang.String;@3a699444
[Ljava.lang.String;@69851a51

推荐答案

这是因为它对给定对象使用 toString 实现.在这种情况下, Array 打印出类型和哈希值.如果将其转换为 List ,则由于 List toString 实现

This is because it uses the toString implementation for the given object. In this case Array prints out the type and hash. If you convert it to a List then it will be a prettier output due to List's toString implementation

scala>println(Array("foo"))
[Ljava.lang.String;HASH    

scala>println(Array("foo").toList)
List(foo)

这篇关于为什么我在rdd中的println打印元素字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆