akashrn5 commented on a change in pull request #3541: 
[CARBONDATA-3636]Timeseries query is not hitting datamap if granularity in 
query is given case insensitive
URL: https://github.com/apache/carbondata/pull/3541#discussion_r373317237
 
 

 ##########
 File path: 
datamap/mv/core/src/main/scala/org/apache/carbondata/mv/rewrite/Utils.scala
 ##########
 @@ -519,4 +521,73 @@ object Utils extends PredicateHelper {
     }
   }
 
+  /**
+   * Check's if timeseries udf function exists. If exists, compare literal 
with case insensitive
+   * value
+   */
+  def isExpressionMatchesUDF(exp: Expression, exprList: Seq[Expression]): 
Boolean = {
+    exp match {
+      case Alias(s: ScalaUDF, _) if 
s.function.isInstanceOf[TimeSeriesFunction] =>
+        val children = s.children
+        val finalExpr = exprList.filter(a1 =>
+          a1.isInstanceOf[Alias] && 
a1.asInstanceOf[Alias].child.isInstanceOf[ScalaUDF] &&
+          a1.asInstanceOf[Alias].child.asInstanceOf[ScalaUDF].function.
+            isInstanceOf[TimeSeriesFunction])
+        finalExpr.exists(f => {
+          val finalExp = 
f.asInstanceOf[Alias].child.asInstanceOf[ScalaUDF].children
+          finalExp.head.semanticEquals(children.head) &&
+          finalExp.last.asInstanceOf[Literal].toString().equalsIgnoreCase(
+            children.last.asInstanceOf[Literal].toString())
+        })
+      case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
+        val children = s.children
+        var expList: Seq[Expression] = Seq.empty
+        exprList foreach {
+          case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
+            expList = expList.+:(s)
+          case Alias(s: ScalaUDF, _) if 
s.function.isInstanceOf[TimeSeriesFunction] =>
+            expList = expList.+:(s.asInstanceOf[Expression])
+          case _ =>
+        }
+        expList.exists(f => {
+          val finalExp = f.asInstanceOf[ScalaUDF].children
+          finalExp.head.semanticEquals(children.head) &&
+          finalExp.last.asInstanceOf[Literal].toString().equalsIgnoreCase(
+            children.last.asInstanceOf[Literal].toString())
+        })
+      case exp: Expression =>
+        val newExp = exp.transform {
+          case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
+            getTransformedTimeSeriesUDF(s)
+          case other => other
+        }
+        val newExprList = exprList map { expr =>
+          expr.transform {
+            case s: ScalaUDF if s.function.isInstanceOf[TimeSeriesFunction] =>
+              getTransformedTimeSeriesUDF(s)
+            case other => other
+          }
+        }
+        newExprList.exists(_.semanticEquals(newExp))
+      case _ => false
+    }
+  }
+
+  def getTransformedTimeSeriesUDF(s: ScalaUDF): Expression = {
+    s.transform {
+      case l: Literal =>
+        Literal(l.toString().toLowerCase, l.dataType)
+    }
+  }
+
+  def isExpressionMatchesUDF(exp: Expression, expr: Expression): Boolean = {
 
 Review comment:
   add comment

----------------------------------------------------------------
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

Reply via email to