Skip to content

Commit

Permalink
disable the error message redirection for stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
chenghao-intel committed Jun 29, 2015
1 parent 00a9d22 commit 8536e81
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ case class ScriptTransformation(
child.execute().mapPartitions { iter =>
val cmd = List("/bin/bash", "-c", script)
val builder = new ProcessBuilder(cmd)
// redirectError(Redirect.INHERIT) would consume the error output from buffer and
// then print it to stderr (inherit the target from the current Scala process).
// If without this there would be 2 issues:
// We need to start threads connected to the process pipeline:
// 1) The error msg generated by the script process would be hidden.
// 2) If the error msg is too big to chock up the buffer, the input logic would be hung
builder.redirectError(Redirect.INHERIT)
val proc = builder.start()
val inputStream = proc.getInputStream
val outputStream = proc.getOutputStream
val errorStream = proc.getErrorStream
val reader = new BufferedReader(new InputStreamReader(inputStream))

val (outputSerde, outputSoi) = ioschema.initOutputSerDe(output)
Expand Down Expand Up @@ -176,6 +174,19 @@ case class ScriptTransformation(
}
}).start()

// Consume the error stream from the pipeline, otherwise it will be blocked if
// the pipeline is full.
new Thread(new Runnable() {
override def run(): Unit = {
var value = -1
do {
value = errorStream.read() // consume the error message stream.
} while (value != -1)

errorStream.close()
}
}).start()

iterator
}
}
Expand Down Expand Up @@ -278,3 +289,4 @@ case class HiveScriptIOSchema (
}
}
}

0 comments on commit 8536e81

Please sign in to comment.