cloud-fan commented on code in PR #40697: URL: https://github.com/apache/spark/pull/40697#discussion_r1160503755
########## sql/core/src/main/scala/org/apache/spark/sql/execution/WholeStageCodegenExec.scala: ########## @@ -750,37 +750,29 @@ case class WholeStageCodegenExec(child: SparkPlan)(val codegenStageId: Int) // but the output must be rows. val rdds = child.asInstanceOf[CodegenSupport].inputRDDs() assert(rdds.size <= 2, "Up to two input RDDs can be supported") + val evaluatorFactory = new WholeStageCodegenEvaluatorFactory( + cleanedSource, durationMs, references) if (rdds.length == 1) { - rdds.head.mapPartitionsWithIndex { (index, iter) => - val (clazz, _) = CodeGenerator.compile(cleanedSource) - val buffer = clazz.generate(references).asInstanceOf[BufferedRowIterator] - buffer.init(index, Array(iter)) - new Iterator[InternalRow] { - override def hasNext: Boolean = { - val v = buffer.hasNext - if (!v) durationMs += buffer.durationMs() - v - } - override def next: InternalRow = buffer.next() + if (conf.getConf(SQLConf.USE_TASK_EVALUATOR)) { + rdds.head.mapPartitionsWithEvaluator(evaluatorFactory) + } else { + rdds.head.mapPartitionsWithIndex { (index, iter) => + val evaluator = evaluatorFactory.createEvaluator() + evaluator.eval(index, iter) } } } else { // Right now, we support up to two input RDDs. - rdds.head.zipPartitions(rdds(1)) { (leftIter, rightIter) => - Iterator((leftIter, rightIter)) - // a small hack to obtain the correct partition index - }.mapPartitionsWithIndex { (index, zippedIter) => - val (leftIter, rightIter) = zippedIter.next() - val (clazz, _) = CodeGenerator.compile(cleanedSource) - val buffer = clazz.generate(references).asInstanceOf[BufferedRowIterator] - buffer.init(index, Array(leftIter, rightIter)) - new Iterator[InternalRow] { - override def hasNext: Boolean = { - val v = buffer.hasNext - if (!v) durationMs += buffer.durationMs() - v - } - override def next: InternalRow = buffer.next() + if (conf.getConf(SQLConf.USE_TASK_EVALUATOR)) { + rdds.head.zipPartitionsWithEvaluator(rdds(1), evaluatorFactory) + } else { + rdds.head.zipPartitions(rdds(1)) { (leftIter, rightIter) => + Iterator((leftIter, rightIter)) + // a small hack to obtain the correct partition index + }.mapPartitionsWithIndex { (index, zippedIter) => + val (leftIter, rightIter) = zippedIter.next() + val evaluator = evaluatorFactory.createEvaluator() Review Comment: using evaluator is just a factor (code move around), otherwise will have to duplicate the code -- 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