AngersZhuuuu commented on a change in pull request #29085:
URL: https://github.com/apache/spark/pull/29085#discussion_r458620082
##########
File path: sql/core/src/test/resources/sql-tests/inputs/transform.sql
##########
@@ -0,0 +1,72 @@
+-- Test data.
+CREATE OR REPLACE TEMPORARY VIEW t1 AS SELECT * FROM VALUES
Review comment:
Done
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/BaseScriptTransformationExec.scala
##########
@@ -56,10 +69,88 @@ trait BaseScriptTransformationExec extends UnaryExecNode {
}
}
- def processIterator(
+ protected def initProc: (OutputStream, Process, InputStream, CircularBuffer)
= {
+ val cmd = List("/bin/bash", "-c", script)
+ val builder = new ProcessBuilder(cmd.asJava)
+
+ val proc = builder.start()
+ val inputStream = proc.getInputStream
+ val outputStream = proc.getOutputStream
+ val errorStream = proc.getErrorStream
+
+ // In order to avoid deadlocks, we need to consume the error output of the
child process.
+ // To avoid issues caused by large error output, we use a circular buffer
to limit the amount
+ // of error output that we retain. See SPARK-7862 for more discussion of
the deadlock / hang
+ // that motivates this.
+ val stderrBuffer = new CircularBuffer(2048)
+ new RedirectThread(
+ errorStream,
+ stderrBuffer,
+ s"Thread-${this.getClass.getSimpleName}-STDERR-Consumer").start()
+ (outputStream, proc, inputStream, stderrBuffer)
+ }
+
+ protected def processIterator(
inputIterator: Iterator[InternalRow],
hadoopConf: Configuration): Iterator[InternalRow]
+ protected def createOutputIteratorWithoutSerde(
+ writerThread: BaseScriptTransformationWriterThread,
+ inputStream: InputStream,
+ proc: Process,
+ stderrBuffer: CircularBuffer): Iterator[InternalRow] = {
+ new Iterator[InternalRow] {
+ var curLine: String = null
+ val reader = new BufferedReader(new InputStreamReader(inputStream,
StandardCharsets.UTF_8))
+
+ val outputRowFormat =
ioschema.outputRowFormatMap("TOK_TABLEROWFORMATFIELD")
+ val processRowWithoutSerde = if (!ioschema.schemaLess) {
+ prevLine: String =>
+ new GenericInternalRow(
+ prevLine.split(outputRowFormat)
+ .zip(fieldWriters)
+ .map { case (data, writer) => writer(data) })
+ } else {
+ // In schema less mode, hive default serde will choose first two
output column as output
+ // if output column size less then 2, it will throw
ArrayIndexOutOfBoundsException.
+ // Here we change spark's behavior same as hive's default serde
+ prevLine: String =>
+ new GenericInternalRow(
+ prevLine.split(outputRowFormat).slice(0, 2)
+
.map(CatalystTypeConverters.createToCatalystConverter(StringType)))
Review comment:
Done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]