6

How can you write to multiple outputs dependent on the key using Scalding(/cascading) in a single Map Reduce Job. I could of course use .filter for all the possible keys, but that is a horrible hack, which will fire up many jobs.

samthebest
  • 30,803
  • 25
  • 102
  • 142

3 Answers3

6

There is TemplatedTsv in Scalding (from version 0.9.0rc16 and up), exactly same as Cascading TemplateTsv.

Tsv(args("input"), ('COUNTRY, 'GDP))
.read
.write(TemplatedTsv(args("output"), "%s", 'COUNTRY))
// it will create a directory for each country under "output" path in Hadoop mode.
proteus
  • 467
  • 4
  • 21
morazow
  • 251
  • 1
  • 8
  • This looks even more flexible than what I requested!! Thanks. Could you say from which Scalding version this is? Is it 0.10.0 and above? or 0.9.0? – samthebest Jun 26 '14 at 14:26
  • 1
    From codebase, it looks to be available from 0.9.0rc16 version. – morazow Jun 27 '14 at 12:18
  • @morazow is there any way to drop the fields used in the template string? In your example, basically I want the resulting files to have only the 'GDP' field in the resulting output. – Syllepsis Oct 14 '14 at 13:48
  • @Syllepsis That is really good question; but, I do not know if it is possible with current TemplatedTsv implementation. However, you can make another, your own, MyTemplatedTsv like here https://github.com/twitter/scalding/blob/0.11.0/scalding-core/src/main/scala/com/twitter/scalding/TemplateSource.scala#L99-L105 and add "override val fields = Fields.ALL" and specify the fields to be written when calling that tap. Could you please reply here if you test that? – morazow Oct 15 '14 at 13:01
0

Use MultipleOutputFormat and extrapolate from these other SO questions to write a custom output class using the output format: Create Scalding Source like TextLine that combines multiple files into single mappers, Compress Output Scalding / Cascading TsvCompressed

Community
  • 1
  • 1
samthebest
  • 30,803
  • 25
  • 102
  • 142
0

This suggestion on the Cascading User group suggests to use Cascading TemplateTap. Not sure how to connect this to Scalding though.

Sasha O
  • 3,710
  • 2
  • 35
  • 45