ravipesala commented on a change in pull request #3129: [CARBONDATA-3295] Fix
that MV datamap throw exception because its rewrite algorithm when query SQL
has multiply subquery
URL: https://github.com/apache/carbondata/pull/3129#discussion_r282844915
##########
File path:
datamap/mv/core/src/main/scala/org/apache/carbondata/mv/datamap/MVHelper.scala
##########
@@ -596,12 +596,20 @@ object MVHelper {
case g: GroupBy =>
MVHelper.updateDataMap(g, rewrite)
}
- // TODO Find a better way to set the rewritten flag, it may fail in some
conditions.
- val mapping =
- rewrittenPlan.collect { case m: ModularPlan => m } zip
- updatedDataMapTablePlan.collect { case m: ModularPlan => m }
- mapping.foreach(f => if (f._1.rewritten) f._2.setRewritten())
+ // Use coarse equal to set the rewritten flag
+ // We may change the ModularPlan relation
+ // So we match the node excluding child comparison
+ updatedDataMapTablePlan.map(plan => {
+ if (rewrittenPlan.find (
+ oriPlan => oriPlan.rewritten && (plan match {
+ case select: Select => select.coarseEqual(oriPlan)
Review comment:
It will unnecessarily add the processing to check the equals of all
relations here. It is better we can remove this code completely and add the
following.
MVHelper
```
def rewriteWithMVTable(rewrittenPlan: ModularPlan, rewrite: QueryRewrite):
ModularPlan = {
if (rewrittenPlan.find(_.rewritten).isDefined) {
val updatedDataMapTablePlan = rewrittenPlan transform {
case s: Select =>
MVHelper.updateDataMap(s, rewrite)
case g: GroupBy =>
MVHelper.updateDataMap(g, rewrite)
}
updatedDataMapTablePlan
} else {
rewrittenPlan
}
}
```
Add new method in org.apache.carbondata.mv.plans.modular.GroupBy
```
override def makeCopy(newArgs: Array[AnyRef]): GroupBy = {
val groupBy = super.makeCopy(newArgs).asInstanceOf[GroupBy]
if (rewritten) groupBy.setRewritten()
groupBy
}
```
Add new method in org.apache.carbondata.mv.plans.modular.Select
```
override def makeCopy(newArgs: Array[AnyRef]): Select = {
val select = super.makeCopy(newArgs).asInstanceOf[Select]
if (rewritten) select.setRewritten()
select
}
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services