[GitHub] ravipesala commented on a change in pull request #3058: [CARBONDATA-3238] Solve StackOverflowError using MV datamap

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] ravipesala commented on a change in pull request #3058: [CARBONDATA-3238] Solve StackOverflowError using MV datamap

GitBox
ravipesala commented on a change in pull request #3058: [CARBONDATA-3238] Solve StackOverflowError using MV datamap
URL: https://github.com/apache/carbondata/pull/3058#discussion_r247390850
 
 

 ##########
 File path: datamap/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/DefaultMatchMaker.scala
 ##########
 @@ -677,8 +677,18 @@ object SelectSelectGroupbyChildDelta extends DefaultMatchPattern with PredicateH
               val aliasMap_exp = AttributeMap(
                 gb_2c.outputList.collect {
                   case a: Alias => (a.toAttribute, a) })
+
+              // avoid to transform a expression more than twrice
+              // accept for select and having
+              val transformedExpFlags = scala.collection.mutable.Map[ExprId, Int]()
+              aliasMap_exp.keySet.map(alias =>
+                transformedExpFlags += (alias.exprId -> 0))
               val sel_3q_exp = sel_3q.transformExpressions({
-                case attr: Attribute if aliasMap_exp.contains(attr) => aliasMap_exp(attr)
+                case attr: Attribute if aliasMap_exp.contains(attr) &&
+                  transformedExpFlags(attr.exprId) < 2 => {
+                  transformedExpFlags(attr.exprId) += 1
+                  aliasMap_exp(attr)
+                }
 
 Review comment:
   In this way, we may not able to solve the complete issue as attributes may repeat in input/output list of select plan. Better create a wrapper and do the transform as below.
   
   First create a wrapper class for alias
   ```
   case class AliasWrapper(alias: Alias) extends UnaryExpression {
                   override def child: Expression = null
   
                   override protected def doGenCode(ctx: CodegenContext,
                       ev: ExprCode): ExprCode = ev
   
                   override def dataType: DataType = alias.dataType
                 }
   ```
   And change the code as below.
   ```
    val aliasMap_exp = AttributeMap(
                   gb_2c.outputList.collect {
                     case a: Alias => (a.toAttribute, AliasWrapper(a)) })
                 val sel_3q_exp = sel_3q.transformExpressions({
                   case attr: Attribute if aliasMap_exp.contains(attr) => aliasMap_exp(attr)
                 }).transformExpressions {
                   case AliasWrapper(alias: Alias) => alias
                 }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services