diff --git a/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala b/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala index 8b1ba168f9..ca3f69cdda 100644 --- a/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala +++ b/spark/src/main/scala/org/apache/spark/sql/comet/operators.scala @@ -381,11 +381,13 @@ abstract class CometNativeExec extends CometExec { */ protected def canonicalizePlans(): CometNativeExec = { def transform(arg: Any): AnyRef = arg match { - case sparkPlan: SparkPlan if !sparkPlan.isInstanceOf[CometNativeExec] => + case sparkPlan: SparkPlan + if !sparkPlan.isInstanceOf[CometNativeExec] && + children.forall(_ != sparkPlan) => // Different to Spark, Comet native query node might have a Spark plan as Product element. // We need to canonicalize the Spark plan. But it cannot be another Comet native query node, // otherwise it will cause recursive canonicalization. - sparkPlan.canonicalized + null case other: AnyRef => other case null => null }