cloud-fan commented on code in PR #50402: URL: https://github.com/apache/spark/pull/50402#discussion_r2065846065
########## sql/core/src/main/scala/org/apache/spark/sql/execution/UnionLoopExec.scala: ########## @@ -107,9 +110,33 @@ case class UnionLoopExec( plan } val df = Dataset.ofRows(session, planWithLimit) - val materializedDF = df.repartition() - val count = materializedDF.queryExecution.toRdd.count() - (materializedDF, count) + + df.queryExecution.optimizedPlan match { + case l: LocalRelation => + (df, l.data.length.toLong) + case Project(_, _: OneRowRelation) => + if (localRelationLimit != 0) { + val local = LocalRelation.fromExternalRows(anchor.output, df.collect().toIndexedSeq) Review Comment: nit: we should follow `ConvertToLocalRelation` and avoid submitting a job ``` case Project(projectList, OneRowRelation) if !projectList.exists(hasUnevaluableExpr) => val projection = new InterpretedMutableProjection(projectList, Nil) projection.initialize(0) LocalRelation(projectList.map(_.toAttribute), Seq(projection(InternalRow.empty))) ``` -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org