-
-
Save manboubird/eac6188828a62a53666d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.scalding._ | |
import cascading.pipe.Pipe | |
import spray.json.JsonWriter | |
import org.apache.hadoop.io.BytesWritable | |
case class Sequins[V](p : String)(implicit writer: JsonWriter[V]) | |
extends FixedPathSource(p) | |
with WritableSequenceFileScheme | |
with TypedSink[(String, V)] { | |
import Dsl._ | |
override val fields = Dsl.intFields(0 to 1) | |
override val keyType = classOf[BytesWritable] | |
override val valueType = classOf[BytesWritable] | |
override def setter[Z <: (String, V)] = TupleSetter.asSubSetter(TupleSetter.of[(String, V)]) | |
override def transformForWrite(pipe: Pipe) : Pipe = { | |
pipe.map((0, 1) -> (0, 1)) { pair: (String, V) => | |
val jsonBytes = writer.write(pair._2).compactPrint.getBytes | |
(new BytesWritable(pair._1.getBytes), new BytesWritable(jsonBytes)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment