Thanks, I was able to declare baos as a class variable and then re-initialize it via reset. json would not work this way though, the output was corrupted, even when I flushed.
On Mon, Feb 18, 2013 at 3:06 PM, Prashant Kommireddi <prash1...@gmail.com>wrote: > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/9481/ > > On February 18th, 2013, 5:51 a.m., *Prashant Kommireddi* wrote: > > > src/org/apache/pig/builtin/ToJson.java<https://reviews.apache.org/r/9481/diff/2/?file=259422#file259422line38> > (Diff > revision 2) > > None > > {'text': ' public String exec(Tuple input) throws IOException {', 'line': > 26} > > 38 > > ByteArrayOutputStream baos = new ByteArrayOutputStream(BUF_SIZE); > > This could probably be constructed lazily only once. Something like > > ByteArrayOutputStream baos; > > if(baos == null) { > baos = new ByteArrayOutputStream(BUF_SIZE); > } > > On February 18th, 2013, 10:43 p.m., *Russell Jurney* wrote: > > ByteArrayOutputStream baos; > if(baos == null) { > baos = new ByteArrayOutputStream(BUF_ > SIZE); > } > > does not parse > > On February 18th, 2013, 11:02 p.m., *Russell Jurney* wrote: > > Thanks, I did this. > > On February 18th, 2013, 11:04 p.m., *Russell Jurney* wrote: > > I had to do baos.reset() each execution to reuse this. > > "does not parse"? Did not get that. Wouldn't declaring it as a class var and > initializing only once work? > > public class ToJson extends EvalFunc<String> { > private static ByteArrayOutputStream baos = null; > > public String exec(Tuple input) throws IOException { > if(input == null ......) > // > > if(baos == null) { > baos = new ByteArrayOutputStream(BUF_SIZE); > } > > // > // > > } > > > > - Prashant > > On February 18th, 2013, 11:03 p.m., Russell Jurney wrote: > Review request for pig, Ashutosh Chauhan, Dmitriy Ryaboy, Alan Gates, > Jonathan Coveney, and Bill Graham. > By Russell Jurney. > > *Updated Feb. 18, 2013, 11:03 p.m.* > Description > > This patch is for JIRA, https://issues.apache.org/jira/browse/PIG-2641 > PIG-2641 - which adds a ToJson builtin based on the serialization in > JsonStorage. > > Testing > > This works for me locally, and there is a working unit test. > > *Bugs: * PIG-2641 <https://issues.apache.org/jira/browse/PIG-2641> > Diffs > > - src/org/apache/pig/builtin/JsonStorage.java (56086ff) > - src/org/apache/pig/builtin/ToJson.java (PRE-CREATION) > - test/org/apache/pig/test/TestToJson.java (PRE-CREATION) > - test/org/apache/pig/test/data/jsonStorage1.tojson (PRE-CREATION) > > View Diff <https://reviews.apache.org/r/9481/diff/> > -- Russell Jurney twitter.com/rjurney russell.jur...@gmail.com datasyndrome.com