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 @@ -64,7 +64,7 @@ private[hive] case class HiveScriptTransformationExec(
outputSoi: StructObjectInspector,
hadoopConf: Configuration): Iterator[InternalRow] = {
new Iterator[InternalRow] with HiveInspectors {
var curLine: String = null
private var completed = false
val scriptOutputStream = new DataInputStream(inputStream)

val scriptOutputReader =
Expand All @@ -78,13 +78,17 @@ private[hive] case class HiveScriptTransformationExec(
lazy val unwrappers = outputSoi.getAllStructFieldRefs.asScala.map(unwrapperFor)

override def hasNext: Boolean = {
if (completed) {
return false
}
try {
if (scriptOutputWritable == null) {
scriptOutputWritable = reusedWritableObject

if (scriptOutputReader != null) {
if (scriptOutputReader.next(scriptOutputWritable) <= 0) {
checkFailureAndPropagate(writerThread, null, proc, stderrBuffer)
completed = true
return false
}
} else {
Expand All @@ -97,6 +101,7 @@ private[hive] case class HiveScriptTransformationExec(
// there can be a lag between EOF being written out and the process
// being terminated. So explicitly waiting for the process to be done.
checkFailureAndPropagate(writerThread, null, proc, stderrBuffer)
completed = true
return false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
import org.scalatest.exceptions.TestFailedException

import org.apache.spark.{SparkException, TestUtils}
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference, Expression}
import org.apache.spark.sql.execution._
import org.apache.spark.sql.functions._
Expand Down Expand Up @@ -438,4 +439,21 @@ class HiveScriptTransformationSuite extends BaseScriptTransformationSuite with T
assert(e2.contains("array<double> cannot be converted to Hive TypeInfo"))
}
}

test("SPARK-38075: ORDER BY with LIMIT should not add fake rows") {
withTempView("v") {
val df = Seq((1), (2), (3)).toDF("a")
df.createTempView("v")
checkAnswer(sql(
"""
|SELECT TRANSFORM(a)
| USING 'cat' AS (a)
|FROM v
|ORDER BY a
|LIMIT 10
|""".stripMargin),
identity,
Row("1") :: Row("2") :: Row("3") :: Nil)
}
}
}