LuciferYang commented on code in PR #13714:
URL: https://github.com/apache/gluten/pull/13714#discussion_r4703383969
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownInputFileExpression.scala:
##########
@@ -228,14 +275,56 @@ object PushDownInputFileExpression {
CollapseProjectShim.buildCleanedProjectList(p1.projectList,
p2.projectList)))
}
- private def canCollapseProject(project: ProjectExec): Boolean = {
- project.projectList.forall {
- case Alias(_: InputFileName | _: InputFileBlockStart | _:
InputFileBlockLength, _) => true
- case _: Attribute => true
- case _ => false
+ /**
+ * Folds `project` into the scan that `withOutput` makes with the given
output. The scan reads
+ * each column once, and each input file function once even when
PreOffload added it for calls
+ * at different levels, since the native scan maps a non-partition column
to one output only. A
+ * project over the scan gives the repeats their values.
+ */
+ private def foldIntoScan(
+ project: ProjectExec,
+ withOutput: Seq[Attribute] => SparkPlan): SparkPlan = {
+ val firstByName = mutable.Map[String, Attribute]()
+ val read = mutable.Set[ExprId]()
+ // Left: read by the scan. Right: given by the project over it.
+ val columns: Seq[Either[Attribute, NamedExpression]] =
project.projectList.map {
+ case a: Alias if firstByName.contains(a.name) =>
+ Right(Alias(firstByName(a.name), a.name)(exprId = a.exprId))
+ case a: Alias =>
+ firstByName(a.name) = a.toAttribute
+ read += a.exprId
+ Left(a.toAttribute)
+ case a if read.contains(a.exprId) => Right(a.toAttribute)
+ case a =>
+ read += a.exprId
+ Left(a.toAttribute)
+ }
+ val scan = withOutput(columns.collect { case Left(attr) => attr })
+ if (columns.forall(_.isLeft)) {
+ scan
+ } else {
+ val scanAttrs = scan.output.map(a => a.exprId -> a).toMap
+
BackendsApiManager.getSparkPlanExecApiInstance.genProjectExecTransformer(
Review Comment:
Let me take a look
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]