kunal642 commented on a change in pull request #3932: URL: https://github.com/apache/carbondata/pull/3932#discussion_r506086546
########## File path: integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/CarbonLateDecodeStrategy.scala ########## @@ -984,6 +988,80 @@ private[sql] class CarbonLateDecodeStrategy extends SparkStrategy { null)(sparkSession) } } + + object ExtractTakeOrderedAndProjectExec { + + def unapply(plan: LogicalPlan): Option[CarbonTakeOrderedAndProjectExec] = { + val allRelations = plan.collect { case logicalRelation: LogicalRelation => logicalRelation } + // push down order by limit to carbon map task, + // only when there are only one CarbonDatasourceHadoopRelation + if (allRelations.size != 1 || + allRelations.exists(x => !x.relation.isInstanceOf[CarbonDatasourceHadoopRelation])) { + return None + } + // check and Replace TakeOrderedAndProject with CarbonTakeOrderedAndProjectExec. + val relation = allRelations.head.relation.asInstanceOf[CarbonDatasourceHadoopRelation] + val sparkPlan = plan match { + case ReturnAnswer(rootPlan) => rootPlan match { + case Limit(IntegerLiteral(limit), Sort(order, true, child)) => + TakeOrderedAndProjectExec(limit, + order, + child.output, + planLater(pushLimit(limit, child))) + case Limit(IntegerLiteral(limit), Project(projectList, Sort(order, true, child))) => + TakeOrderedAndProjectExec(limit, order, projectList, planLater(pushLimit(limit, child))) Review comment: instead of TakeOrderedAndProjectExec, we should directly prepare CarbonTakeOrderedAndProjectExec instance based on the checks below. I feel this TakeOrderedAndProjectExec creation is unnecessary ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org