duckertito duckertito - 1 year ago 124
Scala Question

How to save RDD data into json files, not folders

I am receiving the streaming data

) that I want to save in S3 (basically, for this question, it doesn't matter where exactly do I want to save the outputs, but I am mentioning it just in case).

The following code works well, but it saves folders with the names like
, and then inside the folders it saves files

Is it possible to save each
(these are JSON strings) data into the JSON files, not the folders? I thought that
had to make this trick, but it didn't.

myDStream.foreachRDD { rdd =>
// datetimeString = ....

Answer Source

AFAIK there is no option to save it as a file. Because it's a distributed processing framework and it's not a good practice write on single file rather than each partition writes it's own files in the specified path.

We can pass only output directory where we wanted to save the data. OutputWriter will create file(s)(depends on partitions) inside specified path with part- file name prefix.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download