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_r346177299
 
 

 ##########
 File path: 
datamap/mv/core/src/main/scala/org/apache/carbondata/mv/datamap/MVHelper.scala
 ##########
 @@ -840,5 +895,57 @@ object MVHelper {
       case _ => outputList
     }.get
   }
+
+  private def validateMVTimeSeriesQuery(sparkSession: SparkSession,
+      logicalPlan: LogicalPlan, dataMapSchema: DataMapSchema): (String, 
String) = {
+    var timeSeriesColumn: String = null
+    var timeSeriesFunction: String = null
+    logicalPlan.transformExpressions {
+      case a@Alias(udf: ScalaUDF, _) =>
+        if (udf.function.isInstanceOf[TimeSeriesFunction]) {
+          if (null == timeSeriesColumn && null == timeSeriesFunction) {
+            udf.children.collect {
+              case attr: AttributeReference =>
+                timeSeriesColumn = attr.name
+              case l: Literal =>
+                timeSeriesFunction = 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 (!timeSeriesFunction.equalsIgnoreCase(l.value.toString)) {
+                  throw new MalformedCarbonCommandException(
+                    "Multiple timeseries udf functions are defined in Select 
statement with " +
+                    "different granularities")
+                }
+            }
+          }
+        }
+        a
+    }
+    if (null == timeSeriesColumn && null == timeSeriesFunction) {
+      throw new MalformedCarbonCommandException(
+        "TimeSeries UDF has to be defined in Select statement for using MV 
Timeseries datamap")
+    } else if (null == timeSeriesColumn) {
+      throw new MalformedCarbonCommandException(
+        "MV Timeseries is only supported on Timestamp/Date column")
+    }
+    TimeSeriesUtil.validateTimeSeriesGranularity(timeSeriesFunction)
 
 Review comment:
   If timeseries column or granularity is not provided in the query, then query 
will fail during parsing. This two check's is added to check the below two 
cases:
   1. if timeseries udf is present in mv_timeseries query or not
   2. if timeseriesColumn is not of timestamp/date column.
   I will update the same in description

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


With regards,
Apache Git Services

Reply via email to