Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

scala - How to remove parentheses around records when saveAsTextFile on RDD[(String, Int)]?

I'm using saveAsTextFile(path) in order to save output as text file in later to import the result to DB. The output looks something like this:

(value1, value2)

How to remove the parentheses?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try the following which is very basic:

rdd.map(x => x._1 + "," + x._2).saveAsTextFile(path)

You just map your RDD[(A,B)] to an RDD[String] and save it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...