I want to write first 5 lines to a hdfs file through spark code
sc.textFile("hdfs://localhost:8020/user/hadoop/data-master/retail_db/products/part-00000").map( rec => ( rec.split(",")(4).toDouble, rec )).sortByKey(false).map(_._2)
Here we can use saveAsTextFile API, But it's an action while we need to limit rows through transformations.