diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java index a53b6d5..953cc4c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapRedTask.java @@ -245,10 +245,12 @@ public class MapRedTask extends ExecDriver implements Serializable { // Run ExecDriver in another JVM executor = Runtime.getRuntime().exec(cmdLine, env, new File(workDir)); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, + SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, + SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); diff --git ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java index 2f416a0..64ea416 100644 --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -80,9 +80,17 @@ public class SessionState { /** * Streams to read/write from. */ - public PrintStream out; public InputStream in; + public PrintStream out; public PrintStream err; + /** + * Standard output from any child process(es). + */ + public PrintStream childOut; + /** + * Error output from any child process(es). + */ + public PrintStream childErr; /** * type of the command. @@ -299,6 +307,16 @@ public class SessionState { return ((ss != null) && (ss.err != null)) ? ss.err : System.err; } + public PrintStream getChildOutStream() { + SessionState ss = SessionState.get(); + return ((ss != null) && (ss.childOut != null)) ? ss.childOut : System.out; + } + + public PrintStream getChildErrStream() { + SessionState ss = SessionState.get(); + return ((ss != null) && (ss.childErr != null)) ? ss.childErr : System.err; + } + public boolean getIsSilent() { SessionState ss = SessionState.get(); // use the session or the one supplied in constructor diff --git ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java index 3548533..4685471 100644 --- ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java +++ ql/src/test/org/apache/hadoop/hive/ql/QTestUtil.java @@ -662,10 +662,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdLine); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); @@ -701,10 +701,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdLine); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); @@ -756,10 +756,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdArray); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); @@ -822,10 +822,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdArray1); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); @@ -846,10 +846,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdArray); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); @@ -933,10 +933,10 @@ public class QTestUtil { Process executor = Runtime.getRuntime().exec(cmdArray); - StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), - null, System.out); - StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), - null, System.err); + StreamPrinter outPrinter = new StreamPrinter( + executor.getInputStream(), null, SessionState.getConsole().getChildOutStream()); + StreamPrinter errPrinter = new StreamPrinter( + executor.getErrorStream(), null, SessionState.getConsole().getChildErrStream()); outPrinter.start(); errPrinter.start(); diff --git ql/src/test/org/apache/hadoop/hive/ql/exec/TestExecDriver.java ql/src/test/org/apache/hadoop/hive/ql/exec/TestExecDriver.java index c6a1862..bbc008b 100644 --- ql/src/test/org/apache/hadoop/hive/ql/exec/TestExecDriver.java +++ ql/src/test/org/apache/hadoop/hive/ql/exec/TestExecDriver.java @@ -48,6 +48,7 @@ import org.apache.hadoop.hive.ql.plan.PlanUtils; import org.apache.hadoop.hive.ql.plan.ReduceSinkDesc; import org.apache.hadoop.hive.ql.plan.ScriptDesc; import org.apache.hadoop.hive.ql.plan.SelectDesc; +import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.serde.Constants; import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory; import org.apache.hadoop.mapred.TextInputFormat;