Mercurial > lbo > hg > localmr
changeset 21:10e930e0f531
Some docs, implement MRSinkGenerator for WriteLogWriter as Sink
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 31 Jan 2016 14:05:37 +0000 |
parents | 12e16da09d18 |
children | 63d1a6b2dfda |
files | src/formats/lines.rs src/formats/writelog.rs |
diffstat | 2 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/formats/lines.rs Sun Jan 31 13:53:06 2016 +0000 +++ b/src/formats/lines.rs Sun Jan 31 14:05:37 2016 +0000 @@ -71,6 +71,8 @@ } } +/// An MRSinkGenerator type that uses a simple path as base +/// and creates text files based on it. pub struct LinesSinkGenerator { basepath: String, } @@ -83,6 +85,7 @@ } } +/// Writer that separates the chunks written by '\n' characters. pub struct LinesWriter { file: fs::File, }
--- a/src/formats/writelog.rs Sun Jan 31 13:53:06 2016 +0000 +++ b/src/formats/writelog.rs Sun Jan 31 14:05:37 2016 +0000 @@ -12,6 +12,7 @@ use mapreducer::Record; use formats::util::RecordIterator; +use formats::util::MRSinkGenerator; /// A length-prefixed record stream named for the original use case, /// which was to write a log of all write operations to a database. @@ -106,6 +107,29 @@ } } +pub struct WriteLogGenerator { + base: String, +} + +impl WriteLogGenerator { + pub fn new(base: &String) -> WriteLogGenerator { + WriteLogGenerator { base: base.clone() } + } +} + +impl MRSinkGenerator for WriteLogGenerator { + type Sink = WriteLogWriter; + fn new_output(&mut self, suffix: &String) -> Self::Sink { + let mut path = self.base.clone(); + path.push_str(&suffix[..]); + let writer = WriteLogWriter::new_to_file(&path, false); + match writer { + Err(e) => panic!("Could not open {}: {}", path, e), + Ok(w) => w + } + } +} + /// A Reader for WriteLog files. (more information on WriteLog files is to /// be found above at WriteLogWriter). pub struct WriteLogReader {