diff --git a/extensions/spark/kyuubi-extension-spark-3-4/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala b/extensions/spark/kyuubi-extension-spark-3-4/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala index 4f897d1b600..dd329bd659e 100644 --- a/extensions/spark/kyuubi-extension-spark-3-4/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala +++ b/extensions/spark/kyuubi-extension-spark-3-4/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala @@ -71,9 +71,9 @@ trait ForcedMaxOutputRowsBase extends Rule[LogicalPlan] { protected def canInsertLimit(p: LogicalPlan, maxOutputRowsOpt: Option[Int]): Boolean = { maxOutputRowsOpt match { - case Some(forcedMaxOutputRows) => canInsertLimitInner(p) && - !p.maxRows.exists(_ <= forcedMaxOutputRows) - case None => false + case Some(forcedMaxOutputRows) if forcedMaxOutputRows >= 0 => + canInsertLimitInner(p) && !p.maxRows.exists(_ <= forcedMaxOutputRows) + case _ => false } } diff --git a/extensions/spark/kyuubi-extension-spark-3-5/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala b/extensions/spark/kyuubi-extension-spark-3-5/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala index 4f897d1b600..dd329bd659e 100644 --- a/extensions/spark/kyuubi-extension-spark-3-5/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala +++ b/extensions/spark/kyuubi-extension-spark-3-5/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala @@ -71,9 +71,9 @@ trait ForcedMaxOutputRowsBase extends Rule[LogicalPlan] { protected def canInsertLimit(p: LogicalPlan, maxOutputRowsOpt: Option[Int]): Boolean = { maxOutputRowsOpt match { - case Some(forcedMaxOutputRows) => canInsertLimitInner(p) && - !p.maxRows.exists(_ <= forcedMaxOutputRows) - case None => false + case Some(forcedMaxOutputRows) if forcedMaxOutputRows >= 0 => + canInsertLimitInner(p) && !p.maxRows.exists(_ <= forcedMaxOutputRows) + case _ => false } } diff --git a/extensions/spark/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala b/extensions/spark/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala index 4f897d1b600..dd329bd659e 100644 --- a/extensions/spark/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala +++ b/extensions/spark/kyuubi-extension-spark-common/src/main/scala/org/apache/kyuubi/sql/watchdog/ForcedMaxOutputRowsBase.scala @@ -71,9 +71,9 @@ trait ForcedMaxOutputRowsBase extends Rule[LogicalPlan] { protected def canInsertLimit(p: LogicalPlan, maxOutputRowsOpt: Option[Int]): Boolean = { maxOutputRowsOpt match { - case Some(forcedMaxOutputRows) => canInsertLimitInner(p) && - !p.maxRows.exists(_ <= forcedMaxOutputRows) - case None => false + case Some(forcedMaxOutputRows) if forcedMaxOutputRows >= 0 => + canInsertLimitInner(p) && !p.maxRows.exists(_ <= forcedMaxOutputRows) + case _ => false } }