[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3437: [CARBONDATA-3530] Support Create timeseries MV Datamap with the supported granularity levels.

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

[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3437: [CARBONDATA-3530] Support Create timeseries MV Datamap with the supported granularity levels.

GitBox
Indhumathi27 commented on a change in pull request #3437: [CARBONDATA-3530] Support Create timeseries MV Datamap with the supported granularity levels.
URL: https://github.com/apache/carbondata/pull/3437#discussion_r347130139
 
 

 ##########
 File path: datamap/mv/core/src/main/scala/org/apache/carbondata/mv/datamap/MVHelper.scala
 ##########
 @@ -840,5 +891,68 @@ object MVHelper {
       case _ => outputList
     }.get
   }
+
+  /**
+   * Validate mv timeseries query for timeseries column and granularity.
+   * TimeSeries udf function will contain data type as TimeStamp/cast as TimeStamp
+   *
+   * @param logicalPlan   to be validated
+   * @param dataMapSchema to check if it is lazy/non-lazy datamap
+   * @return
+   */
+  private def validateMVTimeSeriesQuery(logicalPlan: LogicalPlan,
+      dataMapSchema: DataMapSchema): (String, String) = {
+    var timeSeriesColumn: String = null
+    var granularity: String = null
+    logicalPlan.transformExpressions {
+      case alias@Alias(udf: ScalaUDF, _) =>
+        if (udf.function.isInstanceOf[TimeSeriesFunction]) {
+          if (null == timeSeriesColumn && null == granularity) {
+            udf.children.collect {
+              case attr: AttributeReference =>
+                timeSeriesColumn = attr.name
+              case l: Literal =>
+                granularity = l.value.toString
+              case c: Cast =>
+                c.child match {
+                  case attribute: AttributeReference =>
+                    if (attribute.dataType.isInstanceOf[DateType]) {
+                      timeSeriesColumn = attribute.name
+                    }
+                  case _ =>
+                }
+            }
+          } else {
+            udf.children.collect {
+              case attr: AttributeReference =>
+                if (!attr.name.equalsIgnoreCase(timeSeriesColumn)) {
+                  throw new MalformedCarbonCommandException(
+                    "Multiple timeseries udf functions are defined in Select statement with " +
+                    "different timestamp columns")
+                }
+              case l: Literal =>
+                if (!granularity.equalsIgnoreCase(l.value.toString)) {
+                  throw new MalformedCarbonCommandException(
+                    "Multiple timeseries udf functions are defined in Select statement with " +
+                    "different granularities")
+                }
+            }
+          }
+        }
+        alias
+    }
+    // timeseries column and granularity is not null, then validate
+    if ((null != timeSeriesColumn).&&(null != granularity)) {
 
 Review comment:
   okay

----------------------------------------------------------------
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:
[hidden email]


With regards,
Apache Git Services