查数据println(res171.map(_.toBuffer).toBuffer)





scala> 






scala> val rdd2 = sc.textFile("hdfs://centosnode1:9000/person.json")



scala> rdd2.collect

res159: Array[String] = Array(1201 satish8 21, 1202 tom 21, 1203 xiaoming 22, 1204 satish1 21, 1205 satish2 23, 1206 satish3 21, 1207 satish4 23, 1208 satish5 25, 1209 satish6 26, 1210 satish7 21)


scala> rdd2.collect

res160: Array[String] = Array(1201 satish8 21, 1202 tom 21, 1203 xiaoming 22, 1204 satish1 21, 1205 satish2 23, 1206 satish3 21, 1207 satish4 23, 1208 satish5 25, 1209 satish6 26, 1210 satish7 21)


scala> rdd2.flatMap(_.split(","));
res161: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[294] at flatMap at :30


scala> res161.collect

res162: Array[String] = Array(1201 satish8 21, 1202 tom 21, 1203 xiaoming 22, 1204 satish1 21, 1205 satish2 23, 1206 satish3 21, 1207 satish4 23, 1208 satish5 25, 1209 satish6 26, 1210 satish7 21)


scala> rdd2.flatMap(_.split(",")).map(x=>(x._1,x18/04/22 21:38:05 INFO storage.BlockManagerInfo: Removed 


scala> rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2));
:30: error: value _1 is not a member of String
              rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2));
                                                   ^
:30: error: value _2 is not a member of String
              rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2));
                                                        ^


scala> rdd2.flatMap(_.split(",")).map(x=>(x,1))
res164: org.apache.spark.rdd.RDD[(String, Int)] = MapPartitionsRDD[298] at map at :30


scala> res164.collect

res165: Array[(String, Int)] = Array((1201 satish8 21,1), (1202 tom 21,1), (1203 xiaoming 22,1), (1204 satish1 21,1), (1205 satish2 23,1), (1206 satish3 21,1), (1207 satish4 23,1), (1208 satish5 25,1), (1209 satish6 26,1), (1210 satish7 21,1))


scala> rdd2.flatMap(_.split(",")).map(x=>(x))
res166: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[300] at map at :30


scala> res166.collect

res167: Array[String] = Array(1201 satish8 21, 1202 tom 21, 1203 xiaoming 22, 1204 satish1 21, 1205 satish2 23, 1206 satish3 21, 1207 satish4 23, 1208 satish5 25, 1209 satish6 26, 1210 satish7 21)


scala> rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2,x._0)
     | ;
:2: error: ')' expected but ';' found.
       ;
       ^


scala> rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2,x._0);
:1: error: ')' expected but ';' found.
       rdd2.flatMap(_.split(",")).map(x=>(x._1,x._2,x._0);
                                                         ^


scala> rdd2.flatMap(_.split(" "));
res168: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[301] at flatMap at :30


scala> res168.collect

res169: Array[String] = Array(1201, satish8, 21, 1202, tom, 21, 1203, xiaoming, 22, 1204, satish1, 21, 1205, satish2, 23, 1206, satish3, 21, 1207, satish4, 23, 1208, satish5, 25, 1209, satish6, 26, 1210, satish7, 21)


scala> rdd2.map(_.split(" "));
res170: org.apache.spark.rdd.RDD[Array[String]] = MapPartitionsRDD[302] at map at :30


scala> res170.collect

res171: Array[Array[String]] = Array(Array(1201, satish8, 21), Array(1202, tom, 21), Array(1203, xiaoming, 22), Array(1204, satish1, 21), Array(1205, satish2, 23), Array(1206, satish3, 21), Array(1207, satish4, 23), Array(1208, satish5, 25), Array(1209, satish6, 26), Array(1210, satish7, 21))



scala> println(res171)
[[Ljava.lang.String;@2c05c8d1


scala> println(res171.toBuffer)
ArrayBuffer([Ljava.lang.String;@1b9bc3f7, [Ljava.lang.String;@6d362839, [Ljava.lang.String;@19584d4, [Ljava.lang.String;@429ff890, [Ljava.lang.String;@7de0f4f, [Ljava.lang.String;@5b75886d, [Ljava.lang.String;@766b14f3, [Ljava.lang.String;@4b8d29d6, [Ljava.lang.String;@3c5ef39f, [Ljava.lang.String;@4b9f2299)


scala> println(res171.map(_.toBuffer))
[Lscala.collection.mutable.Buffer;@78c24cb6


scala> println(res171.map(_.toBuffer)).toBuffer
:34: error: value toBuffer is not a member of Unit
              println(res171.map(_.toBuffer)).toBuffer
                                              ^


scala> println(res171.map(_.toBuffer).toBuffer)
ArrayBuffer(ArrayBuffer(1201, satish8, 21), ArrayBuffer(1202, tom, 21), ArrayBuffer(1203, xiaoming, 22), ArrayBuffer(1204, satish1, 21), ArrayBuffer(1205, satish2, 23), ArrayBuffer(1206, satish3, 21), ArrayBuffer(1207, satish4, 23), ArrayBuffer(1208, satish5, 25), ArrayBuffer(1209, satish6, 26), ArrayBuffer(1210, satish7, 21))


scala> 

你可能感兴趣的:(spark)