Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,29 @@ case class ScriptTransformation(
val dataOutputStream = new DataOutputStream(outputStream)
val outputProjection = new InterpretedProjection(input, child.output)

iter
.map(outputProjection)
.foreach { row =>
if (inputSerde == null) {
val data = row.mkString("", ioschema.inputRowFormatMap("TOK_TABLEROWFORMATFIELD"),
ioschema.inputRowFormatMap("TOK_TABLEROWFORMATLINES")).getBytes("utf-8")

outputStream.write(data)
} else {
val writable = inputSerde.serialize(row.asInstanceOf[GenericRow].values, inputSoi)
prepareWritable(writable).write(dataOutputStream)
// Put the write(output to the pipeline) into a single thread
// and keep the collector as remain in the main thread.
// otherwise it will causes deadlock if the data size greater than
// the pipeline / buffer capacity.
new Thread(new Runnable() {
override def run(): Unit = {
iter
.map(outputProjection)
.foreach { row =>
if (inputSerde == null) {
val data = row.mkString("", ioschema.inputRowFormatMap("TOK_TABLEROWFORMATFIELD"),
ioschema.inputRowFormatMap("TOK_TABLEROWFORMATLINES")).getBytes("utf-8")

outputStream.write(data)
} else {
val writable = inputSerde.serialize(row.asInstanceOf[GenericRow].values, inputSoi)
prepareWritable(writable).write(dataOutputStream)
}
}
outputStream.close()
}
outputStream.close()
}).start()

iterator
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,12 @@ class SQLQuerySuite extends QueryTest {
sql(s"DROP TABLE $tableName")
}
}

test("test script transform") {
val data = (1 to 100000).map { i => (i, i, i) }
data.toDF("d1", "d2", "d3").registerTempTable("script_trans")
assert(100000 ===
sql("SELECT TRANSFORM (d1, d2, d3) USING 'cat' AS (a,b,c) FROM script_trans")
.queryExecution.toRdd.count())
}
}